private PieSeries GetNewSerie(PieData data) { Random countRandom = new Random(); ChartYAxisValueCollection <ChartYAxisValue> yVals = new ChartYAxisValueCollection <ChartYAxisValue>(); int count = data.XAxisCount; for (int i = 0; i < count; i++) { yVals.Add(new BarYAxisValue(countRandom.Next(0, count))); } PieSeries set1 = new PieSeries(yVals, "DataSet 1"); set1.AddColor(DemoGlobal.GetRandomColor()); set1.AddColor(DemoGlobal.GetRandomColor()); set1.AddColor(DemoGlobal.GetRandomColor()); return(set1); }
private void popList1_Selected(object sender, EventArgs e) { switch (popList1.Selections[0].Text) { case "DataBind": DataBind(); break; case "Legend": this.pieChart1.Legend.XEntrySpace = 10; this.pieChart1.Legend.YEntrySpace = 10; this.pieChart1.Legend.Position = LegendPosition.BELOW_CHART_LEFT; this.pieChart1.Legend.XOffset = 1; this.pieChart1.Legend.YOffset = 1; this.pieChart1.Legend.TextSize = 15; this.pieChart1.Legend.TextColor = System.Drawing.Color.Red; break; case "LegendSize": if (this.pieChart1.Legend.Size == 0) { this.pieChart1.Legend.Size = 10; } else { this.pieChart1.Legend.Size = 0; } break; case "AddSet": this.pieChart1.Data.AddSeries(GetNewSerie(this.pieChart1.Data)); break; case "RemoveSet": if (this.pieChart1.Data.SeriesCount > 0) { this.pieChart1.Data.RemoveSeries(0); } break; case "ClearSet": this.pieChart1.Data.ClearValues(); break; case "SetData": List <string> xLabels = new List <string>(); xLabels.AddRange(new string[] { "1", "2", "3", "4" }); PieData data = new PieData(xLabels); ChartYAxisValueCollection <ChartYAxisValue> yVals = new ChartYAxisValueCollection <ChartYAxisValue>(); yVals.Add(new BarYAxisValue(1111111)); yVals.Add(new BarYAxisValue(3333333)); yVals.Add(new BarYAxisValue(666666666666)); yVals.Add(new BarYAxisValue(333333333333)); PieSeries set1 = new PieSeries(yVals, "DataSet 1"); set1.AddColor(DemoGlobal.GetRandomColor()); set1.AddColor(DemoGlobal.GetRandomColor()); set1.AddColor(DemoGlobal.GetRandomColor()); data.AddSeries(set1); this.pieChart1.Data = data; break; } }