找回密码
 立即注册

QQ登录

只需一步,快速开始

ud7070

初级会员

23

主题

97

帖子

312

积分

初级会员

积分
312

微信认证勋章

ud7070
初级会员   /  发表于:2023-5-10 16:29  /   查看:1589  /  回复:9
5金币


现有数据表结构为4字段 Col1、Col2、Col3、Col4,对应X轴绑定Col1,Y轴绑定Col2,Y2轴绑定Col3,Y3轴绑定Col4。
在DataSet中有n个数据表,现要将n个数据表的数据绘制到 FlexChart中。我在循环添加时的代码如下:

  1. foreach (DataTable objTb in objDs)
  2.             {
  3.                 var series1 = new Series()
  4.                 {
  5.                     Name = "Temperature(°C)",
  6.                     Binding = "HighTemp",
  7.                     ChartType = ChartType.SplineSymbols,
  8.                     SymbolMarker = (SymbolMarker)1,
  9.                     DataSource = objTb,
  10.                     AxisY = new Axis()
  11.                     {
  12.                         Position = Position.Left,
  13.                         Title = "Temperature (°C)",
  14.                         AxisLine = true,
  15.                     }
  16.                 };
  17.                 this.flexChart1.Series.Add(series1);

  18.                 var series2 = new Series()
  19.                 {
  20.                     Name = "Precipitation(mm)",
  21.                     Binding = "Precipitation",
  22.                     ChartType = ChartType.SplineSymbols,
  23.                     SymbolMarker = (SymbolMarker)2,
  24.                     DataSource = objTb,
  25.                     AxisY = new Axis()
  26.                     {
  27.                         Position = Position.Right,
  28.                         Title = "Precipitation (mm)",
  29.                         AxisLine = true,
  30.                     },
  31.                 };
  32.                 this.flexChart1.Series.Add(series2);

  33.                 var series3 = new Series()
  34.                 {
  35.                     Name = "PPL(lb)",
  36.                     Binding = "PPL",
  37.                     ChartType = ChartType.SplineSymbols,
  38.                     SymbolMarker = (SymbolMarker)7,
  39.                     DataSource = objTb,
  40.                     AxisY = new Axis()
  41.                     {
  42.                         Position = Position.Right,
  43.                         Title = "PPL (mm)",
  44.                         AxisLine = true,
  45.                     },
  46.                 };
  47.                 this.flexChart1.Series.Add(series3);
  48.             }
复制代码


但是这样添加后,右边的Y轴会重复显示,但如果不在 new Series() 时设置“AxisY",右侧又不显示轴,请问如何解决?
就是已添加的第二、三Y轴是否可以获取到?

最佳答案

查看完整内容

你是给多个series 绑定同一个Y轴,那么应该是自己new一个Y轴对象出来,然后每次添加series时设置,这样才对

9 个回复

倒序浏览
最佳答案
最佳答案
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2023-5-10 16:29:44
来自 8#
你是给多个series 绑定同一个Y轴,那么应该是自己new一个Y轴对象出来,然后每次添加series时设置,这样才对



本帖子中包含更多资源

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

