Spread中提供了多种图表类型,这些图表类型都是可以通过设计器和代码两种方式来进行设置,本文主要是讲解如何通过代码来设置饼图的显示样式,包括每个分区的填充颜色,以及饼图数据按照百分比的形式进行显示
具体代码如下:
- private void Form2_Load(object sender, EventArgs e)
- {
- string colors = "#ffbb22,#ff9911,#aacc33,#aabbbb,#bb0033,#00cc33,#990099,#0011aa,#14D0EE,#B17EC3,#E67F16,#EE5907,#6A2DA1,#0A35F0,#A816D7,#D218AD,#EE0A96,#5A4DAE,#ACE9D9";
- PieSeries pseries = new PieSeries();
- pseries.Values.AddRange(new double[] { 0.2,0.3,0.1,0.2,0.2});
- pseries.LabelVisible = true;
- pseries.LabelFormatter = new FarPoint.Win.Spread.Model.GeneralFormatter("0.00%", false);
- FillCollection fc = pseries.PieFills;
- List<SolidFill> list = new List<SolidFill>();
- foreach (var color in colors.Split(new char[] { ',' }))
- {
- list.Add(new SolidFill(ColorTranslator.FromHtml(color)));
- }
- fc.Clear();
- fc.AddRange(list.ToArray());
- PiePlotArea plotArea = new PiePlotArea();
- plotArea.Location = new PointF(0.2f, 0.2f);
- plotArea.Size = new SizeF(0.6f, 0.6f);
- plotArea.Series.Add(pseries);
- ChartModel model = new ChartModel();
- model.PlotAreas.Add(plotArea);
- fpSpread1.ActiveSheet.Charts[0].Model = model;
- }
复制代码
运行效果截图:
源码下载:Vs2010 + Spread .NET 6.0
6708_Chart.zip
(10.8 KB, 下载次数: 612)
|
|