- public partial class Form2 : Form
- {
- DataSet ds = new DataSet();
- List<Color> colorList = new List<Color>() { Color.Blue, Color.Red, Color.Green, Color.AliceBlue };
- public Form2()
- {
- InitializeComponent();
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- for (int i = 0; i < 3; i++)
- {
- DataTable objTb = new DataTable();
- objTb.TableName = $"objTb{i + 1}";
- objTb.Columns.Add("Col1", typeof(int));
- objTb.Columns.Add("Col2", typeof(int));
- objTb.Columns.Add("Col3", typeof(int));
- objTb.Columns.Add("Col4", typeof(int));
- for(int r = 0; r < 20; r++)
- {
- DataRow newRow = objTb.NewRow();
- newRow[0] = r;
- for (int c = 1; c < 4; c++)
- {
- newRow[c] = r * Math.Pow((c + 1), 2) * (i == 0 ? 1 : Math.Pow(i, c)) + Math.Pow(i, c) + Math.Pow(r, i + c);
- }
- objTb.Rows.Add(newRow);
- }
- ds.Tables.Add(objTb);
- }
- var chart = flexChart1;
- chart.BeginUpdate();
- chart.AxisX.Title = "Col1";
- chart.AxisY.Title = "Col2";
- chart.BindingX = "Col1";
- chart.AxisX.AxisLine = true;
- chart.AxisX.MajorGrid = true;
- chart.AxisY.Position = Position.Left;
- chart.AxisY.AxisLine = true;
- //for (int i = 0; i < ds.Tables.Count; i++)
- //for (int i = ds.Tables.Count - 1; i >= 0; i--)//可以看到Y3最大坐标
- for (int i = 0; i < 1; i++)
- {
- var curSeries = new Series()
- {
- Name = $"{ds.Tables[i].TableName}_Col2",
- Binding = "Col2",
- ChartType = ChartType.SplineSymbols,
- SymbolMarker = (SymbolMarker)1,
- Style =
- {
- StrokeWidth = 2,
- StrokeColor = colorList[i],
- },
- DataSource = ds.Tables[i],
- };
- chart.Series.Add(curSeries);
- var seriesY2 = new Series()
- {
- Name = $"{ds.Tables[i].TableName}_Col3",
- Binding = "Col3",
- ChartType = ChartType.SplineSymbols,
- SymbolMarker = (SymbolMarker)2,
- Style =
- {
- StrokeWidth = 2,
- StrokeColor = colorList[i],
- },
- DataSource = ds.Tables[i],
- //AxisY = new Axis()
- //{
- // Position = Position.Right,
- // Title = "Y2(Col3)",
- // AxisLine = true,
- // LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
- //},
- };
- if (!GetHaveTypeSeries("Col3"))
- {
- seriesY2.AxisY = new Axis()
- {
- Position = Position.Right,
- Title = "Y2(Col3)",
- AxisLine = true,
- //LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
- };
- }
- chart.Series.Add(seriesY2);
- var seriesY3 = new Series()
- {
- Name = $"{ds.Tables[i].TableName}_Col4",
- Binding = "Col4",
- ChartType = ChartType.SplineSymbols,
- SymbolMarker = (SymbolMarker)7,
- Style =
- {
- StrokeWidth = 2,
- StrokeColor = colorList[i],
- },
- DataSource = ds.Tables[i],
- //AxisY = new Axis()
- //{
- // Position = Position.Right,
- // Title = "Y3(Col4)",
- // AxisLine = true,
- // LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
- //},
- };
- if (!GetHaveTypeSeries("Col4"))
- {
- seriesY3.AxisY = new Axis()
- {
- Position = Position.Right,
- Title = "Y3(Col4)",
- AxisLine = true,
- //LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
- };
- }
- chart.Series.Add(seriesY3);
- }
- chart.EndUpdate();
- chart.Refresh();
- }
- bool GetHaveTypeSeries(string ColName)
- {
- bool rst = false;
- var chart = this.flexChart1;
- foreach (Series s in chart.Series)
- {
- if (s.Binding == ColName)
- {
- rst = true;
- break;
- }
- }
- return rst;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- var chart = flexChart1;
- chart.BeginUpdate();
- chart.AxisX.Title = "Col1";
- chart.AxisY.Title = "Col2";
- chart.BindingX = "Col1";
- chart.AxisX.AxisLine = true;
- chart.AxisX.MajorGrid = true;
- chart.AxisY.Position = Position.Left;
- chart.AxisY.AxisLine = true;
- for (int i = 1; i < ds.Tables.Count; i++)
- {
- var curSeries = new Series()
- {
- Name = $"{ds.Tables[i].TableName}_Col2",
- Binding = "Col2",
- ChartType = ChartType.SplineSymbols,
- SymbolMarker = (SymbolMarker)1,
- Style =
- {
- StrokeWidth = 2,
- StrokeColor = colorList[i],
- },
- DataSource = ds.Tables[i],
- };
- chart.Series.Add(curSeries);
- var seriesY2 = new Series()
- {
- Name = $"{ds.Tables[i].TableName}_Col3",
- Binding = "Col3",
- ChartType = ChartType.SplineSymbols,
- SymbolMarker = (SymbolMarker)2,
- Style =
- {
- StrokeWidth = 2,
- StrokeColor = colorList[i],
- },
- DataSource = ds.Tables[i],
- //AxisY = new Axis()
- //{
- // Position = Position.Right,
- // Title = "Y2(Col3)",
- // AxisLine = true,
- // LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
- //},
- };
- if (!GetHaveTypeSeries("Col3"))
- {
- seriesY2.AxisY = new Axis()
- {
- Position = Position.Right,
- Title = "Y2(Col3)",
- AxisLine = true,
- //LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
- };
- }
- chart.Series.Add(seriesY2);
- var seriesY3 = new Series()
- {
- Name = $"{ds.Tables[i].TableName}_Col4",
- Binding = "Col4",
- ChartType = ChartType.SplineSymbols,
- SymbolMarker = (SymbolMarker)7,
- Style =
- {
- StrokeWidth = 2,
- StrokeColor = colorList[i],
- },
- DataSource = ds.Tables[i],
- //AxisY = new Axis()
- //{
- // Position = Position.Right,
- // Title = "Y3(Col4)",
- // AxisLine = true,
- // //LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
- //},
- };
- if (!GetHaveTypeSeries("Col4"))
- {
- seriesY3.AxisY = new Axis()
- {
- Position = Position.Right,
- Title = "Y3(Col4)",
- AxisLine = true,
- //LogBase = (ConfigurationManager.AppSettings["Y2AxisLog"].ToString().ToLower() == "true") ? double.Parse(ConfigurationManager.AppSettings["Y2AxisLogNum"].ToString()) : double.NaN,
- };
- }
- chart.Series.Add(seriesY3);
- }
- chart.EndUpdate();
- chart.Refresh();
- }
- }
复制代码 |