Spread for WinForms 中同样提供了组合图表的功能,我们只需在图表区域中添加两种不同的图表系列就可以实现。

实现代码如下:
 
private void Form1_Load(object sender, EventArgs e)

        {

            StackedBarSeries stack = new StackedBarSeries();

            stack.LabelVisible = true;

            stack.YAxisId = 1;



            BarSeries series0 = new BarSeries();

            series0.Values.Add(8.0);

            series0.Values.Add(4.0);

            series0.Values.Add(2.0);

            series0.Values.Add(1.0);



            BarSeries series1 = new BarSeries();

            series1.Values.Add(2.0);

            series1.Values.Add(3.0);

            series1.Values.Add(4.0);

            series1.Values.Add(6.0);



            stack.Series.Add(series0);

            stack.Series.Add(series1);



            LineSeries series2 = new LineSeries();

            series2.PointMarker = new BuiltinMarker(MarkerShape.Circle, 7.0f);

            series2.Values.Add(8.0);

            series2.Values.Add(12.0);

            series2.Values.Add(14.0);

            series2.Values.Add(15.0);

            series2.YAxisId = 1;

            series2.LabelVisible = true;



            ValueAxis y2 = new ValueAxis();

            y2.AxisId = 1;

            y2.AutoMaximum = true;

            y2.AutoMinimum = true;

            y2.LabelVisible = true;

            y2.Location = AxisLocation.Far;



            YPlotArea plotArea = new YPlotArea();

            plotArea.Location = new PointF(0.2f, 0.2f);

            plotArea.Size = new SizeF(0.6f, 0.6f);

            plotArea.Series.Add(stack);

            plotArea.Series.Add(series2);



            plotArea.YAxes.Add(y2);



            LabelArea label = new LabelArea();

            label.Location = new PointF(0.5f, 0.02f);

            label.AlignmentX = 0.5f;

            label.AlignmentY = 0.0f;

            label.Text = "组合图表";



            ChartModel model = new ChartModel();

            model.LabelAreas.Add(label);

            model.PlotAreas.Add(plotArea);



            fpSpread1.ActiveSheet.Charts[0].Model = model;



        }

复制代码
运行截图:
(11.58 K, 下载次数:5)