复合图表
问题描述:使用代码创建复合图表,例如:在同一图表中包含条形图和折线图。问题解答:可以通过给YPlotArea添加不同的系列类型来制作复合图表。
关键代码:
private void AddCompositeChart()
{
BarSeries series0 = new BarSeries();
series0.Values.Add(8.0);
series0.Values.Add(4.0);
series0.Values.Add(2.0);
series0.Values.Add(1.0);
series0.YAxisId = 1;
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(series0);
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.Model = model;
}
?
效果截图:
示例下载:点击下载
页:
[1]