C# DevExpress XtraCharts 柱状图 条形图 同一个Series的Bar显示不同颜色
可以在Chart的CustomDrawSeriesPoint事件中,判断Bar的值,来显示不同的颜色
1 BarDrawOptions bo = e.SeriesDrawOptions as BarDrawOptions; 2 if (bo != null) 3 { 4 double value = e.SeriesPoint[0]; 5 if (value == 0) 6 bo.Color = Color.FromArgb(102, 168, 9); 7 else if (value == 1) 8 bo.Color = Color.FromArgb(225, 169, 62); 9 else if (value == 2) 10 bo.Color = Color.FromArgb(152, 28, 23); 11 else if (value == 3) 12 bo.Color = Color.FromArgb(255, 0, 255); 13 else if (value == 4) 14 bo.Color = Color.FromArgb(43, 145, 175); 15 else 16 bo.Color = Color.Black; 17 }
也可以根据X轴每个Bar的不同名称来显示不同的颜色
1 BarDrawOptions bo = e.SeriesDrawOptions as BarDrawOptions; 2 if (bo != null) 3 { 4 string name = e.SeriesPoint.Argument; 5 if (name == "ok") 6 bo.Color = Color.FromArgb(102, 168, 9); 7 else if (name == "warning") 8 bo.Color = Color.FromArgb(225, 169, 62); 9 else if (name == "critical") 10 bo.Color = Color.FromArgb(152, 28, 23); 11 else if (name == "unknown") 12 bo.Color = Color.FromArgb(255, 0, 255); 13 else if (name == "pending") 14 bo.Color = Color.FromArgb(43, 145, 175); 15 }
该事件不仅能修改颜色,也可以修改PointLable , Legend等内容。 比如可以让PointLables同时显示Value及百分比占比