Column chart with different widths of columns

2019-09-02 23:15发布

问题:

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?

回答1:

Change the MarkerSize property on each DataPoint individually



回答2:

You can use a Area type chart like this:

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


标签: c# charts