具有不同宽度列的柱形图

时间:2014-05-29 11:12:46

标签: c# charts

我正在尝试创建一个包含宽度不同的列的柱形图。

是否可以使用图表控件创建这样的图表,还是应该查找支持它的库?

enter image description here

2 个答案:

答案 0 :(得分:1)

分别更改每个MarkerSize上的DataPoint属性

答案 1 :(得分:0)

您可以使用像这样的区域类型图表:

enter image description here

设置

Series s1 = chart1.Series.Add("S1");
s2.ChartType = SeriesChartType.Area;

ChartArea ca = chart1.ChartAreas[0];
ca.AxisX.Minimum = 0;

AddArea(chart1, s2, 12, 53, Color.SlateBlue);
AddArea(chart1, s2, 32, 63, Color.Firebrick);
AddArea(chart1, s2, 22, 23, Color.SlateBlue);
AddArea(chart1, s2, 62, 33, Color.Goldenrod);
AddArea(chart1, s2, 12, 33, Color.PaleVioletRed);

并添加如下内容:

int AddArea(Chart chart, Series s, double x, double y, Color color)
{
    ChartArea ca = chart.ChartAreas[s.ChartArea];
    Axis ax = ca.AxisX;
    Axis ay = ca.AxisY;
    if (s.Points.Count == 0) s.Points.AddXY(ax.Minimum, ay.Minimum);
    DataPoint dp0 = s.Points.Last();
    int p1 = s.Points.AddXY(dp0.XValue, y);
    s.Points.AddXY(dp0.XValue + x, y);
    s.Points.Last().Color = color;
    s.Points.AddXY(dp0.XValue + x, ay.Minimum);
    dp0.Color = color;
    s.Points.Last().Color = color;

    return p1;
}