自定义饼图填充颜色
问题描述:添加饼状图后,Spread 会有默认的填充色,如何通过代码指定填充的颜色。问题解答:饼状图提供了PieFills属性用于获取和设置填充色。
关键代码:
private void ChangeFillColors()
{
string colors = "#ffbb22,#ff9911,#aacc33,#aabbbb,#bb0033,#00cc33,#990099,#0011aa,#14D0EE,#B17EC3,#E67F16,#EE5907,#6A2DA1,#0A35F0,#A816D7,#D218AD,#EE0A96,#5A4DAE,#ACE9D9";
PieSeries pseries = newPieSeries();
pseries.Values.AddRange(newdouble[] { 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 = newList<SolidFill>();
foreach (var color in colors.Split(newchar[] { ',' }))
{
list.Add(newSolidFill(ColorTranslator.FromHtml(color)));
}
fc.Clear();
fc.AddRange(list.ToArray());
PiePlotArea plotArea = newPiePlotArea();
plotArea.Location = newPointF(0.2f, 0.2f);
plotArea.Size = newSizeF(0.6f, 0.6f);
plotArea.Series.Add(pseries);
ChartModel model = newChartModel();
model.PlotAreas.Add(plotArea);
fpSpread1.ActiveSheet.Charts.Model = model;
}
效果截图:
示例下载:点击下载
页:
[1]