x
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2023-5-10 17:56:44
2#
请上传一个重现问题的demo,我帮你排查一下原因,
回复 使用道具 举报
ud7070
初级会员   /  发表于:2023-5-10 18:24:49
3#
Richard.Ma 发表于 2023-5-10 17:56
请上传一个重现问题的demo,我帮你排查一下原因,
  1. private void Form2_Load(object sender, EventArgs e)
  2.         {
  3.             DataSet ds = new DataSet();
  4.             for (int i = 0; i < 3; i++)
  5.             {
  6.                 DataTable objTb = new DataTable();
  7.                 objTb.TableName = $"objTb{i + 1}";
  8.                 objTb.Columns.Add("Col1", typeof(int));
  9.                 objTb.Columns.Add("Col2", typeof(int));
  10.                 objTb.Columns.Add("Col3", typeof(int));
  11.                 objTb.Columns.Add("Col4", typeof(int));

  12.                 for(int r = 0; r < 20; r++)
  13.                 {
  14.                     DataRow newRow = objTb.NewRow();
  15.                     newRow[0] = r;
  16.                     for (int c = 1; c < 4; c++)
  17.                     {
  18.                         newRow[c] = r * c + Math.Pow(i, c);
  19.                     }
  20.                     objTb.Rows.Add(newRow);
  21.                 }

  22.                 ds.Tables.Add(objTb);
  23.             }

  24.             List<Color> colorList = new List<Color>() { Color.Blue, Color.Red, Color.Green, Color.AliceBlue };

  25.             var chart = flexChart1;

  26.             chart.AxisX.Title = "Col1";
  27.             chart.AxisY.Title = "Col2";
  28.             chart.BindingX = "Col1";
  29.             chart.AxisX.AxisLine = true;
  30.             chart.AxisX.MajorGrid = true;
  31.             chart.AxisY.Position = Position.Left;
  32.             chart.AxisY.AxisLine = true;

  33.             for (int i = 0; i < ds.Tables.Count; i++)
  34.             {
  35.                 var curSeries = new Series()
  36.                 {
  37.                     Name = $"{ds.Tables[i].TableName}_Col2",
  38.                     Binding = "Col2",
  39.                     ChartType = ChartType.SplineSymbols,
  40.                     SymbolMarker = (SymbolMarker)1,
  41.                     Style =
  42.                     {
  43.                         StrokeWidth = 2,
  44.                         StrokeColor = colorList[i],
  45.                     },
  46.                     DataSource = ds.Tables[i],
  47.                 };
  48.                 chart.Series.Add(curSeries);

  49.                 var seriesY2 = new Series()
  50.                 {
  51.                     Name = $"{ds.Tables[i].TableName}_Col3",
  52.                     Binding = "Col3",
  53.                     ChartType = ChartType.SplineSymbols,
  54.                     SymbolMarker = (SymbolMarker)2,
  55.                     Style =
  56.                     {
  57.                         StrokeWidth = 2,
  58.                         StrokeColor = colorList[i],
  59.                     },
  60.                     DataSource = ds.Tables[i],
  61.                     AxisY = new Axis()
  62.                     {
  63.                         Position = Position.Right,
  64.                         Title = "Y2(Col3)",
  65.                         AxisLine = true,
  66.                         LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
  67.                     },
  68.                 };
  69.                 chart.Series.Add(seriesY2);

  70.                 var seriesY3 = new Series()
  71.                 {
  72.                     Name = $"{ds.Tables[i].TableName}_Col4",
  73.                     Binding = "Col4",
  74.                     ChartType = ChartType.SplineSymbols,
  75.                     SymbolMarker = (SymbolMarker)7,
  76.                     Style =
  77.                     {
  78.                         StrokeWidth = 2,
  79.                         StrokeColor = colorList[i],
  80.                     },
  81.                     DataSource = ds.Tables[i],
  82.                     AxisY = new Axis()
  83.                     {
  84.                         Position = Position.Right,
  85.                         Title = "Y3(Col4)",
  86.                         AxisLine = true,
  87.                         LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
  88.                     },
  89.                 };
  90.                 chart.Series.Add(seriesY3);
  91.             }
  92.         }
复制代码
回复 使用道具 举报
ud7070
初级会员   /  发表于:2023-5-10 18:41:51
4#
本帖最后由 ud7070 于 2023-5-11 08:53 编辑
Richard.Ma 发表于 2023-5-10 17:56
请上传一个重现问题的demo,我帮你排查一下原因,

又改了一下,轴不重复了,但是如果先添加一次曲线后,再在DataSet 中循环添加表时,右侧的Y2轴和Y3轴的刻度不会根据数据的变化而变化,但左侧的正常。

本帖子中包含更多资源

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

x
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2023-5-11 10:43:33
5#
这个form有用其他的东西,这边运行不起来,请上传完整的一个demo项目上来

本帖子中包含更多资源

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

x
回复 使用道具 举报
ud7070
初级会员   /  发表于:2023-5-11 10:54:03
6#
Richard.Ma 发表于 2023-5-11 10:43
这个form有用其他的东西,这边运行不起来,请上传完整的一个demo项目上来

删除那行即可

