zoukankan      html  css  js  c++  java
  • 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及百分比占比

  • 相关阅读:
    仿MSN小类别滑动效果
    pku1674 Sorting by Swapping
    pku1456 Supermarket
    pku1083 Moving Tables
    pku1125 Stockbroker Grapevine
    pku2232 New StoneForfexCloth Game
    如何低头前进
    和两年前一样
    股票亏了
    早上选举了
  • 原文地址:https://www.cnblogs.com/xyz0835/p/3822206.html
Copyright © 2011-2022 走看看