张奎师弟参与devexpress chartControl绘图--解决了devexpress的chartControl控件不能添加系列的问题
1 using DevExpress.XtraCharts; 2 using System; 3 using System.Collections.Generic; 4 using System.ComponentModel; 5 using System.Data; 6 using System.Drawing; 7 using System.Linq; 8 using System.Text; 9 using System.Windows.Forms; 10 11 12 namespace WindowsFormsApplication1张奎 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 24 25 #region 26 //int tabPagesCount = 0; 27 //ChartControl chartControl1 = new ChartControl(); 28 29 //// Create two series. 30 //Series series1 = new Series("Series 1", ViewType.Bar); 31 //Series series2 = new Series("Series 2", ViewType.Line); 32 33 //// Add points to them, with their arguments different. 34 //series1.Points.Add(new SeriesPoint("A", 10)); 35 //series1.Points.Add(new SeriesPoint("B", 12)); 36 //series1.Points.Add(new SeriesPoint("C", 17)); 37 //series1.Points.Add(new SeriesPoint("D", 14)); 38 //series2.Points.Add(new SeriesPoint("I", 2500)); 39 //series2.Points.Add(new SeriesPoint("II", 3800)); 40 //series2.Points.Add(new SeriesPoint("III", 1500)); 41 //series2.Points.Add(new SeriesPoint("IV", 1300)); 42 43 //// Add both series to the chart. 44 //chartControl1.Series.AddRange(new Series[] { series1, series2 }); 45 46 //// Hide the legend (optional). 47 //chartControl1.Legend.Visible = false; 48 49 //// Cast the chart's diagram to the XYDiagram type, 50 //// to access its axes and panes. 51 //XYDiagram diagram = (XYDiagram)chartControl1.Diagram; 52 53 //// Add secondary axes to the diagram, and adjust their options. 54 //diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 55 //diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 56 //diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 57 //diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 58 59 //// Add a new additional pane to the diagram. 60 //diagram.Panes.Add(new XYDiagramPane("My Pane")); 61 62 //// Assign both the additional pane and, if required, 63 //// the secondary axes to the second series. 64 //LineSeriesView myView = (LineSeriesView)series2.View; 65 //myView.AxisX = diagram.SecondaryAxesX[0]; 66 //myView.AxisY = diagram.SecondaryAxesY[0]; 67 //// Note that the created pane has the zero index in the collection, 68 //// because the existing Default pane is a separate entity. 69 //myView.Pane = diagram.Panes[0]; 70 71 //// Customize the layout of the diagram's panes. 72 //diagram.PaneDistance = 10; 73 //diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 74 //diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 75 //diagram.DefaultPane.Weight = 1.2; 76 77 //// Add the chart to the form. 78 //chartControl1.Dock = DockStyle.Fill; 79 ////this.Controls.Add(chartControl1); 80 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 81 //tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 82 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1); 83 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 84 85 86 //// 87 //ChartControl chartControl2 = new ChartControl(); 88 89 //// Create two series. 90 //Series series3 = new Series("Series 3", ViewType.Bar); 91 //Series series4= new Series("Series 4", ViewType.Line); 92 93 //// Add points to them, with their arguments different. 94 //series3.Points.Add(new SeriesPoint("A", 10)); 95 //series3.Points.Add(new SeriesPoint("B", 12)); 96 //series3.Points.Add(new SeriesPoint("C", 17)); 97 //series3.Points.Add(new SeriesPoint("D", 14)); 98 //series4.Points.Add(new SeriesPoint("I", 2500)); 99 //series4.Points.Add(new SeriesPoint("II", 3800)); 100 //series4.Points.Add(new SeriesPoint("III", 1500)); 101 //series4.Points.Add(new SeriesPoint("IV", 1300)); 102 103 //// Add both series to the chart. 104 //chartControl2.Series.AddRange(new Series[] { series3, series4 }); 105 106 //// Hide the legend (optional). 107 //chartControl2.Legend.Visible = false; 108 109 //// Cast the chart's diagram to the XYDiagram type, 110 //// to access its axes and panes. 111 //XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; 112 113 //// Add secondary axes to the diagram, and adjust their options. 114 //diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 115 //diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 116 //diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 117 //diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 118 119 //// Add a new additional pane to the diagram. 120 //diagram2.Panes.Add(new XYDiagramPane("My Pane")); 121 122 //// Assign both the additional pane and, if required, 123 //// the secondary axes to the second series. 124 //LineSeriesView myView2 = (LineSeriesView)series2.View; 125 //myView2.AxisX = diagram2.SecondaryAxesX[0]; 126 //myView2.AxisY = diagram2.SecondaryAxesY[0]; 127 //// Note that the created pane has the zero index in the collection, 128 //// because the existing Default pane is a separate entity. 129 //myView2.Pane = diagram2.Panes[0]; 130 131 //// Customize the layout of the diagram's panes. 132 //diagram2.PaneDistance = 10; 133 //diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 134 //diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 135 //diagram2.DefaultPane.Weight = 1.2; 136 137 //// Add the chart to the form. 138 //chartControl2.Dock = DockStyle.Fill; 139 ////this.Controls.Add(chartControl1); 140 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 141 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 142 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2); 143 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 144 145 #endregion 146 147 148 this.xtraTabPage1.PageVisible = false; 149 this.xtraTabPage2.PageVisible = false; 150 this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 151 ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl 152 lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 153 154 //产生数据 155 List<double> xaxesList = new List<double>();//x轴数据 156 List<double> ySinList = new List<double>();//系列1-y轴数据 157 List<double> yCosList = new List<double>();//系列2-y轴数据 158 List<double> yTanList = new List<double>();//系列3-y轴数据 159 for (int i = 0; i < 20; i++) 160 { 161 xaxesList.Add(i); 162 ySinList.Add(Math.Sin(i)); 163 yCosList.Add(0.8*Math.Sin(i)); 164 yTanList.Add(Math.Sin(i) + Math.Cos(i)); 165 } 166 //将所有系列的y值放入一个列表,这个列表是列表的列表 167 List<List<double>> YList = new List<List<double>>(); 168 YList.Add(ySinList); 169 YList.Add(yCosList); 170 YList.Add(yTanList); 171 //系列内容名称 172 List<string> seriesTextList = new List<string>();//系列内容名称 173 seriesTextList.Add("预测曲线"); 174 seriesTextList.Add("实验值"); 175 seriesTextList.Add("cos+sin"); 176 //系列名称 177 List<Series> seriesNameList = new List<Series>(); 178 for (int i = 0; i < 3; i++) 179 { 180 //完全建立一个系列,以后直接用就行了 181 seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 182 } 183 //将系列假如chartControl 184 for (int seriesIndex = 0; seriesIndex < 3; seriesIndex++) 185 { 186 if(seriesIndex==0) 187 ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); 188 189 else if (seriesIndex==1) 190 ShowSeries(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 191 192 193 } 194 //显示 195 int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 196 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中 197 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 198 199 200 201 202 203 //尝试第二个图 204 this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 205 ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl 206 lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 207 208 //产生数据 209 List<double> xaxesList2 = new List<double>();//x轴数据 210 List<double> ySinList2 = new List<double>();//系列1-y轴数据 211 List<double> yCosList2 = new List<double>();//系列2-y轴数据 212 List<double> y08sinList2 = new List<double>();//系列3-y轴数据 213 List<double> y05sinList2 = new List<double>(); 214 for (int i = 0; i < 20; i++) 215 { 216 xaxesList2.Add(i); 217 ySinList2.Add(Math.Cos(i)); 218 yCosList2.Add(0.8*Math.Cos(i)); 219 y08sinList2.Add(0.6 * Math.Sin(i)); 220 y05sinList2.Add(0.5*Math.Sin(i)); 221 222 } 223 //将所有系列的y值放入一个列表,这个列表是列表的列表 224 List<List<double>> YList2 = new List<List<double>>(); 225 YList2.Add(ySinList2); 226 YList2.Add(yCosList2); 227 YList2.Add(y08sinList2); 228 YList2.Add(y05sinList2); 229 230 //系列内容名称 231 List<string> seriesTextList2 = new List<string>();//系列内容名称 232 seriesTextList2.Add("预测曲线"); 233 seriesTextList2.Add("实验值"); 234 seriesTextList2.Add("预测曲线2"); 235 seriesTextList2.Add("实验值2"); 236 237 238 //系列名称 239 List<Series> seriesNameList2 = new List<Series>(); 240 for (int i = 0; i < 4; i++) 241 { 242 //完全建立一个系列,以后直接用就行了 243 seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 244 } 245 //将系列加入chartControl 246 for (int seriesIndex = 0; seriesIndex < 4; seriesIndex++) 247 { 248 if(seriesIndex==0 || seriesIndex==2) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce 249 ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); 250 251 else 252 ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 253 } 254 //显示 255 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 256 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中 257 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 258 259 260 261 } 262 public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 263 List<double> yAxes, int iMarkerKind) 264 { 265 266 //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 267 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 268 ((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle 269 ((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; 270 271 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 272 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 273 { 274 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 275 } 276 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 277 lineChartControl.Legend.Visible = true;//图例可见 278 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 279 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 280 } 281 282 public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 283 List<double> yAxes) 284 { 285 286 //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 287 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 288 289 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 290 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 291 { 292 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 293 } 294 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 295 lineChartControl.Legend.Visible = true;//图例可见 296 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 297 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 298 } 299 300 private void Form1_Load(object sender, EventArgs e) 301 { 302 303 } 304 305 306 } 307 }
1 using DevExpress.XtraCharts; 2 using System; 3 using System.Collections.Generic; 4 using System.ComponentModel; 5 using System.Data; 6 using System.Drawing; 7 using System.Linq; 8 using System.Text; 9 using System.Windows.Forms; 10 11 12 namespace WindowsFormsApplication1张奎 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 24 25 #region 26 //int tabPagesCount = 0; 27 //ChartControl chartControl1 = new ChartControl(); 28 29 //// Create two series. 30 //Series series1 = new Series("Series 1", ViewType.Bar); 31 //Series series2 = new Series("Series 2", ViewType.Line); 32 33 //// Add points to them, with their arguments different. 34 //series1.Points.Add(new SeriesPoint("A", 10)); 35 //series1.Points.Add(new SeriesPoint("B", 12)); 36 //series1.Points.Add(new SeriesPoint("C", 17)); 37 //series1.Points.Add(new SeriesPoint("D", 14)); 38 //series2.Points.Add(new SeriesPoint("I", 2500)); 39 //series2.Points.Add(new SeriesPoint("II", 3800)); 40 //series2.Points.Add(new SeriesPoint("III", 1500)); 41 //series2.Points.Add(new SeriesPoint("IV", 1300)); 42 43 //// Add both series to the chart. 44 //chartControl1.Series.AddRange(new Series[] { series1, series2 }); 45 46 //// Hide the legend (optional). 47 //chartControl1.Legend.Visible = false; 48 49 //// Cast the chart's diagram to the XYDiagram type, 50 //// to access its axes and panes. 51 //XYDiagram diagram = (XYDiagram)chartControl1.Diagram; 52 53 //// Add secondary axes to the diagram, and adjust their options. 54 //diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 55 //diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 56 //diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 57 //diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 58 59 //// Add a new additional pane to the diagram. 60 //diagram.Panes.Add(new XYDiagramPane("My Pane")); 61 62 //// Assign both the additional pane and, if required, 63 //// the secondary axes to the second series. 64 //LineSeriesView myView = (LineSeriesView)series2.View; 65 //myView.AxisX = diagram.SecondaryAxesX[0]; 66 //myView.AxisY = diagram.SecondaryAxesY[0]; 67 //// Note that the created pane has the zero index in the collection, 68 //// because the existing Default pane is a separate entity. 69 //myView.Pane = diagram.Panes[0]; 70 71 //// Customize the layout of the diagram's panes. 72 //diagram.PaneDistance = 10; 73 //diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 74 //diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 75 //diagram.DefaultPane.Weight = 1.2; 76 77 //// Add the chart to the form. 78 //chartControl1.Dock = DockStyle.Fill; 79 ////this.Controls.Add(chartControl1); 80 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 81 //tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 82 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1); 83 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 84 85 86 //// 87 //ChartControl chartControl2 = new ChartControl(); 88 89 //// Create two series. 90 //Series series3 = new Series("Series 3", ViewType.Bar); 91 //Series series4= new Series("Series 4", ViewType.Line); 92 93 //// Add points to them, with their arguments different. 94 //series3.Points.Add(new SeriesPoint("A", 10)); 95 //series3.Points.Add(new SeriesPoint("B", 12)); 96 //series3.Points.Add(new SeriesPoint("C", 17)); 97 //series3.Points.Add(new SeriesPoint("D", 14)); 98 //series4.Points.Add(new SeriesPoint("I", 2500)); 99 //series4.Points.Add(new SeriesPoint("II", 3800)); 100 //series4.Points.Add(new SeriesPoint("III", 1500)); 101 //series4.Points.Add(new SeriesPoint("IV", 1300)); 102 103 //// Add both series to the chart. 104 //chartControl2.Series.AddRange(new Series[] { series3, series4 }); 105 106 //// Hide the legend (optional). 107 //chartControl2.Legend.Visible = false; 108 109 //// Cast the chart's diagram to the XYDiagram type, 110 //// to access its axes and panes. 111 //XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; 112 113 //// Add secondary axes to the diagram, and adjust their options. 114 //diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 115 //diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 116 //diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 117 //diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 118 119 //// Add a new additional pane to the diagram. 120 //diagram2.Panes.Add(new XYDiagramPane("My Pane")); 121 122 //// Assign both the additional pane and, if required, 123 //// the secondary axes to the second series. 124 //LineSeriesView myView2 = (LineSeriesView)series2.View; 125 //myView2.AxisX = diagram2.SecondaryAxesX[0]; 126 //myView2.AxisY = diagram2.SecondaryAxesY[0]; 127 //// Note that the created pane has the zero index in the collection, 128 //// because the existing Default pane is a separate entity. 129 //myView2.Pane = diagram2.Panes[0]; 130 131 //// Customize the layout of the diagram's panes. 132 //diagram2.PaneDistance = 10; 133 //diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 134 //diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 135 //diagram2.DefaultPane.Weight = 1.2; 136 137 //// Add the chart to the form. 138 //chartControl2.Dock = DockStyle.Fill; 139 ////this.Controls.Add(chartControl1); 140 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 141 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 142 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2); 143 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 144 145 #endregion 146 147 148 this.xtraTabPage1.PageVisible = false; 149 this.xtraTabPage2.PageVisible = false; 150 this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 151 ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl 152 lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 153 154 //产生数据 155 List<double> xaxesList = new List<double>();//x轴数据 156 List<double> ySinList = new List<double>();//系列1-y轴数据 157 List<double> yCosList = new List<double>();//系列2-y轴数据 158 List<double> ySinAddCosList = new List<double>();//系列3-y轴数据 159 List<double> y08SinAddCosList = new List<double>();//系列3-y轴数据 160 for (int i = 0; i < 20; i++) 161 { 162 xaxesList.Add(i); 163 ySinList.Add(Math.Sin(i)); 164 yCosList.Add(0.8*Math.Sin(i)); 165 ySinAddCosList.Add(Math.Sin(i) + Math.Cos(i)); 166 y08SinAddCosList.Add(0.8*Math.Sin(i) + Math.Cos(i)); 167 } 168 //将所有系列的y值放入一个列表,这个列表是列表的列表 169 List<List<double>> YList = new List<List<double>>(); 170 YList.Add(ySinList); 171 YList.Add(yCosList); 172 YList.Add(ySinAddCosList); 173 YList.Add(y08SinAddCosList); 174 //系列内容名称 175 List<string> seriesTextList = new List<string>();//系列内容名称 176 seriesTextList.Add("SINX"); 177 seriesTextList.Add("0.8*SINX"); 178 seriesTextList.Add("cos+sin"); 179 seriesTextList.Add("cos+0.8*sin"); 180 //系列名称 181 List<Series> seriesNameList = new List<Series>(); 182 for (int i = 0; i < 4; i++) 183 { 184 //完全建立一个系列,以后直接用就行了 185 seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 186 } 187 188 189 190 //产生数据 191 List<double> xaxesList2 = new List<double>();//x轴数据 192 List<double> ySinList2 = new List<double>();//系列1-y轴数据 193 List<double> yCosList2 = new List<double>();//系列2-y轴数据 194 List<double> y08sinList2 = new List<double>();//系列3-y轴数据 195 List<double> y05sinList2 = new List<double>(); 196 for (int i = 0; i < 20; i++) 197 { 198 xaxesList2.Add(i); 199 ySinList2.Add(Math.Cos(i)); 200 yCosList2.Add(0.8 * Math.Cos(i)); 201 y08sinList2.Add(0.6 * Math.Sin(i)); 202 y05sinList2.Add(0.5 * Math.Sin(i)); 203 204 } 205 //将所有系列的y值放入一个列表,这个列表是列表的列表 206 List<List<double>> YList2 = new List<List<double>>(); 207 YList2.Add(ySinList2); 208 YList2.Add(yCosList2); 209 YList2.Add(y08sinList2); 210 YList2.Add(y05sinList2); 211 212 //系列内容名称 213 List<string> seriesTextList2 = new List<string>();//系列内容名称 214 seriesTextList2.Add("预测曲线"); 215 seriesTextList2.Add("实验值"); 216 seriesTextList2.Add("预测曲线2"); 217 seriesTextList2.Add("实验值2"); 218 219 220 //系列名称 221 List<Series> seriesNameList2 = new List<Series>(); 222 for (int i = 0; i < 4; i++) 223 { 224 //完全建立一个系列,以后直接用就行了 225 seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 226 } 227 228 //将系列假如chartControl 229 for (int seriesIndex = 0; seriesIndex < 4; seriesIndex++) 230 { 231 if(seriesIndex%2==0) 232 ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 233 234 else 235 ShowSeries(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 236 237 238 } 239 //显示 240 int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 241 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中 242 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 243 244 245 246 247 248 //尝试第二个图 249 this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 250 ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl 251 lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 252 253 254 //将系列加入chartControl 255 for (int seriesIndex = 0; seriesIndex < 4; seriesIndex++) 256 { 257 if(seriesIndex==0 || seriesIndex==2) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce 258 ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 259 260 else 261 ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 262 } 263 //显示 264 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 265 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中 266 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 267 268 269 //尝试第三个图 270 this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 271 ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl 272 lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 273 274 275 //将系列加入chartControl 276 for (int seriesIndex = 0; seriesIndex < 4; seriesIndex++) 277 { 278 if (seriesIndex == 0 || seriesIndex == 2) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce 279 ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 280 281 else 282 ShowSeries(lineChartControl3, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 283 } 284 //显示 285 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 286 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中 287 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 288 289 290 //尝试第四个图 291 this.xtraTabControl1.TabPages.Add("三角函数图4");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 292 ChartControl lineChartControl4 = new ChartControl();//实例化一个ChartControl 293 lineChartControl4.Legend.UseCheckBoxes = true;//图例可以勾选 294 //将系列假如chartControl 295 for (int seriesIndex = 0; seriesIndex < 4; seriesIndex++) 296 { 297 if (seriesIndex % 2 == 0) 298 ShowSeries_yuce(lineChartControl4, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 299 300 else 301 ShowSeries(lineChartControl4, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 302 303 304 } 305 //显示 306 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 307 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中 308 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 309 310 311 312 313 } 314 public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 315 List<double> yAxes, int iMarkerKind) 316 { 317 318 //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 319 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 320 ((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle 321 ((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; 322 323 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 324 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 325 { 326 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 327 } 328 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 329 lineChartControl.Legend.Visible = true;//图例可见 330 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 331 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 332 } 333 334 public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 335 List<double> yAxes, int iMarkerKind) 336 { 337 338 //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 339 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 340 //((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle 341 //((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; 342 343 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 344 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 345 { 346 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 347 } 348 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 349 lineChartControl.Legend.Visible = true;//图例可见 350 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 351 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 352 } 353 354 private void Form1_Load(object sender, EventArgs e) 355 { 356 357 } 358 359 360 } 361 }
1 using DevExpress.XtraCharts; 2 using System; 3 using System.Collections.Generic; 4 using System.ComponentModel; 5 using System.Data; 6 using System.Drawing; 7 using System.Linq; 8 using System.Text; 9 using System.Windows.Forms; 10 11 12 namespace WindowsFormsApplication1张奎 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 24 25 #region 26 //int tabPagesCount = 0; 27 //ChartControl chartControl1 = new ChartControl(); 28 29 //// Create two series. 30 //Series series1 = new Series("Series 1", ViewType.Bar); 31 //Series series2 = new Series("Series 2", ViewType.Line); 32 33 //// Add points to them, with their arguments different. 34 //series1.Points.Add(new SeriesPoint("A", 10)); 35 //series1.Points.Add(new SeriesPoint("B", 12)); 36 //series1.Points.Add(new SeriesPoint("C", 17)); 37 //series1.Points.Add(new SeriesPoint("D", 14)); 38 //series2.Points.Add(new SeriesPoint("I", 2500)); 39 //series2.Points.Add(new SeriesPoint("II", 3800)); 40 //series2.Points.Add(new SeriesPoint("III", 1500)); 41 //series2.Points.Add(new SeriesPoint("IV", 1300)); 42 43 //// Add both series to the chart. 44 //chartControl1.Series.AddRange(new Series[] { series1, series2 }); 45 46 //// Hide the legend (optional). 47 //chartControl1.Legend.Visible = false; 48 49 //// Cast the chart's diagram to the XYDiagram type, 50 //// to access its axes and panes. 51 //XYDiagram diagram = (XYDiagram)chartControl1.Diagram; 52 53 //// Add secondary axes to the diagram, and adjust their options. 54 //diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 55 //diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 56 //diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 57 //diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 58 59 //// Add a new additional pane to the diagram. 60 //diagram.Panes.Add(new XYDiagramPane("My Pane")); 61 62 //// Assign both the additional pane and, if required, 63 //// the secondary axes to the second series. 64 //LineSeriesView myView = (LineSeriesView)series2.View; 65 //myView.AxisX = diagram.SecondaryAxesX[0]; 66 //myView.AxisY = diagram.SecondaryAxesY[0]; 67 //// Note that the created pane has the zero index in the collection, 68 //// because the existing Default pane is a separate entity. 69 //myView.Pane = diagram.Panes[0]; 70 71 //// Customize the layout of the diagram's panes. 72 //diagram.PaneDistance = 10; 73 //diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 74 //diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 75 //diagram.DefaultPane.Weight = 1.2; 76 77 //// Add the chart to the form. 78 //chartControl1.Dock = DockStyle.Fill; 79 ////this.Controls.Add(chartControl1); 80 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 81 //tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 82 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1); 83 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 84 85 86 //// 87 //ChartControl chartControl2 = new ChartControl(); 88 89 //// Create two series. 90 //Series series3 = new Series("Series 3", ViewType.Bar); 91 //Series series4= new Series("Series 4", ViewType.Line); 92 93 //// Add points to them, with their arguments different. 94 //series3.Points.Add(new SeriesPoint("A", 10)); 95 //series3.Points.Add(new SeriesPoint("B", 12)); 96 //series3.Points.Add(new SeriesPoint("C", 17)); 97 //series3.Points.Add(new SeriesPoint("D", 14)); 98 //series4.Points.Add(new SeriesPoint("I", 2500)); 99 //series4.Points.Add(new SeriesPoint("II", 3800)); 100 //series4.Points.Add(new SeriesPoint("III", 1500)); 101 //series4.Points.Add(new SeriesPoint("IV", 1300)); 102 103 //// Add both series to the chart. 104 //chartControl2.Series.AddRange(new Series[] { series3, series4 }); 105 106 //// Hide the legend (optional). 107 //chartControl2.Legend.Visible = false; 108 109 //// Cast the chart's diagram to the XYDiagram type, 110 //// to access its axes and panes. 111 //XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; 112 113 //// Add secondary axes to the diagram, and adjust their options. 114 //diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 115 //diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 116 //diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 117 //diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 118 119 //// Add a new additional pane to the diagram. 120 //diagram2.Panes.Add(new XYDiagramPane("My Pane")); 121 122 //// Assign both the additional pane and, if required, 123 //// the secondary axes to the second series. 124 //LineSeriesView myView2 = (LineSeriesView)series2.View; 125 //myView2.AxisX = diagram2.SecondaryAxesX[0]; 126 //myView2.AxisY = diagram2.SecondaryAxesY[0]; 127 //// Note that the created pane has the zero index in the collection, 128 //// because the existing Default pane is a separate entity. 129 //myView2.Pane = diagram2.Panes[0]; 130 131 //// Customize the layout of the diagram's panes. 132 //diagram2.PaneDistance = 10; 133 //diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 134 //diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 135 //diagram2.DefaultPane.Weight = 1.2; 136 137 //// Add the chart to the form. 138 //chartControl2.Dock = DockStyle.Fill; 139 ////this.Controls.Add(chartControl1); 140 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 141 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 142 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2); 143 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 144 145 #endregion 146 147 148 this.xtraTabPage1.PageVisible = false; 149 this.xtraTabPage2.PageVisible = false; 150 this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 151 ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl 152 lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 153 154 //产生数据 155 List<double> xaxesList = new List<double>();//x轴数据 156 List<double> ySinList = new List<double>();//系列1-y轴数据 157 List<double> yCosList = new List<double>();//系列2-y轴数据 158 List<double> yTanList = new List<double>();//系列3-y轴数据 159 List<double> y08TanList = new List<double>();//系列3-y轴数据 160 List<double> ySinCosList = new List<double>();//系列3-y轴数据 161 List<double> ySinDICosList = new List<double>();//系列3-y轴数据 162 for (int i = 0; i < 20; i++) 163 { 164 xaxesList.Add(i); 165 ySinList.Add(Math.Sin(i)); 166 yCosList.Add(0.8*Math.Sin(i)); 167 yTanList.Add(Math.Sin(i) + Math.Cos(i)); 168 y08TanList.Add(0.8*Math.Sin(i) + Math.Cos(i)); 169 ySinCosList.Add(Math.Sin(i) * Math.Cos(i)); 170 ySinDICosList.Add( Math.Sin(i)*(i%2+0.5)); 171 } 172 //将所有系列的y值放入一个列表,这个列表是列表的列表 173 List<List<double>> YList = new List<List<double>>(); 174 YList.Add(ySinList); 175 YList.Add(yCosList); 176 YList.Add(yTanList); 177 YList.Add(y08TanList); 178 YList.Add(ySinCosList); 179 YList.Add(ySinDICosList); 180 //系列内容名称 181 List<string> seriesTextList = new List<string>();//系列内容名称 182 seriesTextList.Add("预测曲线"); 183 seriesTextList.Add("实验值"); 184 seriesTextList.Add("cos+sin"); 185 seriesTextList.Add("cos+0.8*sin"); 186 seriesTextList.Add("cos*sin"); 187 seriesTextList.Add("sin/cos"); 188 189 //系列名称 190 List<Series> seriesNameList = new List<Series>(); 191 for (int i = 0; i < 6; i++) 192 { 193 //完全建立一个系列,以后直接用就行了 194 seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 195 } 196 //将系列假如chartControl 197 for (int seriesIndex = 0; seriesIndex <6; seriesIndex++) 198 { 199 if(seriesIndex%2==0) 200 ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); 201 else 202 ShowSeries(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 203 204 205 } 206 //显示 207 int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 208 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中 209 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 210 211 212 213 214 215 //尝试第二个图 216 this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 217 ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl 218 lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 219 220 //产生数据 221 List<double> xaxesList2 = new List<double>();//x轴数据 222 List<double> ySinList2 = new List<double>();//系列1-y轴数据 223 List<double> yCosList2 = new List<double>();//系列2-y轴数据 224 List<double> y08sinList2 = new List<double>();//系列3-y轴数据 225 List<double> y05sinList2 = new List<double>(); 226 List<double> ySinCosList2 = new List<double>(); 227 List<double> ySinDICosList2 = new List<double>(); 228 for (int i = 0; i < 20; i++) 229 { 230 xaxesList2.Add(i); 231 ySinList2.Add(Math.Cos(i)); 232 yCosList2.Add(0.8*Math.Cos(i)); 233 y08sinList2.Add(0.6 * Math.Sin(i)); 234 y05sinList2.Add(0.5*Math.Sin(i)); 235 ySinCosList2.Add(0.8*Math.Sin(i) * Math.Cos(i)); 236 ySinDICosList2.Add(0.8*Math.Sin(i)*(i%2+0.5)); 237 238 } 239 //将所有系列的y值放入一个列表,这个列表是列表的列表 240 List<List<double>> YList2 = new List<List<double>>(); 241 YList2.Add(ySinList2); 242 YList2.Add(yCosList2); 243 YList2.Add(y08sinList2); 244 YList2.Add(y05sinList2); 245 YList2.Add(ySinCosList2); 246 YList2.Add(ySinDICosList2); 247 248 //系列内容名称 249 List<string> seriesTextList2 = new List<string>();//系列内容名称 250 seriesTextList2.Add("预测曲线"); 251 seriesTextList2.Add("实验值"); 252 seriesTextList2.Add("预测曲线2"); 253 seriesTextList2.Add("实验值2"); 254 seriesTextList2.Add("ySinCosList22"); 255 seriesTextList2.Add("ySinDICosList22"); 256 257 258 //系列名称 259 List<Series> seriesNameList2 = new List<Series>(); 260 for (int i = 0; i < 6; i++) 261 { 262 //完全建立一个系列,以后直接用就行了 263 seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 264 } 265 //将系列加入chartControl 266 for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 267 { 268 if(seriesIndex%2==0) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce 269 ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); 270 271 else 272 ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 273 } 274 //显示 275 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 276 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中 277 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 278 279 280 281 } 282 public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 283 List<double> yAxes, int iMarkerKind) 284 { 285 286 //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 287 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 288 ((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle 289 ((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; 290 291 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 292 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 293 { 294 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 295 } 296 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 297 lineChartControl.Legend.Visible = true;//图例可见 298 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 299 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 300 } 301 302 public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 303 List<double> yAxes) 304 { 305 306 //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 307 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 308 309 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 310 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 311 { 312 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 313 } 314 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 315 lineChartControl.Legend.Visible = true;//图例可见 316 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 317 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 318 } 319 320 private void Form1_Load(object sender, EventArgs e) 321 { 322 323 } 324 325 326 } 327 }
1 using DevExpress.XtraCharts; 2 using System; 3 using System.Collections.Generic; 4 using System.ComponentModel; 5 using System.Data; 6 using System.Drawing; 7 using System.Linq; 8 using System.Text; 9 using System.Windows.Forms; 10 11 12 namespace WindowsFormsApplication1张奎 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 24 25 #region 26 //int tabPagesCount = 0; 27 //ChartControl chartControl1 = new ChartControl(); 28 29 //// Create two series. 30 //Series series1 = new Series("Series 1", ViewType.Bar); 31 //Series series2 = new Series("Series 2", ViewType.Line); 32 33 //// Add points to them, with their arguments different. 34 //series1.Points.Add(new SeriesPoint("A", 10)); 35 //series1.Points.Add(new SeriesPoint("B", 12)); 36 //series1.Points.Add(new SeriesPoint("C", 17)); 37 //series1.Points.Add(new SeriesPoint("D", 14)); 38 //series2.Points.Add(new SeriesPoint("I", 2500)); 39 //series2.Points.Add(new SeriesPoint("II", 3800)); 40 //series2.Points.Add(new SeriesPoint("III", 1500)); 41 //series2.Points.Add(new SeriesPoint("IV", 1300)); 42 43 //// Add both series to the chart. 44 //chartControl1.Series.AddRange(new Series[] { series1, series2 }); 45 46 //// Hide the legend (optional). 47 //chartControl1.Legend.Visible = false; 48 49 //// Cast the chart's diagram to the XYDiagram type, 50 //// to access its axes and panes. 51 //XYDiagram diagram = (XYDiagram)chartControl1.Diagram; 52 53 //// Add secondary axes to the diagram, and adjust their options. 54 //diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 55 //diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 56 //diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 57 //diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 58 59 //// Add a new additional pane to the diagram. 60 //diagram.Panes.Add(new XYDiagramPane("My Pane")); 61 62 //// Assign both the additional pane and, if required, 63 //// the secondary axes to the second series. 64 //LineSeriesView myView = (LineSeriesView)series2.View; 65 //myView.AxisX = diagram.SecondaryAxesX[0]; 66 //myView.AxisY = diagram.SecondaryAxesY[0]; 67 //// Note that the created pane has the zero index in the collection, 68 //// because the existing Default pane is a separate entity. 69 //myView.Pane = diagram.Panes[0]; 70 71 //// Customize the layout of the diagram's panes. 72 //diagram.PaneDistance = 10; 73 //diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 74 //diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 75 //diagram.DefaultPane.Weight = 1.2; 76 77 //// Add the chart to the form. 78 //chartControl1.Dock = DockStyle.Fill; 79 ////this.Controls.Add(chartControl1); 80 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 81 //tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 82 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1); 83 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 84 85 86 //// 87 //ChartControl chartControl2 = new ChartControl(); 88 89 //// Create two series. 90 //Series series3 = new Series("Series 3", ViewType.Bar); 91 //Series series4= new Series("Series 4", ViewType.Line); 92 93 //// Add points to them, with their arguments different. 94 //series3.Points.Add(new SeriesPoint("A", 10)); 95 //series3.Points.Add(new SeriesPoint("B", 12)); 96 //series3.Points.Add(new SeriesPoint("C", 17)); 97 //series3.Points.Add(new SeriesPoint("D", 14)); 98 //series4.Points.Add(new SeriesPoint("I", 2500)); 99 //series4.Points.Add(new SeriesPoint("II", 3800)); 100 //series4.Points.Add(new SeriesPoint("III", 1500)); 101 //series4.Points.Add(new SeriesPoint("IV", 1300)); 102 103 //// Add both series to the chart. 104 //chartControl2.Series.AddRange(new Series[] { series3, series4 }); 105 106 //// Hide the legend (optional). 107 //chartControl2.Legend.Visible = false; 108 109 //// Cast the chart's diagram to the XYDiagram type, 110 //// to access its axes and panes. 111 //XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; 112 113 //// Add secondary axes to the diagram, and adjust their options. 114 //diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 115 //diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 116 //diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 117 //diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 118 119 //// Add a new additional pane to the diagram. 120 //diagram2.Panes.Add(new XYDiagramPane("My Pane")); 121 122 //// Assign both the additional pane and, if required, 123 //// the secondary axes to the second series. 124 //LineSeriesView myView2 = (LineSeriesView)series2.View; 125 //myView2.AxisX = diagram2.SecondaryAxesX[0]; 126 //myView2.AxisY = diagram2.SecondaryAxesY[0]; 127 //// Note that the created pane has the zero index in the collection, 128 //// because the existing Default pane is a separate entity. 129 //myView2.Pane = diagram2.Panes[0]; 130 131 //// Customize the layout of the diagram's panes. 132 //diagram2.PaneDistance = 10; 133 //diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 134 //diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 135 //diagram2.DefaultPane.Weight = 1.2; 136 137 //// Add the chart to the form. 138 //chartControl2.Dock = DockStyle.Fill; 139 ////this.Controls.Add(chartControl1); 140 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 141 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 142 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2); 143 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 144 145 #endregion 146 147 148 this.xtraTabPage1.PageVisible = false; 149 this.xtraTabPage2.PageVisible = false; 150 this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 151 ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl 152 lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 153 154 //产生数据 155 List<double> xaxesList = new List<double>();//x轴数据 156 List<double> ySinList = new List<double>();//系列1-y轴数据 157 List<double> yCosList = new List<double>();//系列2-y轴数据 158 List<double> yTanList = new List<double>();//系列3-y轴数据 159 List<double> y08TanList = new List<double>();//系列3-y轴数据 160 List<double> ySinCosList = new List<double>();//系列3-y轴数据 161 List<double> ySinDICosList = new List<double>();//系列3-y轴数据 162 for (int i = 0; i < 20; i++) 163 { 164 xaxesList.Add(i); 165 ySinList.Add(Math.Sin(i)); 166 yCosList.Add(0.8*Math.Sin(i)); 167 yTanList.Add(Math.Sin(i) + Math.Cos(i)); 168 y08TanList.Add(0.8*Math.Sin(i) + Math.Cos(i)); 169 ySinCosList.Add(Math.Sin(i) * Math.Cos(i)); 170 ySinDICosList.Add( Math.Sin(i)*(i%2+0.5)); 171 } 172 //将所有系列的y值放入一个列表,这个列表是列表的列表 173 List<List<double>> YList = new List<List<double>>(); 174 YList.Add(ySinList); 175 YList.Add(yCosList); 176 YList.Add(yTanList); 177 YList.Add(y08TanList); 178 YList.Add(ySinCosList); 179 YList.Add(ySinDICosList); 180 //系列内容名称 181 List<string> seriesTextList = new List<string>();//系列内容名称 182 seriesTextList.Add("预测曲线"); 183 seriesTextList.Add("实验值"); 184 seriesTextList.Add("cos+sin"); 185 seriesTextList.Add("cos+0.8*sin"); 186 seriesTextList.Add("cos*sin"); 187 seriesTextList.Add("sin/cos"); 188 189 //系列名称 190 List<Series> seriesNameList = new List<Series>(); 191 for (int i = 0; i < 6; i++) 192 { 193 //完全建立一个系列,以后直接用就行了 194 seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 195 } 196 //将系列假如chartControl 197 for (int seriesIndex = 0; seriesIndex <6; seriesIndex++) 198 { 199 if(seriesIndex%2==0) 200 ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); 201 else 202 ShowSeries(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 203 204 205 } 206 //显示 207 int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 208 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中 209 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 210 211 212 213 214 215 //尝试第二个图 216 this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 217 ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl 218 lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 219 220 //产生数据 221 List<double> xaxesList2 = new List<double>();//x轴数据 222 List<double> ySinList2 = new List<double>();//系列1-y轴数据 223 List<double> yCosList2 = new List<double>();//系列2-y轴数据 224 List<double> y08sinList2 = new List<double>();//系列3-y轴数据 225 List<double> y05sinList2 = new List<double>(); 226 List<double> ySinCosList2 = new List<double>(); 227 List<double> ySinDICosList2 = new List<double>(); 228 for (int i = 0; i < 20; i++) 229 { 230 xaxesList2.Add(i); 231 ySinList2.Add(Math.Cos(i)); 232 yCosList2.Add(0.8*Math.Cos(i)); 233 y08sinList2.Add(0.6 * Math.Sin(i)); 234 y05sinList2.Add(0.5*Math.Sin(i)); 235 ySinCosList2.Add(0.8*Math.Sin(i) * Math.Cos(i)); 236 ySinDICosList2.Add(0.8*Math.Sin(i)*(i%2+0.5)); 237 238 } 239 //将所有系列的y值放入一个列表,这个列表是列表的列表 240 List<List<double>> YList2 = new List<List<double>>(); 241 YList2.Add(ySinList2); 242 YList2.Add(yCosList2); 243 YList2.Add(y08sinList2); 244 YList2.Add(y05sinList2); 245 YList2.Add(ySinCosList2); 246 YList2.Add(ySinDICosList2); 247 248 //系列内容名称 249 List<string> seriesTextList2 = new List<string>();//系列内容名称 250 seriesTextList2.Add("预测曲线"); 251 seriesTextList2.Add("实验值"); 252 seriesTextList2.Add("预测曲线2"); 253 seriesTextList2.Add("实验值2"); 254 seriesTextList2.Add("ySinCosList22"); 255 seriesTextList2.Add("ySinDICosList22"); 256 257 258 //系列名称 259 List<Series> seriesNameList2 = new List<Series>(); 260 for (int i = 0; i < 6; i++) 261 { 262 //完全建立一个系列,以后直接用就行了 263 seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 264 } 265 //将系列加入chartControl 266 for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 267 { 268 if(seriesIndex%2==0) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce 269 ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); 270 271 else 272 ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 273 } 274 //显示 275 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 276 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中 277 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 278 279 280 //图3 281 this.xtraTabPage1.PageVisible = false; 282 this.xtraTabPage2.PageVisible = false; 283 this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 284 ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl 285 lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 286 287 288 //将系列假如chartControl 289 for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 290 { 291 if (seriesIndex % 2 == 0) 292 ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); 293 else 294 ShowSeries(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 295 296 297 } 298 //显示 299 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 300 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中 301 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 302 303 304 305 306 307 } 308 public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 309 List<double> yAxes, int iMarkerKind) 310 { 311 312 //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 313 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 314 //((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle 315 //((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; 316 317 //((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 318 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 319 { 320 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 321 } 322 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 323 lineChartControl.Legend.Visible = true;//图例可见 324 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 325 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 326 } 327 328 public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 329 List<double> yAxes) 330 { 331 332 //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 333 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 334 335 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 336 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 337 { 338 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 339 } 340 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 341 lineChartControl.Legend.Visible = true;//图例可见 342 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 343 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 344 } 345 346 private void Form1_Load(object sender, EventArgs e) 347 { 348 349 } 350 351 352 } 353 }
师弟最后解决了(就是在showseries子函数中添加了:
seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
这一句):
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Text; 7 using System.Linq; 8 using System.Windows.Forms; 9 using DevExpress.XtraEditors; 10 using DevExpress; 11 using DevExpress.XtraCharts; 12 13 14 15 namespace DXApplication5 16 { 17 public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm 18 { 19 public XtraForm1() 20 { 21 InitializeComponent(); 22 } 23 24 private void button1_Click(object sender, EventArgs e) 25 { 26 //this.xtraTabPage1.PageVisible = false; 27 //this.xtraTabPage2.PageVisible = false; 28 29 30 ////////////////////////////////////////////////////////////////////////////////////////////////// 31 32 //产生数据 1 33 List<double> xaxesList = new List<double>();//x轴数据 34 List<double> ySinList = new List<double>();//系列1-y轴数据 35 List<double> yCosList = new List<double>();//系列2-y轴数据 36 List<double> ySinAddCosList = new List<double>();//系列3-y轴数据 37 List<double> y08SinAddCosList = new List<double>();//系列3-y轴数据 38 List<double> y07SinAddCosList = new List<double>(); 39 List<double> y06SinAddCosList = new List<double>(); 40 41 for (int i = 0; i < 20; i++) 42 { 43 xaxesList.Add(i); 44 ySinList.Add(Math.Sin(i)); 45 yCosList.Add(0.8 * Math.Sin(i)); 46 ySinAddCosList.Add(Math.Sin(i) + Math.Cos(i)); 47 y08SinAddCosList.Add(0.8 * Math.Sin(i) + Math.Cos(i)); 48 y07SinAddCosList.Add(0.7 * Math.Sin(i) + Math.Cos(i)); 49 y06SinAddCosList.Add(0.6 * Math.Sin(i) + Math.Cos(i)); 50 } 51 52 //将所有系列的y值放入一个列表,这个列表是列表的列表 53 List<List<double>> YList = new List<List<double>>(); 54 YList.Add(ySinList); 55 YList.Add(yCosList); 56 YList.Add(ySinAddCosList); 57 YList.Add(y08SinAddCosList); 58 YList.Add(y07SinAddCosList); 59 YList.Add(y06SinAddCosList); 60 61 62 //系列内容名称 63 List<string> seriesTextList = new List<string>();//系列内容名称 64 seriesTextList.Add("预测曲线"); 65 seriesTextList.Add("实验值"); 66 seriesTextList.Add("预测曲线2"); 67 seriesTextList.Add("实验值2"); 68 seriesTextList.Add("y07SinAddCosList"); 69 seriesTextList.Add("y06SinAddCosList"); 70 71 //系列名称 72 List<Series> seriesNameList = new List<Series>(); 73 for (int i = 0; i < 6; i++) 74 { 75 //完全建立一个系列,以后直接用就行了 76 seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 77 } 78 79 80 81 82 //产生数据2////////////////////////////////////////////////////////////// 83 List<double> xaxesList2 = new List<double>();//x轴数据 84 List<double> ySinList2 = new List<double>();//系列1-y轴数据 85 List<double> yCosList2 = new List<double>();//系列2-y轴数据 86 List<double> ySinAddCosList2 = new List<double>();//系列3-y轴数据 87 List<double> y08SinAddCosList2 = new List<double>();//系列3-y轴数据 88 List<double> y07SinAddCosList2 = new List<double>(); 89 List<double> y06SinAddCosList2 = new List<double>(); 90 for (int i = 0; i < 20; i++) 91 { 92 xaxesList2.Add(i); 93 ySinList2.Add(2*Math.Sin(i)); 94 yCosList2.Add(1.8 * Math.Sin(i)); 95 ySinAddCosList2.Add(2.5*Math.Sin(i) + 2.5*Math.Cos(i)); 96 y08SinAddCosList2.Add(2.0 * Math.Sin(i) + 2.0*Math.Cos(i)); 97 y07SinAddCosList2.Add(2.0*0.7 * Math.Sin(i) + 2.0 * Math.Cos(i)); 98 y06SinAddCosList2.Add(2.0 *0.6* Math.Sin(i) + 2.0 * Math.Cos(i)); 99 } 100 101 //将所有系列的y值放入一个列表,这个列表是列表的列表 102 List<List<double>> YList2 = new List<List<double>>(); 103 YList2.Add(ySinList2); 104 YList2.Add(yCosList2); 105 YList2.Add(ySinAddCosList2); 106 YList2.Add(y08SinAddCosList2); 107 YList2.Add(y07SinAddCosList2); 108 YList2.Add(y06SinAddCosList2); 109 110 111 //系列内容名称 112 List<string> seriesTextList2 = new List<string>();//系列内容名称 113 seriesTextList2.Add("预测曲线"); 114 seriesTextList2.Add("实验值"); 115 seriesTextList2.Add("预测曲线2"); 116 seriesTextList2.Add("实验值2"); 117 seriesTextList2.Add("y07SinAddCosList2"); 118 seriesTextList2.Add("y07SinAddCosList2"); 119 120 //系列名称 121 List<Series> seriesNameList2 = new List<Series>(); 122 for (int i = 0; i < 6; i++) 123 { 124 //完全建立一个系列,以后直接用就行了 125 seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 126 } 127 128 129 130 //产生数据3////////////////////////////////////////////////////////////// 131 List<double> xaxesList3 = new List<double>();//x轴数据 132 List<double> ySinList3 = new List<double>();//系列1-y轴数据 133 List<double> yCosList3 = new List<double>();//系列2-y轴数据 134 List<double> ySinAddCosList3 = new List<double>();//系列3-y轴数据 135 List<double> y08SinAddCosList3 = new List<double>();//系列3-y轴数据 136 List<double> y07SinAddCosList3 = new List<double>();// 137 List<double> y06SinAddCosList3 = new List<double>();// 138 139 for (int i = 0; i < 20; i++) 140 { 141 xaxesList3.Add(i); 142 ySinList3.Add(5 * Math.Sin(i)); 143 yCosList3.Add(5.8 * Math.Sin(i)); 144 ySinAddCosList3.Add(4.15 * Math.Sin(i) + 4.15 * Math.Cos(i)); 145 y08SinAddCosList3.Add(5.1 * Math.Sin(i) + 5.1 * Math.Cos(i)); 146 y07SinAddCosList3.Add(0.7*5.1 * Math.Sin(i) + 5.1 * Math.Cos(i)); 147 y06SinAddCosList3.Add(0.6*5.1 * Math.Sin(i) + 5.1 * Math.Cos(i)); 148 } 149 150 //将所有系列的y值放入一个列表,这个列表是列表的列表 151 List<List<double>> YList3 = new List<List<double>>(); 152 YList3.Add(ySinList3); 153 YList3.Add(yCosList3); 154 YList3.Add(ySinAddCosList3); 155 YList3.Add(y08SinAddCosList3); 156 YList3.Add(y07SinAddCosList3); 157 YList3.Add(y06SinAddCosList3); 158 159 160 //系列内容名称 161 List<string> seriesTextList3 = new List<string>();//系列内容名称 162 seriesTextList3.Add("预测曲线"); 163 seriesTextList3.Add("实验值"); 164 seriesTextList3.Add("预测曲线2"); 165 seriesTextList3.Add("实验值2"); 166 seriesTextList3.Add("y07SinAddCosList3"); 167 seriesTextList3.Add("y06SinAddCosList3"); 168 169 //系列名称 170 List<Series> seriesNameList3 = new List<Series>(); 171 for (int i = 0; i < 6; i++) 172 { 173 //完全建立一个系列,以后直接用就行了 174 seriesNameList3.Add(new Series(seriesTextList3[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 175 } 176 177 178 ////////////////////第一张图//////////////////////////////////////////// 179 180 //1.新建TabPage和ChartControl 181 this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 182 ChartControl lineChartControl1 = new ChartControl();//实例化一个ChartControl 183 lineChartControl1.Legend.UseCheckBoxes = true;//图例可以勾选 184 185 //2.将系列加入chartControl 186 for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 187 { 188 //if (seriesIndex % 2 == 0) 189 ShowSeries_yuce(lineChartControl1, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 190 191 // else 192 ShowSeries(lineChartControl1, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 193 194 } 195 196 //3.显示 197 int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 198 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl1);//将ChartControl这个控件添加到这个page中 199 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 200 201 202 203 204 205 ///////////////////第二个图/////////////////////////////////////////////////// 206 //1.新建TabPage和ChartControl 207 this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 208 ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl 209 lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 210 211 212 //2.将系列加入chartControl 213 for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 214 { 215 //if (seriesIndex == 0 || seriesIndex == 2) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce 216 ShowSeries_yuce(lineChartControl2, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 217 218 //else 219 ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 220 } 221 //3.显示 222 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 223 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中 224 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 225 226 227 //////////////////第3个图///////////////////////////////////////////////////// 228 //1.新建TabPage和ChartControl 229 this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 230 ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl 231 lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 232 233 //2.将系列加入chartControl 234 for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 235 { 236 // if (seriesIndex % 2 == 0) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce 237 ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 238 239 //else 240 ShowSeries(lineChartControl3, seriesNameList3[seriesIndex], seriesTextList3[seriesIndex], xaxesList3, YList3[seriesIndex], seriesIndex); 241 } 242 243 //3.显示 244 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 245 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中 246 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 247 248 249 //////////////////第4个图///////////////////////////////////////////////////// 250 //1.新建TabPage和ChartControl 251 this.xtraTabControl1.TabPages.Add("三角函数图4");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 252 ChartControl lineChartControl4 = new ChartControl();//实例化一个ChartControl 253 lineChartControl4.Legend.UseCheckBoxes = true;//图例可以勾选 254 255 //2.将系列假如chartControl 256 for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 257 { 258 //if (seriesIndex % 2 == 0) 259 ShowSeries_yuce(lineChartControl4, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 260 261 //else 262 ShowSeries(lineChartControl4, seriesNameList3[seriesIndex], seriesTextList3[seriesIndex], xaxesList3, YList3[seriesIndex], seriesIndex); 263 264 265 } 266 267 //3.显示 268 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 269 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl4);//将ChartControl这个控件添加到这个page中 270 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 271 } 272 273 ////////////////////////////////////////////////////////////////////////////////////////////// 274 //ShowSeries和ShowSeries_yuce 275 public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 276 List<double> yAxes, int iMarkerKind) 277 { 278 seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 279 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 280 ((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle 281 ((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; 282 283 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 284 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 285 { 286 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 287 } 288 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 289 lineChartControl.Legend.Visible = true;//图例可见 290 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 291 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 292 } 293 294 public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 295 List<double> yAxes, int iMarkerKind) 296 { 297 298 seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 299 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 300 //((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle 301 //((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; 302 303 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 304 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 305 { 306 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 307 } 308 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 309 lineChartControl.Legend.Visible = true;//图例可见 310 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 311 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 312 } 313 } 314 }
下面尝试改变每条线的颜色:
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Text; 7 using System.Linq; 8 using System.Windows.Forms; 9 using DevExpress.XtraEditors; 10 using DevExpress; 11 using DevExpress.XtraCharts; 12 13 namespace DXApplication1借鉴张奎师弟 14 { 15 public partial class Form1 : DevExpress.XtraEditors.XtraForm 16 { 17 public Form1() 18 { 19 InitializeComponent(); 20 } 21 22 private void button1_Click(object sender, EventArgs e) 23 { 24 25 26 27 #region 28 //int tabPagesCount = 0; 29 //ChartControl chartControl1 = new ChartControl(); 30 31 //// Create two series. 32 //Series series1 = new Series("Series 1", ViewType.Bar); 33 //Series series2 = new Series("Series 2", ViewType.Line); 34 35 //// Add points to them, with their arguments different. 36 //series1.Points.Add(new SeriesPoint("A", 10)); 37 //series1.Points.Add(new SeriesPoint("B", 12)); 38 //series1.Points.Add(new SeriesPoint("C", 17)); 39 //series1.Points.Add(new SeriesPoint("D", 14)); 40 //series2.Points.Add(new SeriesPoint("I", 2500)); 41 //series2.Points.Add(new SeriesPoint("II", 3800)); 42 //series2.Points.Add(new SeriesPoint("III", 1500)); 43 //series2.Points.Add(new SeriesPoint("IV", 1300)); 44 45 //// Add both series to the chart. 46 //chartControl1.Series.AddRange(new Series[] { series1, series2 }); 47 48 //// Hide the legend (optional). 49 //chartControl1.Legend.Visible = false; 50 51 //// Cast the chart's diagram to the XYDiagram type, 52 //// to access its axes and panes. 53 //XYDiagram diagram = (XYDiagram)chartControl1.Diagram; 54 55 //// Add secondary axes to the diagram, and adjust their options. 56 //diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 57 //diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 58 //diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 59 //diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 60 61 //// Add a new additional pane to the diagram. 62 //diagram.Panes.Add(new XYDiagramPane("My Pane")); 63 64 //// Assign both the additional pane and, if required, 65 //// the secondary axes to the second series. 66 //LineSeriesView myView = (LineSeriesView)series2.View; 67 //myView.AxisX = diagram.SecondaryAxesX[0]; 68 //myView.AxisY = diagram.SecondaryAxesY[0]; 69 //// Note that the created pane has the zero index in the collection, 70 //// because the existing Default pane is a separate entity. 71 //myView.Pane = diagram.Panes[0]; 72 73 //// Customize the layout of the diagram's panes. 74 //diagram.PaneDistance = 10; 75 //diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 76 //diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 77 //diagram.DefaultPane.Weight = 1.2; 78 79 //// Add the chart to the form. 80 //chartControl1.Dock = DockStyle.Fill; 81 ////this.Controls.Add(chartControl1); 82 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 83 //tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 84 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1); 85 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 86 87 88 //// 89 //ChartControl chartControl2 = new ChartControl(); 90 91 //// Create two series. 92 //Series series3 = new Series("Series 3", ViewType.Bar); 93 //Series series4= new Series("Series 4", ViewType.Line); 94 95 //// Add points to them, with their arguments different. 96 //series3.Points.Add(new SeriesPoint("A", 10)); 97 //series3.Points.Add(new SeriesPoint("B", 12)); 98 //series3.Points.Add(new SeriesPoint("C", 17)); 99 //series3.Points.Add(new SeriesPoint("D", 14)); 100 //series4.Points.Add(new SeriesPoint("I", 2500)); 101 //series4.Points.Add(new SeriesPoint("II", 3800)); 102 //series4.Points.Add(new SeriesPoint("III", 1500)); 103 //series4.Points.Add(new SeriesPoint("IV", 1300)); 104 105 //// Add both series to the chart. 106 //chartControl2.Series.AddRange(new Series[] { series3, series4 }); 107 108 //// Hide the legend (optional). 109 //chartControl2.Legend.Visible = false; 110 111 //// Cast the chart's diagram to the XYDiagram type, 112 //// to access its axes and panes. 113 //XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; 114 115 //// Add secondary axes to the diagram, and adjust their options. 116 //diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 117 //diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 118 //diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 119 //diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 120 121 //// Add a new additional pane to the diagram. 122 //diagram2.Panes.Add(new XYDiagramPane("My Pane")); 123 124 //// Assign both the additional pane and, if required, 125 //// the secondary axes to the second series. 126 //LineSeriesView myView2 = (LineSeriesView)series2.View; 127 //myView2.AxisX = diagram2.SecondaryAxesX[0]; 128 //myView2.AxisY = diagram2.SecondaryAxesY[0]; 129 //// Note that the created pane has the zero index in the collection, 130 //// because the existing Default pane is a separate entity. 131 //myView2.Pane = diagram2.Panes[0]; 132 133 //// Customize the layout of the diagram's panes. 134 //diagram2.PaneDistance = 10; 135 //diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 136 //diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 137 //diagram2.DefaultPane.Weight = 1.2; 138 139 //// Add the chart to the form. 140 //chartControl2.Dock = DockStyle.Fill; 141 ////this.Controls.Add(chartControl1); 142 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 143 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 144 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2); 145 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 146 147 #endregion 148 149 150 this.xtraTabPage1.PageVisible = false; 151 this.xtraTabPage2.PageVisible = false; 152 this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 153 ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl 154 lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 155 156 //产生数据 157 List<double> xaxesList = new List<double>();//x轴数据 158 List<double> ySinList = new List<double>();//系列1-y轴数据 159 List<double> yCosList = new List<double>();//系列2-y轴数据 160 List<double> ySinAddCosList = new List<double>();//系列3-y轴数据 161 162 for (int i = 0; i < 20; i++) 163 { 164 xaxesList.Add(i); 165 ySinList.Add(Math.Sin(i)); 166 yCosList.Add(Math.Cos(i)); 167 ySinAddCosList.Add(Math.Sin(i) + Math.Cos(i)); 168 169 } 170 //将所有系列的y值放入一个列表,这个列表是列表的列表 171 List<List<double>> YList = new List<List<double>>(); 172 YList.Add(ySinList); 173 YList.Add(yCosList); 174 YList.Add(ySinAddCosList); 175 176 //系列内容名称 177 List<string> seriesTextList = new List<string>();//系列内容名称 178 seriesTextList.Add("sin理论"); 179 seriesTextList.Add("cos理论"); 180 seriesTextList.Add("cos+sin理论"); 181 182 183 //系列名称 184 List<Series> seriesNameList = new List<Series>(); 185 for (int i = 0; i < 3; i++) 186 { 187 //完全建立一个系列,以后直接用就行了 188 seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 189 } 190 191 192 193 //产生数据2 194 List<double> xaxesList2 = new List<double>();//x轴数据 195 List<double> ySinList2 = new List<double>();//系列1-y轴数据 196 List<double> yCosList2 = new List<double>();//系列2-y轴数据 197 List<double> ySinAddCosList2 = new List<double>();//系列3-y轴数据 198 199 for (int i = 0; i < 20; i++) 200 { 201 xaxesList2.Add(i); 202 ySinList2.Add(0.8*Math.Sin(i)); 203 yCosList2.Add(0.8 * Math.Cos(i)); 204 ySinAddCosList2.Add(0.8 * Math.Sin(i) + 0.8 * Math.Cos(i)); 205 206 207 } 208 //将所有系列的y值放入一个列表,这个列表是列表的列表 209 List<List<double>> YList2 = new List<List<double>>(); 210 YList2.Add(ySinList2); 211 YList2.Add(yCosList2); 212 YList2.Add(ySinAddCosList2); 213 214 215 //系列内容名称 216 List<string> seriesTextList2 = new List<string>();//系列内容名称 217 seriesTextList2.Add("sin实验"); 218 seriesTextList2.Add("cos实验"); 219 seriesTextList2.Add("sin+cos实验"); 220 221 //系列名称 222 List<Series> seriesNameList2 = new List<Series>(); 223 for (int i = 0; i < 3; i++) 224 { 225 //完全建立一个系列,以后直接用就行了 226 seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 227 } 228 229 230 231 232 233 //将系列加入chartControl 234 for (int seriesIndex = 0; seriesIndex <3; seriesIndex++) 235 { 236 237 ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); 238 239 ShowSeries(lineChartControl, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 240 241 } 242 //显示 243 int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 244 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中 245 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 246 247 248 249 250 251 ////尝试第二个图 252 //this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 253 //ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl 254 //lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 255 256 257 ////将系列加入chartControl 258 //for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 259 //{ 260 // if(seriesIndex%2==0) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce 261 // ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); 262 263 // else 264 // ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 265 //} 266 ////显示 267 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 268 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中 269 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 270 271 272 // //图3 273 // this.xtraTabPage1.PageVisible = false; 274 // this.xtraTabPage2.PageVisible = false; 275 // this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 276 // ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl 277 // lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 278 279 280 // //将系列假如chartControl 281 // for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 282 // { 283 // if (seriesIndex % 2 == 0) 284 // ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); 285 // else 286 // ShowSeries(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 287 288 289 // } 290 // //显示 291 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 292 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中 293 // this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 294 295 296 297 298 299 } 300 public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 301 List<double> yAxes, int iMarkerKind) 302 { 303 304 seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 305 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 306 ((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle 307 ((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; 308 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash; 309 310 311 //((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 312 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 313 { 314 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 315 } 316 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 317 lineChartControl.Legend.Visible = true;//图例可见 318 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 319 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 320 } 321 322 public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 323 List<double> yAxes) 324 { 325 326 seriesName = new Series(seriesText, ViewType.Spline);//新建立一个系列 327 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 328 329 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Solid;//线型 330 331 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 332 { 333 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 334 } 335 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 336 lineChartControl.Legend.Visible = true;//图例可见 337 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 338 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 339 } 340 341 private void Form1_Load(object sender, EventArgs e) 342 { 343 344 } 345 346 347 348 349 350 351 } 352 }
可以变颜色了:
上图的代码(当然,要拉取一个窗口,加入chartcontrol控件,目的是自动加入对应的引用,之后可以删除,因为可以用代码添加chartcontrol。加入xtratabcontrol,目的是盛放图。再加入一个button即可,将下面代码放入button1内(设计模式下双击button即可进入其对应的代码)),其实要解决不能添加series的问题的关键是在showSeries函数中再新建series:
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Text; 7 using System.Linq; 8 using System.Windows.Forms; 9 using DevExpress.XtraEditors; 10 using DevExpress; 11 using DevExpress.XtraCharts; 12 13 namespace DXApplication1借鉴张奎师弟 14 { 15 public partial class Form1 : DevExpress.XtraEditors.XtraForm 16 { 17 public Form1() 18 { 19 InitializeComponent(); 20 } 21 22 private void button1_Click(object sender, EventArgs e) 23 { 24 25 26 27 #region 28 //int tabPagesCount = 0; 29 //ChartControl chartControl1 = new ChartControl(); 30 31 //// Create two series. 32 //Series series1 = new Series("Series 1", ViewType.Bar); 33 //Series series2 = new Series("Series 2", ViewType.Line); 34 35 //// Add points to them, with their arguments different. 36 //series1.Points.Add(new SeriesPoint("A", 10)); 37 //series1.Points.Add(new SeriesPoint("B", 12)); 38 //series1.Points.Add(new SeriesPoint("C", 17)); 39 //series1.Points.Add(new SeriesPoint("D", 14)); 40 //series2.Points.Add(new SeriesPoint("I", 2500)); 41 //series2.Points.Add(new SeriesPoint("II", 3800)); 42 //series2.Points.Add(new SeriesPoint("III", 1500)); 43 //series2.Points.Add(new SeriesPoint("IV", 1300)); 44 45 //// Add both series to the chart. 46 //chartControl1.Series.AddRange(new Series[] { series1, series2 }); 47 48 //// Hide the legend (optional). 49 //chartControl1.Legend.Visible = false; 50 51 //// Cast the chart's diagram to the XYDiagram type, 52 //// to access its axes and panes. 53 //XYDiagram diagram = (XYDiagram)chartControl1.Diagram; 54 55 //// Add secondary axes to the diagram, and adjust their options. 56 //diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 57 //diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 58 //diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 59 //diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 60 61 //// Add a new additional pane to the diagram. 62 //diagram.Panes.Add(new XYDiagramPane("My Pane")); 63 64 //// Assign both the additional pane and, if required, 65 //// the secondary axes to the second series. 66 //LineSeriesView myView = (LineSeriesView)series2.View; 67 //myView.AxisX = diagram.SecondaryAxesX[0]; 68 //myView.AxisY = diagram.SecondaryAxesY[0]; 69 //// Note that the created pane has the zero index in the collection, 70 //// because the existing Default pane is a separate entity. 71 //myView.Pane = diagram.Panes[0]; 72 73 //// Customize the layout of the diagram's panes. 74 //diagram.PaneDistance = 10; 75 //diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 76 //diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 77 //diagram.DefaultPane.Weight = 1.2; 78 79 //// Add the chart to the form. 80 //chartControl1.Dock = DockStyle.Fill; 81 ////this.Controls.Add(chartControl1); 82 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 83 //tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 84 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1); 85 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 86 87 88 //// 89 //ChartControl chartControl2 = new ChartControl(); 90 91 //// Create two series. 92 //Series series3 = new Series("Series 3", ViewType.Bar); 93 //Series series4= new Series("Series 4", ViewType.Line); 94 95 //// Add points to them, with their arguments different. 96 //series3.Points.Add(new SeriesPoint("A", 10)); 97 //series3.Points.Add(new SeriesPoint("B", 12)); 98 //series3.Points.Add(new SeriesPoint("C", 17)); 99 //series3.Points.Add(new SeriesPoint("D", 14)); 100 //series4.Points.Add(new SeriesPoint("I", 2500)); 101 //series4.Points.Add(new SeriesPoint("II", 3800)); 102 //series4.Points.Add(new SeriesPoint("III", 1500)); 103 //series4.Points.Add(new SeriesPoint("IV", 1300)); 104 105 //// Add both series to the chart. 106 //chartControl2.Series.AddRange(new Series[] { series3, series4 }); 107 108 //// Hide the legend (optional). 109 //chartControl2.Legend.Visible = false; 110 111 //// Cast the chart's diagram to the XYDiagram type, 112 //// to access its axes and panes. 113 //XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; 114 115 //// Add secondary axes to the diagram, and adjust their options. 116 //diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 117 //diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 118 //diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 119 //diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 120 121 //// Add a new additional pane to the diagram. 122 //diagram2.Panes.Add(new XYDiagramPane("My Pane")); 123 124 //// Assign both the additional pane and, if required, 125 //// the secondary axes to the second series. 126 //LineSeriesView myView2 = (LineSeriesView)series2.View; 127 //myView2.AxisX = diagram2.SecondaryAxesX[0]; 128 //myView2.AxisY = diagram2.SecondaryAxesY[0]; 129 //// Note that the created pane has the zero index in the collection, 130 //// because the existing Default pane is a separate entity. 131 //myView2.Pane = diagram2.Panes[0]; 132 133 //// Customize the layout of the diagram's panes. 134 //diagram2.PaneDistance = 10; 135 //diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 136 //diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 137 //diagram2.DefaultPane.Weight = 1.2; 138 139 //// Add the chart to the form. 140 //chartControl2.Dock = DockStyle.Fill; 141 ////this.Controls.Add(chartControl1); 142 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 143 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 144 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2); 145 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 146 147 #endregion 148 149 150 this.xtraTabPage1.PageVisible = false; 151 this.xtraTabPage2.PageVisible = false; 152 this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 153 ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl 154 lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 155 156 //产生数据 157 List<double> xaxesList = new List<double>();//x轴数据 158 List<double> ySinList = new List<double>();//系列1-y轴数据 159 List<double> yCosList = new List<double>();//系列2-y轴数据 160 List<double> ySinAddCosList = new List<double>();//系列3-y轴数据 161 List<double> ySinMinCosList = new List<double>(); 162 163 for (int i = 0; i < 20; i++) 164 { 165 xaxesList.Add(i); 166 ySinList.Add(Math.Sin(i)); 167 yCosList.Add(Math.Cos(i)); 168 ySinAddCosList.Add(Math.Sin(i) + Math.Cos(i)); 169 ySinMinCosList.Add(Math.Sin(i) - Math.Cos(i)); 170 } 171 //将所有系列的y值放入一个列表,这个列表是列表的列表 172 List<List<double>> YList = new List<List<double>>(); 173 YList.Add(ySinList); 174 YList.Add(yCosList); 175 YList.Add(ySinAddCosList); 176 YList.Add(ySinMinCosList); 177 178 //系列内容名称 179 List<string> seriesTextList = new List<string>();//系列内容名称 180 seriesTextList.Add("sin理论"); 181 seriesTextList.Add("cos理论"); 182 seriesTextList.Add("sin+cos理论"); 183 seriesTextList.Add("sin-cos理论"); 184 185 186 187 //系列名称 188 List<Series> seriesNameList = new List<Series>(); 189 for (int i = 0; i < 4; i++) 190 { 191 //完全建立一个系列,以后直接用就行了 192 seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 193 } 194 195 196 197 //产生数据2 198 List<double> xaxesList2 = new List<double>();//x轴数据 199 List<double> ySinList2 = new List<double>();//系列1-y轴数据 200 List<double> yCosList2 = new List<double>();//系列2-y轴数据 201 List<double> ySinAddCosList2 = new List<double>();//系列3-y轴数据 202 List<double> ySinMinCosList2 = new List<double>(); 203 for (int i = 0; i < 20; i++) 204 { 205 xaxesList2.Add(i); 206 ySinList2.Add(0.8*Math.Sin(i)); 207 yCosList2.Add(0.8 * Math.Cos(i)); 208 ySinAddCosList2.Add(0.8 * Math.Sin(i) + 0.8 * Math.Cos(i)); 209 ySinMinCosList2.Add(0.8 * Math.Sin(i) - 0.8 * Math.Cos(i)); 210 211 } 212 //将所有系列的y值放入一个列表,这个列表是列表的列表 213 List<List<double>> YList2 = new List<List<double>>(); 214 YList2.Add(ySinList2); 215 YList2.Add(yCosList2); 216 YList2.Add(ySinAddCosList2); 217 YList2.Add(ySinMinCosList2); 218 219 //系列内容名称 220 List<string> seriesTextList2 = new List<string>();//系列内容名称 221 seriesTextList2.Add("sin实验"); 222 seriesTextList2.Add("cos实验"); 223 seriesTextList2.Add("sin+cos实验"); 224 seriesTextList2.Add("sin-cos实验"); 225 226 //系列名称 227 List<Series> seriesNameList2 = new List<Series>(); 228 for (int i = 0; i < 4; i++) 229 { 230 //完全建立一个系列,以后直接用就行了 231 seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 232 } 233 234 235 236 237 238 //将系列加入chartControl 239 for (int seriesIndex = 0; seriesIndex <4; seriesIndex++) 240 { 241 242 ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex],seriesIndex); 243 244 ShowSeries(lineChartControl, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 245 246 } 247 //显示 248 int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 249 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中 250 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 251 252 253 254 255 256 ////尝试第二个图 257 //this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 258 //ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl 259 //lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 260 261 262 ////将系列加入chartControl 263 //for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 264 //{ 265 // if(seriesIndex%2==0) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce 266 // ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); 267 268 // else 269 // ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 270 //} 271 ////显示 272 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 273 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中 274 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 275 276 277 // //图3 278 // this.xtraTabPage1.PageVisible = false; 279 // this.xtraTabPage2.PageVisible = false; 280 // this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 281 // ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl 282 // lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 283 284 285 // //将系列假如chartControl 286 // for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 287 // { 288 // if (seriesIndex % 2 == 0) 289 // ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); 290 // else 291 // ShowSeries(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 292 293 294 // } 295 // //显示 296 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 297 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中 298 // this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 299 300 301 302 303 304 } 305 /// <summary> 306 /// 实验值画图 307 /// </summary> 308 /// <param name="lineChartControl">图</param> 309 /// <param name="seriesName">系列名,可以理解为id号</param> 310 /// <param name="seriesText">系列内容名,显示在图中</param> 311 /// <param name="xAxes"></param> 312 /// <param name="yAxes"></param> 313 /// <param name="iMarkerKind">根据传入的int值来赋标记种类</param> 314 public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 315 List<double> yAxes, int iMarkerKind) 316 { 317 318 seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 319 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 320 ((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle 321 ((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; 322 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash; 323 seriesName.View.Color = Color.FromKnownColor((KnownColor)((iMarkerKind+1)*35%174)); 324 325 //((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 326 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 327 { 328 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 329 } 330 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 331 lineChartControl.Legend.Visible = true;//图例可见 332 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 333 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 334 } 335 336 public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 337 List<double> yAxes, int iMarkerKind) 338 { 339 340 seriesName = new Series(seriesText, ViewType.Spline);//新建立一个系列 341 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 342 seriesName.View.Color = Color.FromKnownColor((KnownColor)((iMarkerKind + 1) * 35 % 174)); 343 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Solid;//线型 344 345 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 346 { 347 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 348 } 349 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 350 lineChartControl.Legend.Visible = true;//图例可见 351 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 352 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 353 } 354 355 private void Form1_Load(object sender, EventArgs e) 356 { 357 358 } 359 360 361 362 363 364 365 } 366 }
1 ((XYDiagram)lineChartControl.Diagram).AxisX.Logarithmic = true;//打开对数坐标 2 ((XYDiagram)lineChartControl.Diagram).AxisX.LogarithmicBase = Math.E;//若为对数坐标系,则底为自然对数e 3 ((XYDiagram)lineChartControl.Diagram).AxisX.Title.Text = "lnp";//x轴标题 4 ((XYDiagram)lineChartControl.Diagram).AxisY.Title.Text = "e";//y轴标题 5 ((XYDiagram)lineChartControl.Diagram).AxisX.Title.Visible = true;//将x轴标题显示出来 6 ((XYDiagram)lineChartControl.Diagram).AxisY.Title.Visible = true;//将y轴标题显示出来
1 using DevExpress.XtraCharts; 2 using System; 3 using System.Collections.Generic; 4 using System.ComponentModel; 5 using System.Data; 6 using System.Drawing; 7 using System.Linq; 8 using System.Text; 9 using System.Windows.Forms; 10 11 12 namespace WindowsFormsApplication1张奎 13 { 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 24 25 #region 26 //int tabPagesCount = 0; 27 //ChartControl chartControl1 = new ChartControl(); 28 29 //// Create two series. 30 //Series series1 = new Series("Series 1", ViewType.Bar); 31 //Series series2 = new Series("Series 2", ViewType.Line); 32 33 //// Add points to them, with their arguments different. 34 //series1.Points.Add(new SeriesPoint("A", 10)); 35 //series1.Points.Add(new SeriesPoint("B", 12)); 36 //series1.Points.Add(new SeriesPoint("C", 17)); 37 //series1.Points.Add(new SeriesPoint("D", 14)); 38 //series2.Points.Add(new SeriesPoint("I", 2500)); 39 //series2.Points.Add(new SeriesPoint("II", 3800)); 40 //series2.Points.Add(new SeriesPoint("III", 1500)); 41 //series2.Points.Add(new SeriesPoint("IV", 1300)); 42 43 //// Add both series to the chart. 44 //chartControl1.Series.AddRange(new Series[] { series1, series2 }); 45 46 //// Hide the legend (optional). 47 //chartControl1.Legend.Visible = false; 48 49 //// Cast the chart's diagram to the XYDiagram type, 50 //// to access its axes and panes. 51 //XYDiagram diagram = (XYDiagram)chartControl1.Diagram; 52 53 //// Add secondary axes to the diagram, and adjust their options. 54 //diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 55 //diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 56 //diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 57 //diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 58 59 //// Add a new additional pane to the diagram. 60 //diagram.Panes.Add(new XYDiagramPane("My Pane")); 61 62 //// Assign both the additional pane and, if required, 63 //// the secondary axes to the second series. 64 //LineSeriesView myView = (LineSeriesView)series2.View; 65 //myView.AxisX = diagram.SecondaryAxesX[0]; 66 //myView.AxisY = diagram.SecondaryAxesY[0]; 67 //// Note that the created pane has the zero index in the collection, 68 //// because the existing Default pane is a separate entity. 69 //myView.Pane = diagram.Panes[0]; 70 71 //// Customize the layout of the diagram's panes. 72 //diagram.PaneDistance = 10; 73 //diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 74 //diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 75 //diagram.DefaultPane.Weight = 1.2; 76 77 //// Add the chart to the form. 78 //chartControl1.Dock = DockStyle.Fill; 79 ////this.Controls.Add(chartControl1); 80 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 81 //tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 82 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1); 83 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 84 85 86 //// 87 //ChartControl chartControl2 = new ChartControl(); 88 89 //// Create two series. 90 //Series series3 = new Series("Series 3", ViewType.Bar); 91 //Series series4= new Series("Series 4", ViewType.Line); 92 93 //// Add points to them, with their arguments different. 94 //series3.Points.Add(new SeriesPoint("A", 10)); 95 //series3.Points.Add(new SeriesPoint("B", 12)); 96 //series3.Points.Add(new SeriesPoint("C", 17)); 97 //series3.Points.Add(new SeriesPoint("D", 14)); 98 //series4.Points.Add(new SeriesPoint("I", 2500)); 99 //series4.Points.Add(new SeriesPoint("II", 3800)); 100 //series4.Points.Add(new SeriesPoint("III", 1500)); 101 //series4.Points.Add(new SeriesPoint("IV", 1300)); 102 103 //// Add both series to the chart. 104 //chartControl2.Series.AddRange(new Series[] { series3, series4 }); 105 106 //// Hide the legend (optional). 107 //chartControl2.Legend.Visible = false; 108 109 //// Cast the chart's diagram to the XYDiagram type, 110 //// to access its axes and panes. 111 //XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; 112 113 //// Add secondary axes to the diagram, and adjust their options. 114 //diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X")); 115 //diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y")); 116 //diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near; 117 //diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; 118 119 //// Add a new additional pane to the diagram. 120 //diagram2.Panes.Add(new XYDiagramPane("My Pane")); 121 122 //// Assign both the additional pane and, if required, 123 //// the secondary axes to the second series. 124 //LineSeriesView myView2 = (LineSeriesView)series2.View; 125 //myView2.AxisX = diagram2.SecondaryAxesX[0]; 126 //myView2.AxisY = diagram2.SecondaryAxesY[0]; 127 //// Note that the created pane has the zero index in the collection, 128 //// because the existing Default pane is a separate entity. 129 //myView2.Pane = diagram2.Panes[0]; 130 131 //// Customize the layout of the diagram's panes. 132 //diagram2.PaneDistance = 10; 133 //diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal; 134 //diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight; 135 //diagram2.DefaultPane.Weight = 1.2; 136 137 //// Add the chart to the form. 138 //chartControl2.Dock = DockStyle.Fill; 139 ////this.Controls.Add(chartControl1); 140 //this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page 141 //tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 142 //this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2); 143 //this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; 144 145 #endregion 146 147 148 this.xtraTabPage1.PageVisible = false; 149 this.xtraTabPage2.PageVisible = false; 150 this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 151 ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl 152 lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 153 154 //产生数据 155 List<double> xaxesList = new List<double>();//x轴数据 156 List<double> ySinList = new List<double>();//系列1-y轴数据 157 List<double> yCosList = new List<double>();//系列2-y轴数据 158 List<double> yTanList = new List<double>();//系列3-y轴数据 159 List<double> y08TanList = new List<double>();//系列3-y轴数据 160 List<double> ySinCosList = new List<double>();//系列3-y轴数据 161 List<double> ySinDICosList = new List<double>();//系列3-y轴数据 162 for (int i = 0; i < 20; i++) 163 { 164 xaxesList.Add(i); 165 ySinList.Add(Math.Sin(i)); 166 yCosList.Add(0.8*Math.Sin(i)); 167 yTanList.Add(Math.Sin(i) + Math.Cos(i)); 168 y08TanList.Add(0.8*Math.Sin(i) + Math.Cos(i)); 169 ySinCosList.Add(Math.Sin(i) * Math.Cos(i)); 170 ySinDICosList.Add( Math.Sin(i)*(i%2+0.5)); 171 } 172 //将所有系列的y值放入一个列表,这个列表是列表的列表 173 List<List<double>> YList = new List<List<double>>(); 174 YList.Add(ySinList); 175 YList.Add(yCosList); 176 YList.Add(yTanList); 177 YList.Add(y08TanList); 178 YList.Add(ySinCosList); 179 YList.Add(ySinDICosList); 180 //系列内容名称 181 List<string> seriesTextList = new List<string>();//系列内容名称 182 seriesTextList.Add("预测曲线"); 183 seriesTextList.Add("实验值"); 184 seriesTextList.Add("cos+sin"); 185 seriesTextList.Add("cos+0.8*sin"); 186 seriesTextList.Add("cos*sin"); 187 seriesTextList.Add("sin/cos"); 188 189 //系列名称 190 List<Series> seriesNameList = new List<Series>(); 191 for (int i = 0; i < 6; i++) 192 { 193 //完全建立一个系列,以后直接用就行了 194 seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 195 } 196 //将系列假如chartControl 197 for (int seriesIndex = 0; seriesIndex <6; seriesIndex++) 198 { 199 if(seriesIndex%2==0) 200 ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); 201 else 202 ShowSeries(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 203 204 205 } 206 //显示 207 int tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 208 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中 209 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 210 211 212 213 214 215 //尝试第二个图 216 this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 217 ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl 218 lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 219 220 //产生数据 221 List<double> xaxesList2 = new List<double>();//x轴数据 222 List<double> ySinList2 = new List<double>();//系列1-y轴数据 223 List<double> yCosList2 = new List<double>();//系列2-y轴数据 224 List<double> y08sinList2 = new List<double>();//系列3-y轴数据 225 List<double> y05sinList2 = new List<double>(); 226 List<double> ySinCosList2 = new List<double>(); 227 List<double> ySinDICosList2 = new List<double>(); 228 for (int i = 0; i < 20; i++) 229 { 230 xaxesList2.Add(i); 231 ySinList2.Add(Math.Cos(i)); 232 yCosList2.Add(0.8*Math.Cos(i)); 233 y08sinList2.Add(0.6 * Math.Sin(i)); 234 y05sinList2.Add(0.5*Math.Sin(i)); 235 ySinCosList2.Add(0.8*Math.Sin(i) * Math.Cos(i)); 236 ySinDICosList2.Add(0.8*Math.Sin(i)*(i%2+0.5)); 237 238 } 239 //将所有系列的y值放入一个列表,这个列表是列表的列表 240 List<List<double>> YList2 = new List<List<double>>(); 241 YList2.Add(ySinList2); 242 YList2.Add(yCosList2); 243 YList2.Add(y08sinList2); 244 YList2.Add(y05sinList2); 245 YList2.Add(ySinCosList2); 246 YList2.Add(ySinDICosList2); 247 248 //系列内容名称 249 List<string> seriesTextList2 = new List<string>();//系列内容名称 250 seriesTextList2.Add("预测曲线"); 251 seriesTextList2.Add("实验值"); 252 seriesTextList2.Add("预测曲线2"); 253 seriesTextList2.Add("实验值2"); 254 seriesTextList2.Add("ySinCosList22"); 255 seriesTextList2.Add("ySinDICosList22"); 256 257 258 //系列名称 259 List<Series> seriesNameList2 = new List<Series>(); 260 for (int i = 0; i < 6; i++) 261 { 262 //完全建立一个系列,以后直接用就行了 263 seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line 264 } 265 //将系列加入chartControl 266 for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 267 { 268 if(seriesIndex%2==0) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce 269 ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); 270 271 else 272 ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); 273 } 274 //显示 275 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 276 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中 277 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 278 279 280 //图3 281 this.xtraTabPage1.PageVisible = false; 282 this.xtraTabPage2.PageVisible = false; 283 this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page 284 ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl 285 lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 286 287 288 //将系列假如chartControl 289 for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++) 290 { 291 if (seriesIndex % 2 == 0) 292 ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); 293 else 294 ShowSeries(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); 295 296 297 } 298 //显示 299 tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove 300 this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中 301 this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page 302 303 304 305 306 307 } 308 public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 309 List<double> yAxes, int iMarkerKind) 310 { 311 312 //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 313 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 314 //((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle 315 //((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; 316 317 //((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 318 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 319 { 320 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 321 } 322 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 323 lineChartControl.Legend.Visible = true;//图例可见 324 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 325 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 326 } 327 328 public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes, 329 List<double> yAxes) 330 { 331 332 //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列 333 seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 334 335 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型 336 for (int pointIndex = 0; pointIndex < xAxes.Count; pointIndex++) 337 { 338 seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex])); 339 } 340 lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列 341 lineChartControl.Legend.Visible = true;//图例可见 342 ((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转 343 lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺 344 } 345 346 private void Form1_Load(object sender, EventArgs e) 347 { 348 349 } 350 351 352 } 353 }
1 using System; 2 using DevExpress.Utils.Menu; 3 4 namespace DevExpress.XtraCharts.Demos { 5 public partial class ChartDemoSecondaryAxes : ChartDemoBase2D { 6 struct AxisItem { 7 readonly Axis axis; 8 9 public Axis Axis { get { return axis; } } 10 11 public AxisItem(Axis axis) { 12 this.axis = axis; 13 } 14 public override string ToString() { 15 return axis.Name; 16 } 17 public override bool Equals(object obj) { 18 if (!(obj is AxisItem)) 19 return false; 20 AxisItem item = (AxisItem)obj; 21 return axis.Equals(item.axis); 22 } 23 public override int GetHashCode() { 24 return axis.GetHashCode(); 25 } 26 } 27 28 const string SecondaryPostfixX = " (Secondary Axis X)"; 29 const string SecondaryPostfixY = " (Secondary Axis Y)"; 30 const string PrimaryPostfixX = " (Primary Axis X)"; 31 const string PrimaryPostfixY = " (Primary Axis Y)"; 32 const int LineChart = 0; 33 const int BarChart = 1; 34 35 bool loading; 36 ChartControl chart; 37 XYDiagram Diagram { get { return ChartControl.Diagram as XYDiagram; } } 38 SecondaryAxisX SecondaryAxisX { get { return (Diagram != null && Diagram.SecondaryAxesX.Count > 0) ? Diagram.SecondaryAxesX[0] : null; } } 39 SecondaryAxisY SecondaryAxisY { get { return (Diagram != null && Diagram.SecondaryAxesY.Count > 0) ? Diagram.SecondaryAxesY[0] : null; } } 40 Series FirstSeries { get { return ChartControl.Series.Count > 0 ? ChartControl.Series[0] : null; } } 41 Series SecondSeries { get { return ChartControl.Series.Count > 1 ? ChartControl.Series[1] : null; } } 42 XYDiagramSeriesViewBase SecondSeriesView { get { return SecondSeries != null ? SecondSeries.View as XYDiagramSeriesViewBase : null; } } 43 public override ChartControl ChartControl { get { return chart; } } 44 45 public ChartDemoSecondaryAxes() { 46 InitializeComponent(); 47 if (Diagram == null) 48 return; 49 ((Axis)Diagram.AxisX).Name = "Primary Axis X"; 50 ((Axis)Diagram.AxisY).Name = "Primary Axis Y"; 51 Diagram.SecondaryAxesX.Add(new SecondaryAxisX("Secondary Axis X")); 52 Diagram.SecondaryAxesY.Add(new SecondaryAxisY("Secondary Axis Y")); 53 this.cbChartType.Properties.Items.AddRange(new string[] { "Line", "Bar" }); 54 loading = true; 55 try { 56 UpdateChartType(); 57 if (SecondSeries != null) { 58 UpdateCBSeriesAxisX(Diagram.AxisX); 59 UpdateCBSeriesAxisY(SecondaryAxisY); 60 } 61 } 62 finally { 63 loading = false; 64 } 65 } 66 void AttachSecondaryAxisX(SecondaryAxisX axisX) { 67 if(axisX == null || Diagram == null) 68 return; 69 if(SecondSeriesView != null) { 70 SecondSeriesView.AxisX = axisX; 71 axisX.Visible = true; 72 if(FirstSeries != null) 73 Diagram.AxisX.Title.Text = FirstSeries.Name + PrimaryPostfixX; 74 if(SecondaryAxisX != null) { 75 SecondaryAxisX.Title.Visible = true; 76 SecondaryAxisX.Title.Text = SecondSeries.Name + SecondaryPostfixX; 77 } 78 } 79 } 80 void AttachSecondaryAxisY(SecondaryAxisY axisY) { 81 if(axisY == null || Diagram == null) 82 return; 83 if(SecondSeriesView != null) { 84 SecondSeriesView.AxisY = axisY; 85 axisY.Visible = true; 86 if(FirstSeries != null) 87 Diagram.AxisY.Title.Text = FirstSeries.Name + PrimaryPostfixY; 88 if(SecondaryAxisY != null) { 89 SecondaryAxisY.Title.Visible = true; 90 SecondaryAxisY.Title.Text = SecondSeries.Name + SecondaryPostfixY; 91 } 92 } 93 } 94 void DetachSecondaryAxisX() { 95 if(Diagram == null) 96 return; 97 if(SecondSeriesView != null) { 98 if(SecondaryAxisX != null) 99 SecondaryAxisX.Visible = false; 100 SecondSeriesView.AxisX = Diagram.AxisX; 101 if(FirstSeries != null) 102 Diagram.AxisX.Title.Text = FirstSeries.Name + ", " + SecondSeries.Name + PrimaryPostfixX; 103 } 104 } 105 void DetachSecondaryAxisY() { 106 if(Diagram == null) 107 return; 108 if(SecondSeriesView != null) { 109 if(SecondaryAxisY != null) 110 SecondaryAxisY.Visible = false; 111 SecondSeriesView.AxisY = Diagram.AxisY; 112 if(FirstSeries != null) 113 Diagram.AxisY.Title.Text = FirstSeries.Name + ", " + SecondSeries.Name + PrimaryPostfixX; 114 } 115 } 116 void ChangeSeriesViewType(ViewType viewType) { 117 foreach (Series series in ChartControl.Series) 118 series.ChangeView(viewType); 119 } 120 void UpdateChartType() { 121 int selectedIndex = -1; 122 foreach(Series series in chart.Series) { 123 if(series.View is LineSeriesView) { 124 selectedIndex = LineChart; 125 break; 126 } 127 else if(series.View is SideBySideBarSeriesView) 128 selectedIndex = BarChart; 129 } 130 cbChartType.SelectedIndex = selectedIndex; 131 } 132 void UpdateCBSeriesAxisX(Axis selectedAxisX) { 133 cbSeriesAxisX.Properties.Items.Clear(); 134 if(Diagram == null) 135 return; 136 cbSeriesAxisX.Properties.Items.Add(new AxisItem(Diagram.AxisX)); 137 foreach(SecondaryAxisX axisX in Diagram.SecondaryAxesX) 138 cbSeriesAxisX.Properties.Items.Add(new AxisItem(axisX)); 139 cbSeriesAxisX.SelectedItem = new AxisItem(selectedAxisX); 140 } 141 void UpdateCBSeriesAxisY(Axis selectedAxisY) { 142 cbSeriesAxisY.Properties.Items.Clear(); 143 if(Diagram == null) 144 return; 145 cbSeriesAxisY.Properties.Items.Add(new AxisItem(Diagram.AxisY)); 146 foreach(SecondaryAxisY axisY in Diagram.SecondaryAxesY) 147 cbSeriesAxisY.Properties.Items.Add(new AxisItem(axisY)); 148 cbSeriesAxisY.SelectedItem = new AxisItem(selectedAxisY); 149 } 150 void cbChartType_SelectedIndexChanged(object sender, EventArgs e) { 151 if (loading) 152 return; 153 if (cbChartType.SelectedIndex == LineChart) 154 ChangeSeriesViewType(ViewType.Line); 155 else if (cbChartType.SelectedIndex == BarChart) 156 ChangeSeriesViewType(ViewType.Bar); 157 } 158 void cbSeriesAxisX_SelectedIndexChanged(object sender, EventArgs e) { 159 SecondaryAxisX axisX = ((AxisItem)cbSeriesAxisX.SelectedItem).Axis as SecondaryAxisX; 160 if(axisX != null) 161 AttachSecondaryAxisX(axisX); 162 else 163 DetachSecondaryAxisX(); 164 } 165 void cbSeriesAxisY_SelectedIndexChanged(object sender, EventArgs e) { 166 SecondaryAxisY axisY = ((AxisItem)cbSeriesAxisY.SelectedItem).Axis as SecondaryAxisY; 167 if(axisY != null) 168 AttachSecondaryAxisY(axisY); 169 else 170 DetachSecondaryAxisY(); 171 } 172 protected override DXPopupMenu ConstructPopupMenu(object obj, ChartControl chartControl) { 173 return DXMenuHelper.ConstructSecondaryAxesMenu(obj, chartControl); 174 } 175 public override void UpdateControls() { 176 base.UpdateControls(); 177 loading = true; 178 try { 179 UpdateChartType(); 180 if (SecondSeriesView != null) { 181 UpdateCBSeriesAxisX(SecondSeriesView.AxisX); 182 UpdateCBSeriesAxisY(SecondSeriesView.AxisY); 183 } 184 } 185 finally { 186 loading = false; 187 } 188 } 189 } 190 }
1 using System; 2 using DevExpress.Utils; 3 4 namespace DevExpress.XtraCharts.Demos { 5 public partial class ChartDemoScatterLine : ChartDemoLineBase { 6 const int a = 10; 7 const int archimedianSpiralIndex = 0; 8 const int cardioidIndex = 1; 9 const int cartesianFoliumIndex = 2; 10 11 SeriesCollection Series { get { return chart.Series; } } 12 Series ArchimedianSpiralSeries { get { return Series[archimedianSpiralIndex]; } } 13 Series CardioidSeries { get { return Series[cardioidIndex]; } } 14 Series CartesianFoliumSeries { get { return Series[cartesianFoliumIndex]; } } 15 protected override Series[] ProcessedSeries { get { return new Series[] { ArchimedianSpiralSeries, CardioidSeries, CartesianFoliumSeries }; } } 16 protected override DefaultBoolean CrosshairEnabled { get { return DefaultBoolean.False; } } 17 protected override DefaultBoolean ToolTipEnabled { get { return DefaultBoolean.True; } } 18 public override ChartControl ChartControl { get { return chart; } } 19 20 public ChartDemoScatterLine() { 21 InitializeComponent(); 22 23 } 24 void CreateArchimedianSpiralPoints() { 25 for (int i = 0; i < 720; i += 10) { 26 double t = (double)i / 180 * Math.PI; 27 double x = t * Math.Cos(t); 28 double y = t * Math.Sin(t); 29 ArchimedianSpiralSeries.Points.Add(new SeriesPoint(x, y)); 30 } 31 } 32 void CreateCardioidPoints() { 33 for (int i = 0; i < 360; i += 10) { 34 double t = (double)i / 180 * Math.PI; 35 double x = a * (2 * Math.Cos(t) - Math.Cos(2 * t)); 36 double y = a * (2 * Math.Sin(t) - Math.Sin(2 * t)); 37 CardioidSeries.Points.Add(new SeriesPoint(x, y)); 38 } 39 } 40 void CreateCartesianFoliumPoints() { 41 for (int i = -30; i < 125; i += 5) { 42 double t = Math.Tan((double)i / 180 * Math.PI); 43 double x = 3 * (double)a * t / (t * t * t + 1); 44 double y = x * t; 45 CartesianFoliumSeries.Points.Add(new SeriesPoint(x, y)); 46 } 47 } 48 void ShowSeries(Series visibleSeries) { 49 foreach (Series series in Series) { 50 if (series == visibleSeries) { 51 visibleSeries.Visible = true; 52 seriesSelected = series; 53 } 54 else 55 series.Visible = false; 56 } 57 } 58 void comboBoxEditFunctionType_SelectedIndexChanged(object sender, EventArgs e) { 59 if(comboBoxEditFunctionType.SelectedIndex == archimedianSpiralIndex) { 60 if (ArchimedianSpiralSeries.Points.Count == 0) 61 CreateArchimedianSpiralPoints(); 62 ShowSeries(ArchimedianSpiralSeries); 63 } 64 else if(comboBoxEditFunctionType.SelectedIndex == cardioidIndex) { 65 if (CardioidSeries.Points.Count == 0) 66 CreateCardioidPoints(); 67 ShowSeries(CardioidSeries); 68 } 69 else if(comboBoxEditFunctionType.SelectedIndex == cartesianFoliumIndex) { 70 if (CartesianFoliumSeries.Points.Count == 0) 71 CreateCartesianFoliumPoints(); 72 ShowSeries(CartesianFoliumSeries); 73 } 74 } 75 protected override void InitControls() { 76 base.InitControls(); 77 ShowLabels = false; 78 comboBoxEditFunctionType.SelectedIndex = archimedianSpiralIndex; 79 foreach (Series series in chart.Series) 80 series.ToolTipPointPattern = "{A:F2} : {V:F2}"; 81 } 82 } 83 }
1 using System; 2 3 namespace DevExpress.XtraCharts.Demos { 4 public partial class ChartDemoRealtimeChart : ChartDemoBase { 5 const int interval = 20; 6 7 static RegressionLine GetRegressionLine(Series series) { 8 if (series != null) { 9 SwiftPlotSeriesView swiftPlotView = series.View as SwiftPlotSeriesView; 10 if (swiftPlotView != null) 11 foreach (Indicator indicator in swiftPlotView.Indicators) { 12 RegressionLine regressionLine = indicator as RegressionLine; 13 if (regressionLine != null) 14 return regressionLine; 15 } 16 } 17 return null; 18 } 19 20 Random random = new Random(); 21 double value1 = 10.0; 22 double value2 = -10.0; 23 bool? inProcess = null; 24 25 int TimeInterval { get { return Convert.ToInt32(spnTimeInterval.EditValue); } } 26 Series Series1 { get { return chart.Series.Count > 0 ? chart.Series[0] : null; } } 27 Series Series2 { get { return chart.Series.Count > 1 ? chart.Series[1] : null; } } 28 RegressionLine Regression1 { get { return GetRegressionLine(Series1); } } 29 RegressionLine Regression2 { get { return GetRegressionLine(Series2); } } 30 public override ChartControl ChartControl { get { return chart; } } 31 32 public ChartDemoRealtimeChart() { 33 InitializeComponent(); 34 } 35 void SetPauseResumeButtonText() { 36 btnPauseResume.Text = timer.Enabled ? "Pause" : "Resume"; 37 } 38 double CalculateNextValue(double value) { 39 return value + (random.NextDouble() * 10.0 - 5.0); 40 } 41 void UpdateValues() { 42 value1 = CalculateNextValue(value1); 43 value2 = CalculateNextValue(value2); 44 } 45 void DisableProcess() { 46 inProcess = timer.Enabled; 47 timer.Enabled = false; 48 } 49 void RestoreProcess() { 50 if(inProcess != null) { 51 timer.Enabled = (bool)inProcess; 52 inProcess = null; 53 } 54 } 55 protected override void InitControls() { 56 base.InitControls(); 57 timer.Interval = interval; 58 SetPauseResumeButtonText(); 59 } 60 protected override void DoShow() { 61 base.DoShow(); 62 RestoreProcess(); 63 } 64 protected override void DoHide() { 65 base.DoHide(); 66 DisableProcess(); 67 } 68 void timer_Tick(object sender, EventArgs e) { 69 if (Series1 == null || Series2 == null) 70 return; 71 DateTime argument = DateTime.Now; 72 SeriesPoint[] pointsToUpdate1 = new SeriesPoint[interval]; 73 SeriesPoint[] pointsToUpdate2 = new SeriesPoint[interval]; 74 for (int i = 0; i < interval; i++) { 75 pointsToUpdate1[i] = new SeriesPoint(argument, value1); 76 pointsToUpdate2[i] = new SeriesPoint(argument, value2); 77 argument = argument.AddMilliseconds(1); 78 UpdateValues(); 79 } 80 DateTime minDate = argument.AddSeconds(-TimeInterval); 81 int pointsToRemoveCount = 0; 82 foreach (SeriesPoint point in Series1.Points) 83 if (point.DateTimeArgument < minDate) 84 pointsToRemoveCount++; 85 if (pointsToRemoveCount < Series1.Points.Count) 86 pointsToRemoveCount--; 87 AddPoints(Series1, pointsToUpdate1); 88 AddPoints(Series2, pointsToUpdate2); 89 if (pointsToRemoveCount > 0) { 90 Series1.Points.RemoveRange(0, pointsToRemoveCount); 91 Series2.Points.RemoveRange(0, pointsToRemoveCount); 92 } 93 SwiftPlotDiagram diagram = chart.Diagram as SwiftPlotDiagram; 94 if (diagram != null && (diagram.AxisX.DateTimeScaleOptions.MeasureUnit == DateTimeMeasureUnit.Millisecond || diagram.AxisX.DateTimeScaleOptions.ScaleMode == ScaleMode.Continuous)) 95 diagram.AxisX.WholeRange.SetMinMaxValues(minDate, argument); 96 } 97 void AddPoints(Series series, SeriesPoint[] pointsToUpdate) { 98 if(series.View is SwiftPlotSeriesViewBase) 99 series.Points.AddRange(pointsToUpdate); 100 } 101 void btnPauseResume_Click(object sender, EventArgs e) { 102 timer.Enabled = !timer.Enabled; 103 SetPauseResumeButtonText(); 104 } 105 void chRegression_CheckedChanged(object sender, EventArgs e) { 106 if(Regression1 != null) 107 Regression1.Visible = chRegression.Checked; 108 if(Regression2 != null) 109 Regression2.Visible = chRegression.Checked; 110 } 111 } 112 }