删除"LogBase"配置
回复 使用道具 举报
ud7070
初级会员   /  发表于:2023-5-11 11:00:20
7#
Richard.Ma 发表于 2023-5-11 10:43
这个form有用其他的东西,这边运行不起来,请上传完整的一个demo项目上来
  1. public partial class Form2 : Form
  2.     {
  3.         DataSet ds = new DataSet();
  4.         List<Color> colorList = new List<Color>() { Color.Blue, Color.Red, Color.Green, Color.AliceBlue };

  5.         public Form2()
  6.         {
  7.             InitializeComponent();
  8.         }

  9.         private void Form2_Load(object sender, EventArgs e)
  10.         {
  11.             for (int i = 0; i < 3; i++)
  12.             {
  13.                 DataTable objTb = new DataTable();
  14.                 objTb.TableName = $"objTb{i + 1}";
  15.                 objTb.Columns.Add("Col1", typeof(int));
  16.                 objTb.Columns.Add("Col2", typeof(int));
  17.                 objTb.Columns.Add("Col3", typeof(int));
  18.                 objTb.Columns.Add("Col4", typeof(int));

  19.                 for(int r = 0; r < 20; r++)
  20.                 {
  21.                     DataRow newRow = objTb.NewRow();
  22.                     newRow[0] = r;
  23.                     for (int c = 1; c < 4; c++)
  24.                     {
  25.                         newRow[c] = r * Math.Pow((c + 1), 2) * (i == 0 ? 1 : Math.Pow(i, c)) + Math.Pow(i, c) + Math.Pow(r, i + c);
  26.                     }
  27.                     objTb.Rows.Add(newRow);
  28.                 }

  29.                 ds.Tables.Add(objTb);
  30.             }

  31.             var chart = flexChart1;

  32.             chart.BeginUpdate();

  33.             chart.AxisX.Title = "Col1";
  34.             chart.AxisY.Title = "Col2";
  35.             chart.BindingX = "Col1";
  36.             chart.AxisX.AxisLine = true;
  37.             chart.AxisX.MajorGrid = true;
  38.             chart.AxisY.Position = Position.Left;
  39.             chart.AxisY.AxisLine = true;

  40.             //for (int i = 0; i < ds.Tables.Count; i++)
  41.             //for (int i = ds.Tables.Count - 1; i >= 0; i--)//可以看到Y3最大坐标
  42.             for (int i = 0; i < 1; i++)
  43.             {
  44.                 var curSeries = new Series()
  45.                 {
  46.                     Name = $"{ds.Tables[i].TableName}_Col2",
  47.                     Binding = "Col2",
  48.                     ChartType = ChartType.SplineSymbols,
  49.                     SymbolMarker = (SymbolMarker)1,
  50.                     Style =
  51.                     {
  52.                         StrokeWidth = 2,
  53.                         StrokeColor = colorList[i],
  54.                     },
  55.                     DataSource = ds.Tables[i],
  56.                 };
  57.                 chart.Series.Add(curSeries);

  58.                 var seriesY2 = new Series()
  59.                 {
  60.                     Name = $"{ds.Tables[i].TableName}_Col3",
  61.                     Binding = "Col3",
  62.                     ChartType = ChartType.SplineSymbols,
  63.                     SymbolMarker = (SymbolMarker)2,
  64.                     Style =
  65.                     {
  66.                         StrokeWidth = 2,
  67.                         StrokeColor = colorList[i],
  68.                     },
  69.                     DataSource = ds.Tables[i],
  70.                     //AxisY = new Axis()
  71.                     //{
  72.                     //    Position = Position.Right,
  73.                     //    Title = "Y2(Col3)",
  74.                     //    AxisLine = true,
  75.                     //    LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
  76.                     //},
  77.                 };
  78.                 if (!GetHaveTypeSeries("Col3"))
  79.                 {
  80.                     seriesY2.AxisY = new Axis()
  81.                     {
  82.                         Position = Position.Right,
  83.                         Title = "Y2(Col3)",
  84.                         AxisLine = true,
  85.                         //LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
  86.                     };
  87.                 }
  88.                 chart.Series.Add(seriesY2);

  89.                 var seriesY3 = new Series()
  90.                 {
  91.                     Name = $"{ds.Tables[i].TableName}_Col4",
  92.                     Binding = "Col4",
  93.                     ChartType = ChartType.SplineSymbols,
  94.                     SymbolMarker = (SymbolMarker)7,
  95.                     Style =
  96.                     {
  97.                         StrokeWidth = 2,
  98.                         StrokeColor = colorList[i],
  99.                     },
  100.                     DataSource = ds.Tables[i],
  101.                     //AxisY = new Axis()
  102.                     //{
  103.                     //    Position = Position.Right,
  104.                     //    Title = "Y3(Col4)",
  105.                     //    AxisLine = true,
  106.                     //    LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
  107.                     //},
  108.                 };
  109.                 if (!GetHaveTypeSeries("Col4"))
  110.                 {
  111.                     seriesY3.AxisY = new Axis()
  112.                     {
  113.                         Position = Position.Right,
  114.                         Title = "Y3(Col4)",
  115.                         AxisLine = true,
  116.                         //LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
  117.                     };
  118.                 }
  119.                 chart.Series.Add(seriesY3);
  120.             }

  121.             chart.EndUpdate();
  122.             chart.Refresh();
  123.         }


  124.         bool GetHaveTypeSeries(string ColName)
  125.         {
  126.             bool rst = false;

  127.             var chart = this.flexChart1;
  128.             foreach (Series s in chart.Series)
  129.             {
  130.                 if (s.Binding == ColName)
  131.                 {
  132.                     rst = true;
  133.                     break;
  134.                 }
  135.             }

  136.             return rst;
  137.         }

  138.         private void button1_Click(object sender, EventArgs e)
  139.         {
  140.             var chart = flexChart1;

  141.             chart.BeginUpdate();

  142.             chart.AxisX.Title = "Col1";
  143.             chart.AxisY.Title = "Col2";
  144.             chart.BindingX = "Col1";
  145.             chart.AxisX.AxisLine = true;
  146.             chart.AxisX.MajorGrid = true;
  147.             chart.AxisY.Position = Position.Left;
  148.             chart.AxisY.AxisLine = true;

  149.             for (int i = 1; i < ds.Tables.Count; i++)
  150.             {
  151.                 var curSeries = new Series()
  152.                 {
  153.                     Name = $"{ds.Tables[i].TableName}_Col2",
  154.                     Binding = "Col2",
  155.                     ChartType = ChartType.SplineSymbols,
  156.                     SymbolMarker = (SymbolMarker)1,
  157.                     Style =
  158.                     {
  159.                         StrokeWidth = 2,
  160.                         StrokeColor = colorList[i],
  161.                     },
  162.                     DataSource = ds.Tables[i],
  163.                 };
  164.                 chart.Series.Add(curSeries);

  165.                 var seriesY2 = new Series()
  166.                 {
  167.                     Name = $"{ds.Tables[i].TableName}_Col3",
  168.                     Binding = "Col3",
  169.                     ChartType = ChartType.SplineSymbols,
  170.                     SymbolMarker = (SymbolMarker)2,
  171.                     Style =
  172.                     {
  173.                         StrokeWidth = 2,
  174.                         StrokeColor = colorList[i],
  175.                     },
  176.                     DataSource = ds.Tables[i],
  177.                     //AxisY = new Axis()
  178.                     //{
  179.                     //    Position = Position.Right,
  180.                     //    Title = "Y2(Col3)",
  181.                     //    AxisLine = true,
  182.                     //    LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
  183.                     //},
  184.                 };
  185.                 if (!GetHaveTypeSeries("Col3"))
  186.                 {
  187.                     seriesY2.AxisY = new Axis()
  188.                     {
  189.                         Position = Position.Right,
  190.                         Title = "Y2(Col3)",
  191.                         AxisLine = true,
  192.                         //LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
  193.                     };
  194.                 }
  195.                 chart.Series.Add(seriesY2);

  196.                 var seriesY3 = new Series()
  197.                 {
  198.                     Name = $"{ds.Tables[i].TableName}_Col4",
  199.                     Binding = "Col4",
  200.                     ChartType = ChartType.SplineSymbols,
  201.                     SymbolMarker = (SymbolMarker)7,
  202.                     Style =
  203.                     {
  204.                         StrokeWidth = 2,
  205.                         StrokeColor = colorList[i],
  206.                     },
  207.                     DataSource = ds.Tables[i],
  208.                     //AxisY = new Axis()
  209.                     //{
  210.                     //    Position = Position.Right,
  211.                     //    Title = "Y3(Col4)",
  212.                     //    AxisLine = true,
  213.                     //    //LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
  214.                     //},
  215.                 };
  216.                 if (!GetHaveTypeSeries("Col4"))
  217.                 {
  218.                     seriesY3.AxisY = new Axis()
  219.                     {
  220.                         Position = Position.Right,
  221.                         Title = "Y3(Col4)",
  222.                         AxisLine = true,
  223.                         //LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
  224.                     };
  225.                 }
  226.                 chart.Series.Add(seriesY3);
  227.             }

  228.             chart.EndUpdate();
  229.             chart.Refresh();
  230.         }
  231.     }
复制代码
回复 使用道具 举报
ud7070
初级会员   /  发表于:2023-5-11 11:35:29
9#
Richard.Ma 发表于 2023-5-11 11:29
你是给多个series 绑定同一个Y轴,那么应该是自己new一个Y轴对象出来,然后每次添加series时设置,这样才对 ...

好的,我试一下
回复 使用道具 举报
Richard.Ma讲师达人认证 悬赏达人认证 SpreadJS 开发认证
超级版主   /  发表于:2023-5-11 14:25:11
10#
好的
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部