Column chart with different widths of columns

2019-09-02 22:59发布

I'm trying to create a column chart that has columns with diffrent widths.

Is it possible to create a chart like that with the chart control or should I look for a library that supports it?

enter image description here

标签: c# charts
2条回答
Bombasti
2楼-- · 2019-09-02 23:36

You can use a Area type chart like this:

enter image description here

Set it up

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);

and add points like this:

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;
}
查看更多
来,给爷笑一个
3楼-- · 2019-09-03 00:01

Change the MarkerSize property on each DataPoint individually

查看更多
登录 后发表回答