找回密码
 立即注册

QQ登录

只需一步,快速开始

menghuanyunxia

高级会员

111

主题

396

帖子

1075

积分

高级会员

积分
1075

活字格认证微信认证勋章元老葡萄

menghuanyunxia
高级会员   /  发表于:2013-8-27 08:50  /   查看:7967  /  回复:9
一个Chart上放置散点图和柱状图,出现了两个坐标轴,现在有两个问题:
1,可否只用一个坐标轴?
2,如果必须用两个坐标轴,可不可以设置不让拖动坐标轴?

图1

图1

9 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2013-8-27 09:39:00
沙发
回复 1楼menghuanyunxia的帖子

请问您是如何添加形成多个坐标轴的?
一般通过向 PlotArea 中添加 Series 来实现复合图表。例子中添加了 柱状图和折线图。

  1. yPlotArea1.Series.AddRange(new FarPoint.Win.Chart.Series[] {
  2.             clusteredBarSeries2,
  3.             lineSeries1});
复制代码
回复 使用道具 举报
menghuanyunxia
高级会员   /  发表于:2013-8-27 10:16:00
板凳
回复 2楼iceman的帖子
  1. var yPlotArea = new YPlotArea();
  2. yPlotArea .Series.Add(new ClusteredBarSeries());

  3. var xyPlotArea = new XYPlotArea();
  4. xyPlotArea.Series.Add(new XYLineSeries());

  5. chart.Model.PlotAreas.Add(yPlotArea );
  6. chart.Model.PlotAreas.Add(xyPlotArea );
复制代码
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-8-27 10:50:00
地板
回复 3楼menghuanyunxia的帖子

能否把你的 Demo 放上来我查看?
回复 使用道具 举报
menghuanyunxia
高级会员   /  发表于:2013-8-27 11:08:00
5#
回复 4楼iceman的帖子


Demo.zip (48.33 KB, 下载次数: 157)
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-8-27 16:04:00
6#
回复 5楼menghuanyunxia的帖子

请参考我的设置代码:

  1. private void Form1_Load(object sender, EventArgs e)
  2.         {
  3.             FarPoint.Win.Spread.Chart.SpreadChart chart = new FarPoint.Win.Spread.Chart.SpreadChart();
  4.             chart.Location = new Point(0,0);
  5.             chart.Size = new System.Drawing.Size(400, 400);

  6.             BarSeries bseries = new BarSeries();
  7.             bseries.SeriesName = "Series 0";
  8.             bseries.Values.Add(2.0);
  9.             bseries.Values.Add(4.0);
  10.             bseries.Values.Add(3.0);
  11.             bseries.Values.Add(5.0);


  12.             LineSeries lseries = new LineSeries();
  13.             lseries.Values.Add(2.0);
  14.             lseries.Values.Add(4.0);
  15.             lseries.Values.Add(3.0);
  16.             lseries.Values.Add(5.0);

  17.             YPlotArea plotArea = new YPlotArea();
  18.             plotArea.Location = new PointF(0.2f, 0.2f);
  19.             plotArea.Size = new SizeF(0.6f, 0.6f);
  20.             plotArea.Series.Add(bseries);
  21.             plotArea.Series.Add(lseries);
  22.             LabelArea label = new LabelArea();
  23.             label.Text = "Bar Chart";
  24.             label.Location = new PointF(0.5f, 0.02f);
  25.             label.AlignmentX = 0.5f;
  26.             label.AlignmentY = 0.0f;
  27.             LegendArea legend = new LegendArea();
  28.             legend.Location = new PointF(0.98f, 0.5f);
  29.             legend.AlignmentX = 1.0f;
  30.             legend.AlignmentY = 0.5f;
  31.             ChartModel model = new ChartModel();


  32.             model.LabelAreas.Add(label);
  33.             model.LegendAreas.Add(legend);
  34.             model.PlotAreas.Add(plotArea);
  35.             chart.Model = model;

  36.             fpSpread1.Sheets[0].Charts.Add(chart);


  37.         }
复制代码
回复 使用道具 举报
menghuanyunxia
高级会员   /  发表于:2013-8-27 16:39:00
7#
回复 6楼iceman的帖子
  1. LineSeries lseries = new LineSeries();
  2. lseries.Values.Add(2.0);
  3. lseries.Values.Add(4.0);
  4. lseries.Values.Add(3.0);
  5. lseries.Values.Add(5.0);
复制代码

这里的LineSeries不是我需要的,我需要的是XYLineSeries。
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-8-27 18:00:00
8#
回复 7楼menghuanyunxia的帖子

menghuanyunxia 你好,

经过调查,不同类型的 PlotArea 需要使用不同的坐标轴。

目前还无法共用一个坐标轴。能否考虑使用 line (LineSeries )chart 代替?
回复 使用道具 举报
menghuanyunxia
高级会员   /  发表于:2013-8-28 08:03:00
9#
回复 8楼iceman的帖子

既然这样的话,可设置不让坐标轴拖动吗,否则的话两个轴很容易出现拖动后如上图凌乱的样子?
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2013-8-28 11:05:00
10#
回复 9楼menghuanyunxia的帖子

menghuanyunxia 你好,

可以通过以下方式设置 PlotArea (包含轴位置)位置,请参考:

  1.         PointF location;
  2. private void Form1_Load(object sender, EventArgs e)
  3.         {
  4.             var chart = new SpreadChart();
  5.             chart.DynamicMove = true;
  6.             chart.DynamicSize = true;
  7.             chart.Location = new Point(20, 20);
  8.             chart.Size = new Size(400, 300);

  9.             var yPlotArea = new YPlotArea();
  10.             var cluSeries = new ClusteredBarSeries();
  11.             yPlotArea.Series.Add(cluSeries);
  12.             var barSeries = new BarSeries();
  13.             barSeries.Values.Add(1);
  14.             barSeries.Values.Add(2);
  15.             barSeries.Values.Add(3);
  16.             cluSeries.Series.Add(barSeries);
  17.             chart.Model.PlotAreas.Add(yPlotArea);

  18.             var xyPlotArea = new XYPlotArea();
  19.             var xySeries = new XYLineSeries();
  20.             xyPlotArea.Series.Add(xySeries);
  21.             xySeries.XValues.Add(1);
  22.             xySeries.YValues.Add(3);

  23.             xySeries.XValues.Add(2);
  24.             xySeries.YValues.Add(6);

  25.             xySeries.XValues.Add(3);
  26.             xySeries.YValues.Add(8);
  27.             location = yPlotArea.Location;
  28.             chart.Model.PlotAreas.Add(xyPlotArea);


  29.             yPlotArea.Changed += new EventHandler(yPlotArea_Changed);
  30.             chart.Model.LegendAreas.Add(new LegendArea());
  31.             chart.Model.LabelAreas.Add(new LabelArea());

  32.             this.fpSpread1_Sheet1.Charts.Add(chart);
  33.         }


  34.         void yPlotArea_Changed(object sender, EventArgs e)
  35.         {
  36.             YPlotArea yPlotArea = sender as YPlotArea;
  37.             PointF a = yPlotArea.Location;

  38.             this.fpSpread1_Sheet1.Charts[0].Model.PlotAreas[0].Location = location;
  39.         }
复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部