找回密码
 立即注册

QQ登录

只需一步,快速开始

[WinForms] 复合图表

roger.wang
社区贡献组   /  发表于:2014-5-16 11:25  /   查看:4763  /  回复:0
问题描述:使用代码创建复合图表,例如:在同一图表中包含条形图和折线图。
问题解答:可以通过给YPlotArea添加不同的系列类型来制作复合图表。
关键代码:

  1.         private void AddCompositeChart()
  2.         {
  3.             BarSeries series0 = new BarSeries();
  4.             series0.Values.Add(8.0);
  5.             series0.Values.Add(4.0);
  6.             series0.Values.Add(2.0);
  7.             series0.Values.Add(1.0);
  8.             series0.YAxisId = 1;


  9.             LineSeries series2 = new LineSeries();
  10.             series2.PointMarker = new BuiltinMarker(MarkerShape.Circle, 7.0f);
  11.             series2.Values.Add(8.0);
  12.             series2.Values.Add(12.0);
  13.             series2.Values.Add(14.0);
  14.             series2.Values.Add(15.0);
  15.             series2.YAxisId = 1;
  16.             series2.LabelVisible = true;

  17.             ValueAxis y2 = new ValueAxis();
  18.             y2.AxisId = 1;
  19.             y2.AutoMaximum = true;
  20.             y2.AutoMinimum = true;
  21.             y2.LabelVisible = true;
  22.             y2.Location = AxisLocation.Far;

  23.             YPlotArea plotArea = new YPlotArea();
  24.             plotArea.Location = new PointF(0.2f, 0.2f);
  25.             plotArea.Size = new SizeF(0.6f, 0.6f);
  26.             plotArea.Series.Add(series0);
  27.             plotArea.Series.Add(series2);

  28.             plotArea.YAxes.Add(y2);

  29.             LabelArea label = new LabelArea();
  30.             label.Location = new PointF(0.5f, 0.02f);
  31.             label.AlignmentX = 0.5f;
  32.             label.AlignmentY = 0.0f;
  33.             label.Text = "组合图表";

  34.             ChartModel model = new ChartModel();
  35.             model.LabelAreas.Add(label);
  36.             model.PlotAreas.Add(plotArea);

  37.             fpSpread1.ActiveSheet.Charts[0].Model = model;
  38.         }
复制代码

?
效果截图:


示例下载:点击下载

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

0 个回复

您需要登录后才可以回帖 登录 | 立即注册
返回顶部