默认情况下 FpChart 会给饼图的每个区域自动填充颜色,在某些情况下我们希望饼图的显示风格和我们的系统使用的色系(主题)能够一致,此时我们可以自己定制饼图的显示颜色,代码如下:
- protected void Page_Load(object sender, EventArgs e)
- {
- if (IsPostBack)
- {
- return;
- }
- #region 设置饼图中各部分的颜色
- string colors = "#ffbb22,#ff9911,#aacc33,#aabbbb,#bb0033,#00cc33,#990099,#0011aa,#14D0EE,#B17EC3,#E67F16,#EE5907,#6A2DA1,#0A35F0,#A816D7,#D218AD,#EE0A96,#5A4DAE,#ACE9D9";
-
- FillCollection fc = ((FpChart1.Model.PlotAreas[0] as FarPoint.Web.Chart.PiePlotArea).Series[0] as FarPoint.Web.Chart.PieSeries).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());
- #endregion
- }
复制代码
运行效果如下:
|
|