DevExpress的WebChartControl控件绘制图表,要求每个柱体的颜色都自定义

isme2014 2014-12-11 02:24:09

1 if (dt!= null && dt.Rows.Count > 0)
2 {
3 this.WebChartControl2.Series.Clear();
4 this.WebChartControl2.Titles.Clear();
5
6 //set chart title
7 SetChartTitle(this.WebChartControl2, true, "Titile", true, 2, StringAlignment.Center, ChartTitleDockStyle.Top, true, new Font("Arial", 12, FontStyle.Bold), Color.Black, 10);
8
9 Series seriesOnand = new Series("", ViewType.Bar);
10 seriesOnand.DataSource = dtOnHand;
11 seriesOnand.ArgumentDataMember = dt.PublicDataListFields.GroupColumn.ToString();
12 seriesOnand.ValueDataMembers[0] = dt.PublicDataListFields.Count.ToString();
13
14 this.WebChartControl2.Series.Add(seriesOnand);
15
16 //set AxisX
17 SetAxisX(this.WebChartControl2, true, StringAlignment.Center, "Days", Color.Black, true, new Font("Arial", 10, FontStyle.Bold));
18 SetAxisY(this.WebChartControl2, true, StringAlignment.Center, "Inq Qty", Color.Black, true, new Font("Arial", 10, FontStyle.Bold));
19
20 string[] colorArray = { "#00FF00", "#00FF00", "#FFCC00", "#FF0000" };
21 int i = 0;
22 foreach (Series s in this.WebChartControl2.Series)
23 {
24 if (s.View.ToString() == "Bar")
25 {
26 BarSeriesView barView = (BarSeriesView)s.View;
27
28 barView.Color = System.Drawing.ColorTranslator.FromHtml(colorArray[i]);
29
30
31 }
32 i++;
33
34 if (i >= 4)
35 i = 0;
36 }
37 }


我的目的是希望每一个柱体都显示不同的颜色,但是执行以上代码后,得到的效果却是下图所示:


求教:如何才能实现每个柱体都能显示不同的颜色,类似于下图这样的:


谢谢!
...全文
1912 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yzf86211861 2016-10-24
  • 打赏
  • 举报
回复
楼主 这个问题解决了嘛 我也遇到 这个问题了
1377194675 2016-04-20
  • 打赏
  • 举报
回复
我觉得这应该要把数据分成不同的序列 你的代码我试过了 只有一个序列的时候颜色就是一样的
1377194675 2016-04-20
  • 打赏
  • 举报
回复
问题解决没有? 我现在也遇到类似的问题
isme2014 2014-12-11
  • 打赏
  • 举报
回复
Series是是一组数据对象,而Seriespoint则是这组数据对象中的一个对象,需要设置SeriesPoint这个对象的颜色就可以实现,问题是如何设置SeriesPoint这个对象的颜色呢?
isme2014 2014-12-11
  • 打赏
  • 举报
回复
有人么,自己顶贴啦,汗。。。。
isme2014 2014-12-11
  • 打赏
  • 举报
回复
在的童鞋进来看看嘛,或许可以帮到楼主呢,谢谢了哈!

4,816

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 图表区
社区管理员
  • 图表区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