using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication1张奎
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{ #region
//int tabPagesCount = 0;
//ChartControl chartControl1 = new ChartControl(); //// Create two series.
//Series series1 = new Series("Series 1", ViewType.Bar);
//Series series2 = new Series("Series 2", ViewType.Line); //// Add points to them, with their arguments different.
//series1.Points.Add(new SeriesPoint("A", 10));
//series1.Points.Add(new SeriesPoint("B", 12));
//series1.Points.Add(new SeriesPoint("C", 17));
//series1.Points.Add(new SeriesPoint("D", 14));
//series2.Points.Add(new SeriesPoint("I", 2500));
//series2.Points.Add(new SeriesPoint("II", 3800));
//series2.Points.Add(new SeriesPoint("III", 1500));
//series2.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl1.Series.AddRange(new Series[] { series1, series2 }); //// Hide the legend (optional).
//chartControl1.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram = (XYDiagram)chartControl1.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView = (LineSeriesView)series2.View;
//myView.AxisX = diagram.SecondaryAxesX[0];
//myView.AxisY = diagram.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView.Pane = diagram.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram.PaneDistance = 10;
//diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl1.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; ////
//ChartControl chartControl2 = new ChartControl(); //// Create two series.
//Series series3 = new Series("Series 3", ViewType.Bar);
//Series series4= new Series("Series 4", ViewType.Line); //// Add points to them, with their arguments different.
//series3.Points.Add(new SeriesPoint("A", 10));
//series3.Points.Add(new SeriesPoint("B", 12));
//series3.Points.Add(new SeriesPoint("C", 17));
//series3.Points.Add(new SeriesPoint("D", 14));
//series4.Points.Add(new SeriesPoint("I", 2500));
//series4.Points.Add(new SeriesPoint("II", 3800));
//series4.Points.Add(new SeriesPoint("III", 1500));
//series4.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl2.Series.AddRange(new Series[] { series3, series4 }); //// Hide the legend (optional).
//chartControl2.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram2.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView2 = (LineSeriesView)series2.View;
//myView2.AxisX = diagram2.SecondaryAxesX[0];
//myView2.AxisY = diagram2.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView2.Pane = diagram2.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram2.PaneDistance = 10;
//diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram2.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl2.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; #endregion this.xtraTabPage1.PageVisible = false;
this.xtraTabPage2.PageVisible = false;
this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl
lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList = new List<double>();//x轴数据
List<double> ySinList = new List<double>();//系列1-y轴数据
List<double> yCosList = new List<double>();//系列2-y轴数据
List<double> yTanList = new List<double>();//系列3-y轴数据
for (int i = ; i < ; i++)
{
xaxesList.Add(i);
ySinList.Add(Math.Sin(i));
yCosList.Add(0.8*Math.Sin(i));
yTanList.Add(Math.Sin(i) + Math.Cos(i));
}
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList = new List<List<double>>();
YList.Add(ySinList);
YList.Add(yCosList);
YList.Add(yTanList);
//系列内容名称
List<string> seriesTextList = new List<string>();//系列内容名称
seriesTextList.Add("预测曲线");
seriesTextList.Add("实验值");
seriesTextList.Add("cos+sin");
//系列名称
List<Series> seriesNameList = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
}
//将系列假如chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if(seriesIndex==)
ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); else if (seriesIndex==)
ShowSeries(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); }
//显示
int tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //尝试第二个图
this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl
lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList2 = new List<double>();//x轴数据
List<double> ySinList2 = new List<double>();//系列1-y轴数据
List<double> yCosList2 = new List<double>();//系列2-y轴数据
List<double> y08sinList2 = new List<double>();//系列3-y轴数据
List<double> y05sinList2 = new List<double>();
for (int i = ; i < ; i++)
{
xaxesList2.Add(i);
ySinList2.Add(Math.Cos(i));
yCosList2.Add(0.8*Math.Cos(i));
y08sinList2.Add(0.6 * Math.Sin(i));
y05sinList2.Add(0.5*Math.Sin(i)); }
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList2 = new List<List<double>>();
YList2.Add(ySinList2);
YList2.Add(yCosList2);
YList2.Add(y08sinList2);
YList2.Add(y05sinList2); //系列内容名称
List<string> seriesTextList2 = new List<string>();//系列内容名称
seriesTextList2.Add("预测曲线");
seriesTextList2.Add("实验值");
seriesTextList2.Add("预测曲线2");
seriesTextList2.Add("实验值2"); //系列名称
List<Series> seriesNameList2 = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
}
//将系列加入chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if(seriesIndex== || seriesIndex==) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce
ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); else
ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex);
}
//显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page }
public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{ //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % ));//mark类型 MarkerKind.Triangle
((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes)
{ //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} private void Form1_Load(object sender, EventArgs e)
{ } }
}
Form1.cs-运行正确
using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication1张奎
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{ #region
//int tabPagesCount = 0;
//ChartControl chartControl1 = new ChartControl(); //// Create two series.
//Series series1 = new Series("Series 1", ViewType.Bar);
//Series series2 = new Series("Series 2", ViewType.Line); //// Add points to them, with their arguments different.
//series1.Points.Add(new SeriesPoint("A", 10));
//series1.Points.Add(new SeriesPoint("B", 12));
//series1.Points.Add(new SeriesPoint("C", 17));
//series1.Points.Add(new SeriesPoint("D", 14));
//series2.Points.Add(new SeriesPoint("I", 2500));
//series2.Points.Add(new SeriesPoint("II", 3800));
//series2.Points.Add(new SeriesPoint("III", 1500));
//series2.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl1.Series.AddRange(new Series[] { series1, series2 }); //// Hide the legend (optional).
//chartControl1.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram = (XYDiagram)chartControl1.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView = (LineSeriesView)series2.View;
//myView.AxisX = diagram.SecondaryAxesX[0];
//myView.AxisY = diagram.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView.Pane = diagram.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram.PaneDistance = 10;
//diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl1.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; ////
//ChartControl chartControl2 = new ChartControl(); //// Create two series.
//Series series3 = new Series("Series 3", ViewType.Bar);
//Series series4= new Series("Series 4", ViewType.Line); //// Add points to them, with their arguments different.
//series3.Points.Add(new SeriesPoint("A", 10));
//series3.Points.Add(new SeriesPoint("B", 12));
//series3.Points.Add(new SeriesPoint("C", 17));
//series3.Points.Add(new SeriesPoint("D", 14));
//series4.Points.Add(new SeriesPoint("I", 2500));
//series4.Points.Add(new SeriesPoint("II", 3800));
//series4.Points.Add(new SeriesPoint("III", 1500));
//series4.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl2.Series.AddRange(new Series[] { series3, series4 }); //// Hide the legend (optional).
//chartControl2.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram2.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView2 = (LineSeriesView)series2.View;
//myView2.AxisX = diagram2.SecondaryAxesX[0];
//myView2.AxisY = diagram2.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView2.Pane = diagram2.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram2.PaneDistance = 10;
//diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram2.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl2.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; #endregion this.xtraTabPage1.PageVisible = false;
this.xtraTabPage2.PageVisible = false;
this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl
lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList = new List<double>();//x轴数据
List<double> ySinList = new List<double>();//系列1-y轴数据
List<double> yCosList = new List<double>();//系列2-y轴数据
List<double> ySinAddCosList = new List<double>();//系列3-y轴数据
List<double> y08SinAddCosList = new List<double>();//系列3-y轴数据
for (int i = ; i < ; i++)
{
xaxesList.Add(i);
ySinList.Add(Math.Sin(i));
yCosList.Add(0.8*Math.Sin(i));
ySinAddCosList.Add(Math.Sin(i) + Math.Cos(i));
y08SinAddCosList.Add(0.8*Math.Sin(i) + Math.Cos(i));
}
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList = new List<List<double>>();
YList.Add(ySinList);
YList.Add(yCosList);
YList.Add(ySinAddCosList);
YList.Add(y08SinAddCosList);
//系列内容名称
List<string> seriesTextList = new List<string>();//系列内容名称
seriesTextList.Add("SINX");
seriesTextList.Add("0.8*SINX");
seriesTextList.Add("cos+sin");
seriesTextList.Add("cos+0.8*sin");
//系列名称
List<Series> seriesNameList = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
} //产生数据
List<double> xaxesList2 = new List<double>();//x轴数据
List<double> ySinList2 = new List<double>();//系列1-y轴数据
List<double> yCosList2 = new List<double>();//系列2-y轴数据
List<double> y08sinList2 = new List<double>();//系列3-y轴数据
List<double> y05sinList2 = new List<double>();
for (int i = ; i < ; i++)
{
xaxesList2.Add(i);
ySinList2.Add(Math.Cos(i));
yCosList2.Add(0.8 * Math.Cos(i));
y08sinList2.Add(0.6 * Math.Sin(i));
y05sinList2.Add(0.5 * Math.Sin(i)); }
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList2 = new List<List<double>>();
YList2.Add(ySinList2);
YList2.Add(yCosList2);
YList2.Add(y08sinList2);
YList2.Add(y05sinList2); //系列内容名称
List<string> seriesTextList2 = new List<string>();//系列内容名称
seriesTextList2.Add("预测曲线");
seriesTextList2.Add("实验值");
seriesTextList2.Add("预测曲线2");
seriesTextList2.Add("实验值2"); //系列名称
List<Series> seriesNameList2 = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
} //将系列假如chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if(seriesIndex%==)
ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); else
ShowSeries(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); }
//显示
int tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //尝试第二个图
this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl
lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 //将系列加入chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if(seriesIndex== || seriesIndex==) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce
ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); else
ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex);
}
//显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //尝试第三个图
this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl
lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 //将系列加入chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if (seriesIndex == || seriesIndex == ) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce
ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); else
ShowSeries(lineChartControl3, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex);
}
//显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //尝试第四个图
this.xtraTabControl1.TabPages.Add("三角函数图4");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl4 = new ChartControl();//实例化一个ChartControl
lineChartControl4.Legend.UseCheckBoxes = true;//图例可以勾选
//将系列假如chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if (seriesIndex % == )
ShowSeries_yuce(lineChartControl4, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); else
ShowSeries(lineChartControl4, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); }
//显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page }
public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{ //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % ));//mark类型 MarkerKind.Triangle
((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{ //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
//((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle
//((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} private void Form1_Load(object sender, EventArgs e)
{ } }
}
我添加图和系列后还是无法运行
using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication1张奎
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{ #region
//int tabPagesCount = 0;
//ChartControl chartControl1 = new ChartControl(); //// Create two series.
//Series series1 = new Series("Series 1", ViewType.Bar);
//Series series2 = new Series("Series 2", ViewType.Line); //// Add points to them, with their arguments different.
//series1.Points.Add(new SeriesPoint("A", 10));
//series1.Points.Add(new SeriesPoint("B", 12));
//series1.Points.Add(new SeriesPoint("C", 17));
//series1.Points.Add(new SeriesPoint("D", 14));
//series2.Points.Add(new SeriesPoint("I", 2500));
//series2.Points.Add(new SeriesPoint("II", 3800));
//series2.Points.Add(new SeriesPoint("III", 1500));
//series2.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl1.Series.AddRange(new Series[] { series1, series2 }); //// Hide the legend (optional).
//chartControl1.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram = (XYDiagram)chartControl1.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView = (LineSeriesView)series2.View;
//myView.AxisX = diagram.SecondaryAxesX[0];
//myView.AxisY = diagram.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView.Pane = diagram.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram.PaneDistance = 10;
//diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl1.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; ////
//ChartControl chartControl2 = new ChartControl(); //// Create two series.
//Series series3 = new Series("Series 3", ViewType.Bar);
//Series series4= new Series("Series 4", ViewType.Line); //// Add points to them, with their arguments different.
//series3.Points.Add(new SeriesPoint("A", 10));
//series3.Points.Add(new SeriesPoint("B", 12));
//series3.Points.Add(new SeriesPoint("C", 17));
//series3.Points.Add(new SeriesPoint("D", 14));
//series4.Points.Add(new SeriesPoint("I", 2500));
//series4.Points.Add(new SeriesPoint("II", 3800));
//series4.Points.Add(new SeriesPoint("III", 1500));
//series4.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl2.Series.AddRange(new Series[] { series3, series4 }); //// Hide the legend (optional).
//chartControl2.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram2.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView2 = (LineSeriesView)series2.View;
//myView2.AxisX = diagram2.SecondaryAxesX[0];
//myView2.AxisY = diagram2.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView2.Pane = diagram2.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram2.PaneDistance = 10;
//diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram2.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl2.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; #endregion this.xtraTabPage1.PageVisible = false;
this.xtraTabPage2.PageVisible = false;
this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl
lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList = new List<double>();//x轴数据
List<double> ySinList = new List<double>();//系列1-y轴数据
List<double> yCosList = new List<double>();//系列2-y轴数据
List<double> yTanList = new List<double>();//系列3-y轴数据
List<double> y08TanList = new List<double>();//系列3-y轴数据
List<double> ySinCosList = new List<double>();//系列3-y轴数据
List<double> ySinDICosList = new List<double>();//系列3-y轴数据
for (int i = ; i < ; i++)
{
xaxesList.Add(i);
ySinList.Add(Math.Sin(i));
yCosList.Add(0.8*Math.Sin(i));
yTanList.Add(Math.Sin(i) + Math.Cos(i));
y08TanList.Add(0.8*Math.Sin(i) + Math.Cos(i));
ySinCosList.Add(Math.Sin(i) * Math.Cos(i));
ySinDICosList.Add( Math.Sin(i)*(i%+0.5));
}
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList = new List<List<double>>();
YList.Add(ySinList);
YList.Add(yCosList);
YList.Add(yTanList);
YList.Add(y08TanList);
YList.Add(ySinCosList);
YList.Add(ySinDICosList);
//系列内容名称
List<string> seriesTextList = new List<string>();//系列内容名称
seriesTextList.Add("预测曲线");
seriesTextList.Add("实验值");
seriesTextList.Add("cos+sin");
seriesTextList.Add("cos+0.8*sin");
seriesTextList.Add("cos*sin");
seriesTextList.Add("sin/cos"); //系列名称
List<Series> seriesNameList = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
}
//将系列假如chartControl
for (int seriesIndex = ; seriesIndex <; seriesIndex++)
{
if(seriesIndex%==)
ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]);
else
ShowSeries(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); }
//显示
int tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //尝试第二个图
this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl
lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList2 = new List<double>();//x轴数据
List<double> ySinList2 = new List<double>();//系列1-y轴数据
List<double> yCosList2 = new List<double>();//系列2-y轴数据
List<double> y08sinList2 = new List<double>();//系列3-y轴数据
List<double> y05sinList2 = new List<double>();
List<double> ySinCosList2 = new List<double>();
List<double> ySinDICosList2 = new List<double>();
for (int i = ; i < ; i++)
{
xaxesList2.Add(i);
ySinList2.Add(Math.Cos(i));
yCosList2.Add(0.8*Math.Cos(i));
y08sinList2.Add(0.6 * Math.Sin(i));
y05sinList2.Add(0.5*Math.Sin(i));
ySinCosList2.Add(0.8*Math.Sin(i) * Math.Cos(i));
ySinDICosList2.Add(0.8*Math.Sin(i)*(i%+0.5)); }
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList2 = new List<List<double>>();
YList2.Add(ySinList2);
YList2.Add(yCosList2);
YList2.Add(y08sinList2);
YList2.Add(y05sinList2);
YList2.Add(ySinCosList2);
YList2.Add(ySinDICosList2); //系列内容名称
List<string> seriesTextList2 = new List<string>();//系列内容名称
seriesTextList2.Add("预测曲线");
seriesTextList2.Add("实验值");
seriesTextList2.Add("预测曲线2");
seriesTextList2.Add("实验值2");
seriesTextList2.Add("ySinCosList22");
seriesTextList2.Add("ySinDICosList22"); //系列名称
List<Series> seriesNameList2 = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
}
//将系列加入chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if(seriesIndex%==) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce
ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); else
ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex);
}
//显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page }
public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{ //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % ));//mark类型 MarkerKind.Triangle
((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes)
{ //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} private void Form1_Load(object sender, EventArgs e)
{ } }
}
改动师弟的,还能运行
using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication1张奎
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{ #region
//int tabPagesCount = 0;
//ChartControl chartControl1 = new ChartControl(); //// Create two series.
//Series series1 = new Series("Series 1", ViewType.Bar);
//Series series2 = new Series("Series 2", ViewType.Line); //// Add points to them, with their arguments different.
//series1.Points.Add(new SeriesPoint("A", 10));
//series1.Points.Add(new SeriesPoint("B", 12));
//series1.Points.Add(new SeriesPoint("C", 17));
//series1.Points.Add(new SeriesPoint("D", 14));
//series2.Points.Add(new SeriesPoint("I", 2500));
//series2.Points.Add(new SeriesPoint("II", 3800));
//series2.Points.Add(new SeriesPoint("III", 1500));
//series2.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl1.Series.AddRange(new Series[] { series1, series2 }); //// Hide the legend (optional).
//chartControl1.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram = (XYDiagram)chartControl1.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView = (LineSeriesView)series2.View;
//myView.AxisX = diagram.SecondaryAxesX[0];
//myView.AxisY = diagram.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView.Pane = diagram.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram.PaneDistance = 10;
//diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl1.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; ////
//ChartControl chartControl2 = new ChartControl(); //// Create two series.
//Series series3 = new Series("Series 3", ViewType.Bar);
//Series series4= new Series("Series 4", ViewType.Line); //// Add points to them, with their arguments different.
//series3.Points.Add(new SeriesPoint("A", 10));
//series3.Points.Add(new SeriesPoint("B", 12));
//series3.Points.Add(new SeriesPoint("C", 17));
//series3.Points.Add(new SeriesPoint("D", 14));
//series4.Points.Add(new SeriesPoint("I", 2500));
//series4.Points.Add(new SeriesPoint("II", 3800));
//series4.Points.Add(new SeriesPoint("III", 1500));
//series4.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl2.Series.AddRange(new Series[] { series3, series4 }); //// Hide the legend (optional).
//chartControl2.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram2.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView2 = (LineSeriesView)series2.View;
//myView2.AxisX = diagram2.SecondaryAxesX[0];
//myView2.AxisY = diagram2.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView2.Pane = diagram2.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram2.PaneDistance = 10;
//diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram2.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl2.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; #endregion this.xtraTabPage1.PageVisible = false;
this.xtraTabPage2.PageVisible = false;
this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl
lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList = new List<double>();//x轴数据
List<double> ySinList = new List<double>();//系列1-y轴数据
List<double> yCosList = new List<double>();//系列2-y轴数据
List<double> yTanList = new List<double>();//系列3-y轴数据
List<double> y08TanList = new List<double>();//系列3-y轴数据
List<double> ySinCosList = new List<double>();//系列3-y轴数据
List<double> ySinDICosList = new List<double>();//系列3-y轴数据
for (int i = ; i < ; i++)
{
xaxesList.Add(i);
ySinList.Add(Math.Sin(i));
yCosList.Add(0.8*Math.Sin(i));
yTanList.Add(Math.Sin(i) + Math.Cos(i));
y08TanList.Add(0.8*Math.Sin(i) + Math.Cos(i));
ySinCosList.Add(Math.Sin(i) * Math.Cos(i));
ySinDICosList.Add( Math.Sin(i)*(i%+0.5));
}
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList = new List<List<double>>();
YList.Add(ySinList);
YList.Add(yCosList);
YList.Add(yTanList);
YList.Add(y08TanList);
YList.Add(ySinCosList);
YList.Add(ySinDICosList);
//系列内容名称
List<string> seriesTextList = new List<string>();//系列内容名称
seriesTextList.Add("预测曲线");
seriesTextList.Add("实验值");
seriesTextList.Add("cos+sin");
seriesTextList.Add("cos+0.8*sin");
seriesTextList.Add("cos*sin");
seriesTextList.Add("sin/cos"); //系列名称
List<Series> seriesNameList = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
}
//将系列假如chartControl
for (int seriesIndex = ; seriesIndex <; seriesIndex++)
{
if(seriesIndex%==)
ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]);
else
ShowSeries(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); }
//显示
int tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //尝试第二个图
this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl
lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList2 = new List<double>();//x轴数据
List<double> ySinList2 = new List<double>();//系列1-y轴数据
List<double> yCosList2 = new List<double>();//系列2-y轴数据
List<double> y08sinList2 = new List<double>();//系列3-y轴数据
List<double> y05sinList2 = new List<double>();
List<double> ySinCosList2 = new List<double>();
List<double> ySinDICosList2 = new List<double>();
for (int i = ; i < ; i++)
{
xaxesList2.Add(i);
ySinList2.Add(Math.Cos(i));
yCosList2.Add(0.8*Math.Cos(i));
y08sinList2.Add(0.6 * Math.Sin(i));
y05sinList2.Add(0.5*Math.Sin(i));
ySinCosList2.Add(0.8*Math.Sin(i) * Math.Cos(i));
ySinDICosList2.Add(0.8*Math.Sin(i)*(i%+0.5)); }
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList2 = new List<List<double>>();
YList2.Add(ySinList2);
YList2.Add(yCosList2);
YList2.Add(y08sinList2);
YList2.Add(y05sinList2);
YList2.Add(ySinCosList2);
YList2.Add(ySinDICosList2); //系列内容名称
List<string> seriesTextList2 = new List<string>();//系列内容名称
seriesTextList2.Add("预测曲线");
seriesTextList2.Add("实验值");
seriesTextList2.Add("预测曲线2");
seriesTextList2.Add("实验值2");
seriesTextList2.Add("ySinCosList22");
seriesTextList2.Add("ySinDICosList22"); //系列名称
List<Series> seriesNameList2 = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
}
//将系列加入chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if(seriesIndex%==) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce
ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); else
ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex);
}
//显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //图3
this.xtraTabPage1.PageVisible = false;
this.xtraTabPage2.PageVisible = false;
this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl
lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 //将系列假如chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if (seriesIndex % == )
ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]);
else
ShowSeries(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); }
//显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page }
public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{ //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
//((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle
//((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; //((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes)
{ //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} private void Form1_Load(object sender, EventArgs e)
{ } }
}
画第三幅图时就不行了
师弟最后解决了(就是在showseries子函数中添加了:
seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
这一句):
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress;
using DevExpress.XtraCharts; namespace DXApplication5
{
public partial class XtraForm1 : DevExpress.XtraEditors.XtraForm
{
public XtraForm1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
//this.xtraTabPage1.PageVisible = false;
//this.xtraTabPage2.PageVisible = false; ////////////////////////////////////////////////////////////////////////////////////////////////// //产生数据 1
List<double> xaxesList = new List<double>();//x轴数据
List<double> ySinList = new List<double>();//系列1-y轴数据
List<double> yCosList = new List<double>();//系列2-y轴数据
List<double> ySinAddCosList = new List<double>();//系列3-y轴数据
List<double> y08SinAddCosList = new List<double>();//系列3-y轴数据
List<double> y07SinAddCosList = new List<double>();
List<double> y06SinAddCosList = new List<double>(); for (int i = ; i < ; i++)
{
xaxesList.Add(i);
ySinList.Add(Math.Sin(i));
yCosList.Add(0.8 * Math.Sin(i));
ySinAddCosList.Add(Math.Sin(i) + Math.Cos(i));
y08SinAddCosList.Add(0.8 * Math.Sin(i) + Math.Cos(i));
y07SinAddCosList.Add(0.7 * Math.Sin(i) + Math.Cos(i));
y06SinAddCosList.Add(0.6 * Math.Sin(i) + Math.Cos(i));
} //将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList = new List<List<double>>();
YList.Add(ySinList);
YList.Add(yCosList);
YList.Add(ySinAddCosList);
YList.Add(y08SinAddCosList);
YList.Add(y07SinAddCosList);
YList.Add(y06SinAddCosList); //系列内容名称
List<string> seriesTextList = new List<string>();//系列内容名称
seriesTextList.Add("预测曲线");
seriesTextList.Add("实验值");
seriesTextList.Add("预测曲线2");
seriesTextList.Add("实验值2");
seriesTextList.Add("y07SinAddCosList");
seriesTextList.Add("y06SinAddCosList"); //系列名称
List<Series> seriesNameList = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
} //产生数据2//////////////////////////////////////////////////////////////
List<double> xaxesList2 = new List<double>();//x轴数据
List<double> ySinList2 = new List<double>();//系列1-y轴数据
List<double> yCosList2 = new List<double>();//系列2-y轴数据
List<double> ySinAddCosList2 = new List<double>();//系列3-y轴数据
List<double> y08SinAddCosList2 = new List<double>();//系列3-y轴数据
List<double> y07SinAddCosList2 = new List<double>();
List<double> y06SinAddCosList2 = new List<double>();
for (int i = ; i < ; i++)
{
xaxesList2.Add(i);
ySinList2.Add(*Math.Sin(i));
yCosList2.Add(1.8 * Math.Sin(i));
ySinAddCosList2.Add(2.5*Math.Sin(i) + 2.5*Math.Cos(i));
y08SinAddCosList2.Add(2.0 * Math.Sin(i) + 2.0*Math.Cos(i));
y07SinAddCosList2.Add(2.0*0.7 * Math.Sin(i) + 2.0 * Math.Cos(i));
y06SinAddCosList2.Add(2.0 *0.6* Math.Sin(i) + 2.0 * Math.Cos(i));
} //将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList2 = new List<List<double>>();
YList2.Add(ySinList2);
YList2.Add(yCosList2);
YList2.Add(ySinAddCosList2);
YList2.Add(y08SinAddCosList2);
YList2.Add(y07SinAddCosList2);
YList2.Add(y06SinAddCosList2); //系列内容名称
List<string> seriesTextList2 = new List<string>();//系列内容名称
seriesTextList2.Add("预测曲线");
seriesTextList2.Add("实验值");
seriesTextList2.Add("预测曲线2");
seriesTextList2.Add("实验值2");
seriesTextList2.Add("y07SinAddCosList2");
seriesTextList2.Add("y07SinAddCosList2"); //系列名称
List<Series> seriesNameList2 = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
} //产生数据3//////////////////////////////////////////////////////////////
List<double> xaxesList3 = new List<double>();//x轴数据
List<double> ySinList3 = new List<double>();//系列1-y轴数据
List<double> yCosList3 = new List<double>();//系列2-y轴数据
List<double> ySinAddCosList3 = new List<double>();//系列3-y轴数据
List<double> y08SinAddCosList3 = new List<double>();//系列3-y轴数据
List<double> y07SinAddCosList3 = new List<double>();//
List<double> y06SinAddCosList3 = new List<double>();// for (int i = ; i < ; i++)
{
xaxesList3.Add(i);
ySinList3.Add( * Math.Sin(i));
yCosList3.Add(5.8 * Math.Sin(i));
ySinAddCosList3.Add(4.15 * Math.Sin(i) + 4.15 * Math.Cos(i));
y08SinAddCosList3.Add(5.1 * Math.Sin(i) + 5.1 * Math.Cos(i));
y07SinAddCosList3.Add(0.7*5.1 * Math.Sin(i) + 5.1 * Math.Cos(i));
y06SinAddCosList3.Add(0.6*5.1 * Math.Sin(i) + 5.1 * Math.Cos(i));
} //将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList3 = new List<List<double>>();
YList3.Add(ySinList3);
YList3.Add(yCosList3);
YList3.Add(ySinAddCosList3);
YList3.Add(y08SinAddCosList3);
YList3.Add(y07SinAddCosList3);
YList3.Add(y06SinAddCosList3); //系列内容名称
List<string> seriesTextList3 = new List<string>();//系列内容名称
seriesTextList3.Add("预测曲线");
seriesTextList3.Add("实验值");
seriesTextList3.Add("预测曲线2");
seriesTextList3.Add("实验值2");
seriesTextList3.Add("y07SinAddCosList3");
seriesTextList3.Add("y06SinAddCosList3"); //系列名称
List<Series> seriesNameList3 = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList3.Add(new Series(seriesTextList3[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
} ////////////////////第一张图//////////////////////////////////////////// //1.新建TabPage和ChartControl
this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl1 = new ChartControl();//实例化一个ChartControl
lineChartControl1.Legend.UseCheckBoxes = true;//图例可以勾选 //2.将系列加入chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
//if (seriesIndex % 2 == 0)
ShowSeries_yuce(lineChartControl1, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); // else
ShowSeries(lineChartControl1, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); } //3.显示
int tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl1);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page ///////////////////第二个图///////////////////////////////////////////////////
//1.新建TabPage和ChartControl
this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl
lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 //2.将系列加入chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
//if (seriesIndex == 0 || seriesIndex == 2) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce
ShowSeries_yuce(lineChartControl2, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); //else
ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex);
}
//3.显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //////////////////第3个图/////////////////////////////////////////////////////
//1.新建TabPage和ChartControl
this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl
lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 //2.将系列加入chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
// if (seriesIndex % 2 == 0) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce
ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); //else
ShowSeries(lineChartControl3, seriesNameList3[seriesIndex], seriesTextList3[seriesIndex], xaxesList3, YList3[seriesIndex], seriesIndex);
} //3.显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //////////////////第4个图/////////////////////////////////////////////////////
//1.新建TabPage和ChartControl
this.xtraTabControl1.TabPages.Add("三角函数图4");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl4 = new ChartControl();//实例化一个ChartControl
lineChartControl4.Legend.UseCheckBoxes = true;//图例可以勾选 //2.将系列假如chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
//if (seriesIndex % 2 == 0)
ShowSeries_yuce(lineChartControl4, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); //else
ShowSeries(lineChartControl4, seriesNameList3[seriesIndex], seriesTextList3[seriesIndex], xaxesList3, YList3[seriesIndex], seriesIndex); } //3.显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl4);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page
} //////////////////////////////////////////////////////////////////////////////////////////////
//ShowSeries和ShowSeries_yuce
public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{
seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % ));//mark类型 MarkerKind.Triangle
((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{ seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
//((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle
//((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
}
}
}
画四幅图都没问题
下面尝试改变每条线的颜色:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress;
using DevExpress.XtraCharts; namespace DXApplication1借鉴张奎师弟
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{ #region
//int tabPagesCount = 0;
//ChartControl chartControl1 = new ChartControl(); //// Create two series.
//Series series1 = new Series("Series 1", ViewType.Bar);
//Series series2 = new Series("Series 2", ViewType.Line); //// Add points to them, with their arguments different.
//series1.Points.Add(new SeriesPoint("A", 10));
//series1.Points.Add(new SeriesPoint("B", 12));
//series1.Points.Add(new SeriesPoint("C", 17));
//series1.Points.Add(new SeriesPoint("D", 14));
//series2.Points.Add(new SeriesPoint("I", 2500));
//series2.Points.Add(new SeriesPoint("II", 3800));
//series2.Points.Add(new SeriesPoint("III", 1500));
//series2.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl1.Series.AddRange(new Series[] { series1, series2 }); //// Hide the legend (optional).
//chartControl1.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram = (XYDiagram)chartControl1.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView = (LineSeriesView)series2.View;
//myView.AxisX = diagram.SecondaryAxesX[0];
//myView.AxisY = diagram.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView.Pane = diagram.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram.PaneDistance = 10;
//diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl1.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; ////
//ChartControl chartControl2 = new ChartControl(); //// Create two series.
//Series series3 = new Series("Series 3", ViewType.Bar);
//Series series4= new Series("Series 4", ViewType.Line); //// Add points to them, with their arguments different.
//series3.Points.Add(new SeriesPoint("A", 10));
//series3.Points.Add(new SeriesPoint("B", 12));
//series3.Points.Add(new SeriesPoint("C", 17));
//series3.Points.Add(new SeriesPoint("D", 14));
//series4.Points.Add(new SeriesPoint("I", 2500));
//series4.Points.Add(new SeriesPoint("II", 3800));
//series4.Points.Add(new SeriesPoint("III", 1500));
//series4.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl2.Series.AddRange(new Series[] { series3, series4 }); //// Hide the legend (optional).
//chartControl2.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram2.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView2 = (LineSeriesView)series2.View;
//myView2.AxisX = diagram2.SecondaryAxesX[0];
//myView2.AxisY = diagram2.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView2.Pane = diagram2.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram2.PaneDistance = 10;
//diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram2.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl2.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; #endregion this.xtraTabPage1.PageVisible = false;
this.xtraTabPage2.PageVisible = false;
this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl
lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList = new List<double>();//x轴数据
List<double> ySinList = new List<double>();//系列1-y轴数据
List<double> yCosList = new List<double>();//系列2-y轴数据
List<double> ySinAddCosList = new List<double>();//系列3-y轴数据 for (int i = ; i < ; i++)
{
xaxesList.Add(i);
ySinList.Add(Math.Sin(i));
yCosList.Add(Math.Cos(i));
ySinAddCosList.Add(Math.Sin(i) + Math.Cos(i)); }
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList = new List<List<double>>();
YList.Add(ySinList);
YList.Add(yCosList);
YList.Add(ySinAddCosList); //系列内容名称
List<string> seriesTextList = new List<string>();//系列内容名称
seriesTextList.Add("sin理论");
seriesTextList.Add("cos理论");
seriesTextList.Add("cos+sin理论"); //系列名称
List<Series> seriesNameList = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
} //产生数据2
List<double> xaxesList2 = new List<double>();//x轴数据
List<double> ySinList2 = new List<double>();//系列1-y轴数据
List<double> yCosList2 = new List<double>();//系列2-y轴数据
List<double> ySinAddCosList2 = new List<double>();//系列3-y轴数据 for (int i = ; i < ; i++)
{
xaxesList2.Add(i);
ySinList2.Add(0.8*Math.Sin(i));
yCosList2.Add(0.8 * Math.Cos(i));
ySinAddCosList2.Add(0.8 * Math.Sin(i) + 0.8 * Math.Cos(i)); }
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList2 = new List<List<double>>();
YList2.Add(ySinList2);
YList2.Add(yCosList2);
YList2.Add(ySinAddCosList2); //系列内容名称
List<string> seriesTextList2 = new List<string>();//系列内容名称
seriesTextList2.Add("sin实验");
seriesTextList2.Add("cos实验");
seriesTextList2.Add("sin+cos实验"); //系列名称
List<Series> seriesNameList2 = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
} //将系列加入chartControl
for (int seriesIndex = ; seriesIndex <; seriesIndex++)
{ ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]); ShowSeries(lineChartControl, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); }
//显示
int tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page ////尝试第二个图
//this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
//ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl
//lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 ////将系列加入chartControl
//for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++)
//{
// if(seriesIndex%2==0) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce
// ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); // else
// ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex);
//}
////显示
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page // //图3
// this.xtraTabPage1.PageVisible = false;
// this.xtraTabPage2.PageVisible = false;
// this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
// ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl
// lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 // //将系列假如chartControl
// for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++)
// {
// if (seriesIndex % 2 == 0)
// ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]);
// else
// ShowSeries(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); // }
// //显示
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中
// this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page }
public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{ seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % ));//mark类型 MarkerKind.Triangle
((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True;
((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash; //((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes)
{ seriesName = new Series(seriesText, ViewType.Spline);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Solid;//线型 for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} private void Form1_Load(object sender, EventArgs e)
{ } }
}
尝试改变颜色,数据准备好
可以变颜色了:
上图的代码(当然,要拉取一个窗口,加入chartcontrol控件,目的是自动加入对应的引用,之后可以删除,因为可以用代码添加chartcontrol。加入xtratabcontrol,目的是盛放图。再加入一个button即可,将下面代码放入button1内(设计模式下双击button即可进入其对应的代码)),其实要解决不能添加series的问题的关键是在showSeries函数中再新建series:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress;
using DevExpress.XtraCharts; namespace DXApplication1借鉴张奎师弟
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{ #region
//int tabPagesCount = 0;
//ChartControl chartControl1 = new ChartControl(); //// Create two series.
//Series series1 = new Series("Series 1", ViewType.Bar);
//Series series2 = new Series("Series 2", ViewType.Line); //// Add points to them, with their arguments different.
//series1.Points.Add(new SeriesPoint("A", 10));
//series1.Points.Add(new SeriesPoint("B", 12));
//series1.Points.Add(new SeriesPoint("C", 17));
//series1.Points.Add(new SeriesPoint("D", 14));
//series2.Points.Add(new SeriesPoint("I", 2500));
//series2.Points.Add(new SeriesPoint("II", 3800));
//series2.Points.Add(new SeriesPoint("III", 1500));
//series2.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl1.Series.AddRange(new Series[] { series1, series2 }); //// Hide the legend (optional).
//chartControl1.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram = (XYDiagram)chartControl1.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView = (LineSeriesView)series2.View;
//myView.AxisX = diagram.SecondaryAxesX[0];
//myView.AxisY = diagram.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView.Pane = diagram.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram.PaneDistance = 10;
//diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl1.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; ////
//ChartControl chartControl2 = new ChartControl(); //// Create two series.
//Series series3 = new Series("Series 3", ViewType.Bar);
//Series series4= new Series("Series 4", ViewType.Line); //// Add points to them, with their arguments different.
//series3.Points.Add(new SeriesPoint("A", 10));
//series3.Points.Add(new SeriesPoint("B", 12));
//series3.Points.Add(new SeriesPoint("C", 17));
//series3.Points.Add(new SeriesPoint("D", 14));
//series4.Points.Add(new SeriesPoint("I", 2500));
//series4.Points.Add(new SeriesPoint("II", 3800));
//series4.Points.Add(new SeriesPoint("III", 1500));
//series4.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl2.Series.AddRange(new Series[] { series3, series4 }); //// Hide the legend (optional).
//chartControl2.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram2.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView2 = (LineSeriesView)series2.View;
//myView2.AxisX = diagram2.SecondaryAxesX[0];
//myView2.AxisY = diagram2.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView2.Pane = diagram2.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram2.PaneDistance = 10;
//diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram2.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl2.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; #endregion this.xtraTabPage1.PageVisible = false;
this.xtraTabPage2.PageVisible = false;
this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl
lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList = new List<double>();//x轴数据
List<double> ySinList = new List<double>();//系列1-y轴数据
List<double> yCosList = new List<double>();//系列2-y轴数据
List<double> ySinAddCosList = new List<double>();//系列3-y轴数据
List<double> ySinMinCosList = new List<double>(); for (int i = ; i < ; i++)
{
xaxesList.Add(i);
ySinList.Add(Math.Sin(i));
yCosList.Add(Math.Cos(i));
ySinAddCosList.Add(Math.Sin(i) + Math.Cos(i));
ySinMinCosList.Add(Math.Sin(i) - Math.Cos(i));
}
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList = new List<List<double>>();
YList.Add(ySinList);
YList.Add(yCosList);
YList.Add(ySinAddCosList);
YList.Add(ySinMinCosList); //系列内容名称
List<string> seriesTextList = new List<string>();//系列内容名称
seriesTextList.Add("sin理论");
seriesTextList.Add("cos理论");
seriesTextList.Add("sin+cos理论");
seriesTextList.Add("sin-cos理论"); //系列名称
List<Series> seriesNameList = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
} //产生数据2
List<double> xaxesList2 = new List<double>();//x轴数据
List<double> ySinList2 = new List<double>();//系列1-y轴数据
List<double> yCosList2 = new List<double>();//系列2-y轴数据
List<double> ySinAddCosList2 = new List<double>();//系列3-y轴数据
List<double> ySinMinCosList2 = new List<double>();
for (int i = ; i < ; i++)
{
xaxesList2.Add(i);
ySinList2.Add(0.8*Math.Sin(i));
yCosList2.Add(0.8 * Math.Cos(i));
ySinAddCosList2.Add(0.8 * Math.Sin(i) + 0.8 * Math.Cos(i));
ySinMinCosList2.Add(0.8 * Math.Sin(i) - 0.8 * Math.Cos(i)); }
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList2 = new List<List<double>>();
YList2.Add(ySinList2);
YList2.Add(yCosList2);
YList2.Add(ySinAddCosList2);
YList2.Add(ySinMinCosList2); //系列内容名称
List<string> seriesTextList2 = new List<string>();//系列内容名称
seriesTextList2.Add("sin实验");
seriesTextList2.Add("cos实验");
seriesTextList2.Add("sin+cos实验");
seriesTextList2.Add("sin-cos实验"); //系列名称
List<Series> seriesNameList2 = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
} //将系列加入chartControl
for (int seriesIndex = ; seriesIndex <; seriesIndex++)
{ ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex],seriesIndex); ShowSeries(lineChartControl, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex); }
//显示
int tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page ////尝试第二个图
//this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
//ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl
//lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 ////将系列加入chartControl
//for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++)
//{
// if(seriesIndex%2==0) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce
// ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); // else
// ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex);
//}
////显示
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page // //图3
// this.xtraTabPage1.PageVisible = false;
// this.xtraTabPage2.PageVisible = false;
// this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
// ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl
// lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 // //将系列假如chartControl
// for (int seriesIndex = 0; seriesIndex < 6; seriesIndex++)
// {
// if (seriesIndex % 2 == 0)
// ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]);
// else
// ShowSeries(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); // }
// //显示
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中
// this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page }
/// <summary>
/// 实验值画图
/// </summary>
/// <param name="lineChartControl">图</param>
/// <param name="seriesName">系列名,可以理解为id号</param>
/// <param name="seriesText">系列内容名,显示在图中</param>
/// <param name="xAxes"></param>
/// <param name="yAxes"></param>
/// <param name="iMarkerKind">根据传入的int值来赋标记种类</param>
public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{ seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % ));//mark类型 MarkerKind.Triangle
((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True;
((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;
seriesName.View.Color = Color.FromKnownColor((KnownColor)((iMarkerKind+)*%)); //((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{ seriesName = new Series(seriesText, ViewType.Spline);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
seriesName.View.Color = Color.FromKnownColor((KnownColor)((iMarkerKind + ) * % ));
((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Solid;//线型 for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} private void Form1_Load(object sender, EventArgs e)
{ } }
}
可以绘图啦
((XYDiagram)lineChartControl.Diagram).AxisX.Logarithmic = true;//打开对数坐标
((XYDiagram)lineChartControl.Diagram).AxisX.LogarithmicBase = Math.E;//若为对数坐标系,则底为自然对数e
((XYDiagram)lineChartControl.Diagram).AxisX.Title.Text = "lnp";//x轴标题
((XYDiagram)lineChartControl.Diagram).AxisY.Title.Text = "e";//y轴标题
((XYDiagram)lineChartControl.Diagram).AxisX.Title.Visible = true;//将x轴标题显示出来
((XYDiagram)lineChartControl.Diagram).AxisY.Title.Visible = true;//将y轴标题显示出来
x轴对数坐标
using DevExpress.XtraCharts;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms; namespace WindowsFormsApplication1张奎
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{ #region
//int tabPagesCount = 0;
//ChartControl chartControl1 = new ChartControl(); //// Create two series.
//Series series1 = new Series("Series 1", ViewType.Bar);
//Series series2 = new Series("Series 2", ViewType.Line); //// Add points to them, with their arguments different.
//series1.Points.Add(new SeriesPoint("A", 10));
//series1.Points.Add(new SeriesPoint("B", 12));
//series1.Points.Add(new SeriesPoint("C", 17));
//series1.Points.Add(new SeriesPoint("D", 14));
//series2.Points.Add(new SeriesPoint("I", 2500));
//series2.Points.Add(new SeriesPoint("II", 3800));
//series2.Points.Add(new SeriesPoint("III", 1500));
//series2.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl1.Series.AddRange(new Series[] { series1, series2 }); //// Hide the legend (optional).
//chartControl1.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram = (XYDiagram)chartControl1.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView = (LineSeriesView)series2.View;
//myView.AxisX = diagram.SecondaryAxesX[0];
//myView.AxisY = diagram.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView.Pane = diagram.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram.PaneDistance = 10;
//diagram.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl1.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count-1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl1);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; ////
//ChartControl chartControl2 = new ChartControl(); //// Create two series.
//Series series3 = new Series("Series 3", ViewType.Bar);
//Series series4= new Series("Series 4", ViewType.Line); //// Add points to them, with their arguments different.
//series3.Points.Add(new SeriesPoint("A", 10));
//series3.Points.Add(new SeriesPoint("B", 12));
//series3.Points.Add(new SeriesPoint("C", 17));
//series3.Points.Add(new SeriesPoint("D", 14));
//series4.Points.Add(new SeriesPoint("I", 2500));
//series4.Points.Add(new SeriesPoint("II", 3800));
//series4.Points.Add(new SeriesPoint("III", 1500));
//series4.Points.Add(new SeriesPoint("IV", 1300)); //// Add both series to the chart.
//chartControl2.Series.AddRange(new Series[] { series3, series4 }); //// Hide the legend (optional).
//chartControl2.Legend.Visible = false; //// Cast the chart's diagram to the XYDiagram type,
//// to access its axes and panes.
//XYDiagram diagram2 = (XYDiagram)chartControl2.Diagram; //// Add secondary axes to the diagram, and adjust their options.
//diagram2.SecondaryAxesX.Add(new SecondaryAxisX("My Axis X"));
//diagram2.SecondaryAxesY.Add(new SecondaryAxisY("My Axis Y"));
//diagram2.SecondaryAxesX[0].Alignment = AxisAlignment.Near;
//diagram2.SecondaryAxesY[0].Alignment = AxisAlignment.Near; //// Add a new additional pane to the diagram.
//diagram2.Panes.Add(new XYDiagramPane("My Pane")); //// Assign both the additional pane and, if required,
//// the secondary axes to the second series.
//LineSeriesView myView2 = (LineSeriesView)series2.View;
//myView2.AxisX = diagram2.SecondaryAxesX[0];
//myView2.AxisY = diagram2.SecondaryAxesY[0];
//// Note that the created pane has the zero index in the collection,
//// because the existing Default pane is a separate entity.
//myView2.Pane = diagram2.Panes[0]; //// Customize the layout of the diagram's panes.
//diagram2.PaneDistance = 10;
//diagram2.PaneLayoutDirection = PaneLayoutDirection.Horizontal;
//diagram2.DefaultPane.SizeMode = PaneSizeMode.UseWeight;
//diagram2.DefaultPane.Weight = 1.2; //// Add the chart to the form.
//chartControl2.Dock = DockStyle.Fill;
////this.Controls.Add(chartControl1);
//this.xtraTabControl1.TabPages.Add("zbl两个pane图");//添加一个page
//tabPagesCount = this.xtraTabControl1.TabPages.Count - 1;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
//this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(chartControl2);
//this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount; #endregion this.xtraTabPage1.PageVisible = false;
this.xtraTabPage2.PageVisible = false;
this.xtraTabControl1.TabPages.Add("三角函数图");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl = new ChartControl();//实例化一个ChartControl
lineChartControl.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList = new List<double>();//x轴数据
List<double> ySinList = new List<double>();//系列1-y轴数据
List<double> yCosList = new List<double>();//系列2-y轴数据
List<double> yTanList = new List<double>();//系列3-y轴数据
List<double> y08TanList = new List<double>();//系列3-y轴数据
List<double> ySinCosList = new List<double>();//系列3-y轴数据
List<double> ySinDICosList = new List<double>();//系列3-y轴数据
for (int i = ; i < ; i++)
{
xaxesList.Add(i);
ySinList.Add(Math.Sin(i));
yCosList.Add(0.8*Math.Sin(i));
yTanList.Add(Math.Sin(i) + Math.Cos(i));
y08TanList.Add(0.8*Math.Sin(i) + Math.Cos(i));
ySinCosList.Add(Math.Sin(i) * Math.Cos(i));
ySinDICosList.Add( Math.Sin(i)*(i%+0.5));
}
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList = new List<List<double>>();
YList.Add(ySinList);
YList.Add(yCosList);
YList.Add(yTanList);
YList.Add(y08TanList);
YList.Add(ySinCosList);
YList.Add(ySinDICosList);
//系列内容名称
List<string> seriesTextList = new List<string>();//系列内容名称
seriesTextList.Add("预测曲线");
seriesTextList.Add("实验值");
seriesTextList.Add("cos+sin");
seriesTextList.Add("cos+0.8*sin");
seriesTextList.Add("cos*sin");
seriesTextList.Add("sin/cos"); //系列名称
List<Series> seriesNameList = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList.Add(new Series(seriesTextList[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
}
//将系列假如chartControl
for (int seriesIndex = ; seriesIndex <; seriesIndex++)
{
if(seriesIndex%==)
ShowSeries_yuce(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]);
else
ShowSeries(lineChartControl, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); }
//显示
int tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //尝试第二个图
this.xtraTabControl1.TabPages.Add("三角函数图2");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl2 = new ChartControl();//实例化一个ChartControl
lineChartControl2.Legend.UseCheckBoxes = true;//图例可以勾选 //产生数据
List<double> xaxesList2 = new List<double>();//x轴数据
List<double> ySinList2 = new List<double>();//系列1-y轴数据
List<double> yCosList2 = new List<double>();//系列2-y轴数据
List<double> y08sinList2 = new List<double>();//系列3-y轴数据
List<double> y05sinList2 = new List<double>();
List<double> ySinCosList2 = new List<double>();
List<double> ySinDICosList2 = new List<double>();
for (int i = ; i < ; i++)
{
xaxesList2.Add(i);
ySinList2.Add(Math.Cos(i));
yCosList2.Add(0.8*Math.Cos(i));
y08sinList2.Add(0.6 * Math.Sin(i));
y05sinList2.Add(0.5*Math.Sin(i));
ySinCosList2.Add(0.8*Math.Sin(i) * Math.Cos(i));
ySinDICosList2.Add(0.8*Math.Sin(i)*(i%+0.5)); }
//将所有系列的y值放入一个列表,这个列表是列表的列表
List<List<double>> YList2 = new List<List<double>>();
YList2.Add(ySinList2);
YList2.Add(yCosList2);
YList2.Add(y08sinList2);
YList2.Add(y05sinList2);
YList2.Add(ySinCosList2);
YList2.Add(ySinDICosList2); //系列内容名称
List<string> seriesTextList2 = new List<string>();//系列内容名称
seriesTextList2.Add("预测曲线");
seriesTextList2.Add("实验值");
seriesTextList2.Add("预测曲线2");
seriesTextList2.Add("实验值2");
seriesTextList2.Add("ySinCosList22");
seriesTextList2.Add("ySinDICosList22"); //系列名称
List<Series> seriesNameList2 = new List<Series>();
for (int i = ; i < ; i++)
{
//完全建立一个系列,以后直接用就行了
seriesNameList2.Add(new Series(seriesTextList2[i], ViewType.Spline));//ScatterLine点划线,实验值用这种,理论值用line
}
//将系列加入chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if(seriesIndex%==) //根据数据是实验值还是预测值分别选择绘图函数 ShowSeries或者ShowSeries_yuce
ShowSeries_yuce(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex]); else
ShowSeries(lineChartControl2, seriesNameList2[seriesIndex], seriesTextList2[seriesIndex], xaxesList2, YList2[seriesIndex], seriesIndex);
}
//显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl2);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page //图3
this.xtraTabPage1.PageVisible = false;
this.xtraTabPage2.PageVisible = false;
this.xtraTabControl1.TabPages.Add("三角函数图3");//添加一个page,在此之前可以直接用ui界面的本控件的remove属性删除默认的两个page
ChartControl lineChartControl3 = new ChartControl();//实例化一个ChartControl
lineChartControl3.Legend.UseCheckBoxes = true;//图例可以勾选 //将系列假如chartControl
for (int seriesIndex = ; seriesIndex < ; seriesIndex++)
{
if (seriesIndex % == )
ShowSeries_yuce(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex]);
else
ShowSeries(lineChartControl3, seriesNameList[seriesIndex], seriesTextList[seriesIndex], xaxesList, YList[seriesIndex], seriesIndex); }
//显示
tabPagesCount = this.xtraTabControl1.TabPages.Count - ;//xtraTabControl2page的个数,为了删除默认的,可以用ui界面的remove
this.xtraTabControl1.TabPages[tabPagesCount].Controls.Add(lineChartControl3);//将ChartControl这个控件添加到这个page中
this.xtraTabControl1.SelectedTabPageIndex = tabPagesCount;//切换到这个page为选中的page }
public void ShowSeries(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes, int iMarkerKind)
{ //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字
//((LineSeriesView)seriesName.View).LineMarkerOptions.Kind = (MarkerKind)((iMarkerKind % 9));//mark类型 MarkerKind.Triangle
//((LineSeriesView)seriesName.View).MarkerVisibility = DevExpress.Utils.DefaultBoolean.True; //((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} public void ShowSeries_yuce(ChartControl lineChartControl, Series seriesName, string seriesText, List<double> xAxes,
List<double> yAxes)
{ //seriesName = new Series(seriesText, ViewType.ScatterLine);//新建立一个系列
seriesName.ArgumentScaleType = ScaleType.Numerical;//x轴数据类型,为数字 ((LineSeriesView)seriesName.View).LineStyle.DashStyle = DashStyle.Dash;//线型
for (int pointIndex = ; pointIndex < xAxes.Count; pointIndex++)
{
seriesName.Points.Add(new SeriesPoint(xAxes[pointIndex], yAxes[pointIndex]));
}
lineChartControl.Series.Add(seriesName);//往ChartControl控件上添加系列
lineChartControl.Legend.Visible = true;//图例可见
((XYDiagram)lineChartControl.Diagram).Rotated = false;//ChartControl控件不旋转
lineChartControl.Dock = DockStyle.Fill;//ChartControl控件在父控件内填满平铺
} private void Form1_Load(object sender, EventArgs e)
{ } }
}
using System;
using DevExpress.Utils.Menu; namespace DevExpress.XtraCharts.Demos {
public partial class ChartDemoSecondaryAxes : ChartDemoBase2D {
struct AxisItem {
readonly Axis axis; public Axis Axis { get { return axis; } } public AxisItem(Axis axis) {
this.axis = axis;
}
public override string ToString() {
return axis.Name;
}
public override bool Equals(object obj) {
if (!(obj is AxisItem))
return false;
AxisItem item = (AxisItem)obj;
return axis.Equals(item.axis);
}
public override int GetHashCode() {
return axis.GetHashCode();
}
} const string SecondaryPostfixX = " (Secondary Axis X)";
const string SecondaryPostfixY = " (Secondary Axis Y)";
const string PrimaryPostfixX = " (Primary Axis X)";
const string PrimaryPostfixY = " (Primary Axis Y)";
const int LineChart = ;
const int BarChart = ; bool loading;
ChartControl chart;
XYDiagram Diagram { get { return ChartControl.Diagram as XYDiagram; } }
SecondaryAxisX SecondaryAxisX { get { return (Diagram != null && Diagram.SecondaryAxesX.Count > ) ? Diagram.SecondaryAxesX[] : null; } }
SecondaryAxisY SecondaryAxisY { get { return (Diagram != null && Diagram.SecondaryAxesY.Count > ) ? Diagram.SecondaryAxesY[] : null; } }
Series FirstSeries { get { return ChartControl.Series.Count > ? ChartControl.Series[] : null; } }
Series SecondSeries { get { return ChartControl.Series.Count > ? ChartControl.Series[] : null; } }
XYDiagramSeriesViewBase SecondSeriesView { get { return SecondSeries != null ? SecondSeries.View as XYDiagramSeriesViewBase : null; } }
public override ChartControl ChartControl { get { return chart; } } public ChartDemoSecondaryAxes() {
InitializeComponent();
if (Diagram == null)
return;
((Axis)Diagram.AxisX).Name = "Primary Axis X";
((Axis)Diagram.AxisY).Name = "Primary Axis Y";
Diagram.SecondaryAxesX.Add(new SecondaryAxisX("Secondary Axis X"));
Diagram.SecondaryAxesY.Add(new SecondaryAxisY("Secondary Axis Y"));
this.cbChartType.Properties.Items.AddRange(new string[] { "Line", "Bar" });
loading = true;
try {
UpdateChartType();
if (SecondSeries != null) {
UpdateCBSeriesAxisX(Diagram.AxisX);
UpdateCBSeriesAxisY(SecondaryAxisY);
}
}
finally {
loading = false;
}
}
void AttachSecondaryAxisX(SecondaryAxisX axisX) {
if(axisX == null || Diagram == null)
return;
if(SecondSeriesView != null) {
SecondSeriesView.AxisX = axisX;
axisX.Visible = true;
if(FirstSeries != null)
Diagram.AxisX.Title.Text = FirstSeries.Name + PrimaryPostfixX;
if(SecondaryAxisX != null) {
SecondaryAxisX.Title.Visible = true;
SecondaryAxisX.Title.Text = SecondSeries.Name + SecondaryPostfixX;
}
}
}
void AttachSecondaryAxisY(SecondaryAxisY axisY) {
if(axisY == null || Diagram == null)
return;
if(SecondSeriesView != null) {
SecondSeriesView.AxisY = axisY;
axisY.Visible = true;
if(FirstSeries != null)
Diagram.AxisY.Title.Text = FirstSeries.Name + PrimaryPostfixY;
if(SecondaryAxisY != null) {
SecondaryAxisY.Title.Visible = true;
SecondaryAxisY.Title.Text = SecondSeries.Name + SecondaryPostfixY;
}
}
}
void DetachSecondaryAxisX() {
if(Diagram == null)
return;
if(SecondSeriesView != null) {
if(SecondaryAxisX != null)
SecondaryAxisX.Visible = false;
SecondSeriesView.AxisX = Diagram.AxisX;
if(FirstSeries != null)
Diagram.AxisX.Title.Text = FirstSeries.Name + ", " + SecondSeries.Name + PrimaryPostfixX;
}
}
void DetachSecondaryAxisY() {
if(Diagram == null)
return;
if(SecondSeriesView != null) {
if(SecondaryAxisY != null)
SecondaryAxisY.Visible = false;
SecondSeriesView.AxisY = Diagram.AxisY;
if(FirstSeries != null)
Diagram.AxisY.Title.Text = FirstSeries.Name + ", " + SecondSeries.Name + PrimaryPostfixX;
}
}
void ChangeSeriesViewType(ViewType viewType) {
foreach (Series series in ChartControl.Series)
series.ChangeView(viewType);
}
void UpdateChartType() {
int selectedIndex = -;
foreach(Series series in chart.Series) {
if(series.View is LineSeriesView) {
selectedIndex = LineChart;
break;
}
else if(series.View is SideBySideBarSeriesView)
selectedIndex = BarChart;
}
cbChartType.SelectedIndex = selectedIndex;
}
void UpdateCBSeriesAxisX(Axis selectedAxisX) {
cbSeriesAxisX.Properties.Items.Clear();
if(Diagram == null)
return;
cbSeriesAxisX.Properties.Items.Add(new AxisItem(Diagram.AxisX));
foreach(SecondaryAxisX axisX in Diagram.SecondaryAxesX)
cbSeriesAxisX.Properties.Items.Add(new AxisItem(axisX));
cbSeriesAxisX.SelectedItem = new AxisItem(selectedAxisX);
}
void UpdateCBSeriesAxisY(Axis selectedAxisY) {
cbSeriesAxisY.Properties.Items.Clear();
if(Diagram == null)
return;
cbSeriesAxisY.Properties.Items.Add(new AxisItem(Diagram.AxisY));
foreach(SecondaryAxisY axisY in Diagram.SecondaryAxesY)
cbSeriesAxisY.Properties.Items.Add(new AxisItem(axisY));
cbSeriesAxisY.SelectedItem = new AxisItem(selectedAxisY);
}
void cbChartType_SelectedIndexChanged(object sender, EventArgs e) {
if (loading)
return;
if (cbChartType.SelectedIndex == LineChart)
ChangeSeriesViewType(ViewType.Line);
else if (cbChartType.SelectedIndex == BarChart)
ChangeSeriesViewType(ViewType.Bar);
}
void cbSeriesAxisX_SelectedIndexChanged(object sender, EventArgs e) {
SecondaryAxisX axisX = ((AxisItem)cbSeriesAxisX.SelectedItem).Axis as SecondaryAxisX;
if(axisX != null)
AttachSecondaryAxisX(axisX);
else
DetachSecondaryAxisX();
}
void cbSeriesAxisY_SelectedIndexChanged(object sender, EventArgs e) {
SecondaryAxisY axisY = ((AxisItem)cbSeriesAxisY.SelectedItem).Axis as SecondaryAxisY;
if(axisY != null)
AttachSecondaryAxisY(axisY);
else
DetachSecondaryAxisY();
}
protected override DXPopupMenu ConstructPopupMenu(object obj, ChartControl chartControl) {
return DXMenuHelper.ConstructSecondaryAxesMenu(obj, chartControl);
}
public override void UpdateControls() {
base.UpdateControls();
loading = true;
try {
UpdateChartType();
if (SecondSeriesView != null) {
UpdateCBSeriesAxisX(SecondSeriesView.AxisX);
UpdateCBSeriesAxisY(SecondSeriesView.AxisY);
}
}
finally {
loading = false;
}
}
}
}
两个y轴
using System;
using DevExpress.Utils; namespace DevExpress.XtraCharts.Demos {
public partial class ChartDemoScatterLine : ChartDemoLineBase {
const int a = ;
const int archimedianSpiralIndex = ;
const int cardioidIndex = ;
const int cartesianFoliumIndex = ; SeriesCollection Series { get { return chart.Series; } }
Series ArchimedianSpiralSeries { get { return Series[archimedianSpiralIndex]; } }
Series CardioidSeries { get { return Series[cardioidIndex]; } }
Series CartesianFoliumSeries { get { return Series[cartesianFoliumIndex]; } }
protected override Series[] ProcessedSeries { get { return new Series[] { ArchimedianSpiralSeries, CardioidSeries, CartesianFoliumSeries }; } }
protected override DefaultBoolean CrosshairEnabled { get { return DefaultBoolean.False; } }
protected override DefaultBoolean ToolTipEnabled { get { return DefaultBoolean.True; } }
public override ChartControl ChartControl { get { return chart; } } public ChartDemoScatterLine() {
InitializeComponent(); }
void CreateArchimedianSpiralPoints() {
for (int i = ; i < ; i += ) {
double t = (double)i / * Math.PI;
double x = t * Math.Cos(t);
double y = t * Math.Sin(t);
ArchimedianSpiralSeries.Points.Add(new SeriesPoint(x, y));
}
}
void CreateCardioidPoints() {
for (int i = ; i < ; i += ) {
double t = (double)i / * Math.PI;
double x = a * ( * Math.Cos(t) - Math.Cos( * t));
double y = a * ( * Math.Sin(t) - Math.Sin( * t));
CardioidSeries.Points.Add(new SeriesPoint(x, y));
}
}
void CreateCartesianFoliumPoints() {
for (int i = -; i < ; i += ) {
double t = Math.Tan((double)i / * Math.PI);
double x = * (double)a * t / (t * t * t + );
double y = x * t;
CartesianFoliumSeries.Points.Add(new SeriesPoint(x, y));
}
}
void ShowSeries(Series visibleSeries) {
foreach (Series series in Series) {
if (series == visibleSeries) {
visibleSeries.Visible = true;
seriesSelected = series;
}
else
series.Visible = false;
}
}
void comboBoxEditFunctionType_SelectedIndexChanged(object sender, EventArgs e) {
if(comboBoxEditFunctionType.SelectedIndex == archimedianSpiralIndex) {
if (ArchimedianSpiralSeries.Points.Count == )
CreateArchimedianSpiralPoints();
ShowSeries(ArchimedianSpiralSeries);
}
else if(comboBoxEditFunctionType.SelectedIndex == cardioidIndex) {
if (CardioidSeries.Points.Count == )
CreateCardioidPoints();
ShowSeries(CardioidSeries);
}
else if(comboBoxEditFunctionType.SelectedIndex == cartesianFoliumIndex) {
if (CartesianFoliumSeries.Points.Count == )
CreateCartesianFoliumPoints();
ShowSeries(CartesianFoliumSeries);
}
}
protected override void InitControls() {
base.InitControls();
ShowLabels = false;
comboBoxEditFunctionType.SelectedIndex = archimedianSpiralIndex;
foreach (Series series in chart.Series)
series.ToolTipPointPattern = "{A:F2} : {V:F2}";
}
}
}
scatterLine
using System; namespace DevExpress.XtraCharts.Demos {
public partial class ChartDemoRealtimeChart : ChartDemoBase {
const int interval = ; static RegressionLine GetRegressionLine(Series series) {
if (series != null) {
SwiftPlotSeriesView swiftPlotView = series.View as SwiftPlotSeriesView;
if (swiftPlotView != null)
foreach (Indicator indicator in swiftPlotView.Indicators) {
RegressionLine regressionLine = indicator as RegressionLine;
if (regressionLine != null)
return regressionLine;
}
}
return null;
} Random random = new Random();
double value1 = 10.0;
double value2 = -10.0;
bool? inProcess = null; int TimeInterval { get { return Convert.ToInt32(spnTimeInterval.EditValue); } }
Series Series1 { get { return chart.Series.Count > ? chart.Series[] : null; } }
Series Series2 { get { return chart.Series.Count > ? chart.Series[] : null; } }
RegressionLine Regression1 { get { return GetRegressionLine(Series1); } }
RegressionLine Regression2 { get { return GetRegressionLine(Series2); } }
public override ChartControl ChartControl { get { return chart; } } public ChartDemoRealtimeChart() {
InitializeComponent();
}
void SetPauseResumeButtonText() {
btnPauseResume.Text = timer.Enabled ? "Pause" : "Resume";
}
double CalculateNextValue(double value) {
return value + (random.NextDouble() * 10.0 - 5.0);
}
void UpdateValues() {
value1 = CalculateNextValue(value1);
value2 = CalculateNextValue(value2);
}
void DisableProcess() {
inProcess = timer.Enabled;
timer.Enabled = false;
}
void RestoreProcess() {
if(inProcess != null) {
timer.Enabled = (bool)inProcess;
inProcess = null;
}
}
protected override void InitControls() {
base.InitControls();
timer.Interval = interval;
SetPauseResumeButtonText();
}
protected override void DoShow() {
base.DoShow();
RestoreProcess();
}
protected override void DoHide() {
base.DoHide();
DisableProcess();
}
void timer_Tick(object sender, EventArgs e) {
if (Series1 == null || Series2 == null)
return;
DateTime argument = DateTime.Now;
SeriesPoint[] pointsToUpdate1 = new SeriesPoint[interval];
SeriesPoint[] pointsToUpdate2 = new SeriesPoint[interval];
for (int i = ; i < interval; i++) {
pointsToUpdate1[i] = new SeriesPoint(argument, value1);
pointsToUpdate2[i] = new SeriesPoint(argument, value2);
argument = argument.AddMilliseconds();
UpdateValues();
}
DateTime minDate = argument.AddSeconds(-TimeInterval);
int pointsToRemoveCount = ;
foreach (SeriesPoint point in Series1.Points)
if (point.DateTimeArgument < minDate)
pointsToRemoveCount++;
if (pointsToRemoveCount < Series1.Points.Count)
pointsToRemoveCount--;
AddPoints(Series1, pointsToUpdate1);
AddPoints(Series2, pointsToUpdate2);
if (pointsToRemoveCount > ) {
Series1.Points.RemoveRange(, pointsToRemoveCount);
Series2.Points.RemoveRange(, pointsToRemoveCount);
}
SwiftPlotDiagram diagram = chart.Diagram as SwiftPlotDiagram;
if (diagram != null && (diagram.AxisX.DateTimeScaleOptions.MeasureUnit == DateTimeMeasureUnit.Millisecond || diagram.AxisX.DateTimeScaleOptions.ScaleMode == ScaleMode.Continuous))
diagram.AxisX.WholeRange.SetMinMaxValues(minDate, argument);
}
void AddPoints(Series series, SeriesPoint[] pointsToUpdate) {
if(series.View is SwiftPlotSeriesViewBase)
series.Points.AddRange(pointsToUpdate);
}
void btnPauseResume_Click(object sender, EventArgs e) {
timer.Enabled = !timer.Enabled;
SetPauseResumeButtonText();
}
void chRegression_CheckedChanged(object sender, EventArgs e) {
if(Regression1 != null)
Regression1.Visible = chRegression.Checked;
if(Regression2 != null)
Regression2.Visible = chRegression.Checked;
}
}
}
RealTime实时曲线
张奎师弟参与devexpress chartControl绘图--解决了devexpress的chartControl控件不能添加系列的问题的更多相关文章
-
在DevExpress程序中使用条形码二维码控件,以及进行报表打印处理
在很多业务系统里面,越来越多涉及到条形码.二维码的应用了,不管在Web界面还是WInform界面都需要处理很多物料相关的操作,甚至很多企业为了减少录入错误操作,为每个设备进行条形码.二维码的标签,直接 ...
-
WPF解决按钮上被透明控件遮盖时无法点击问题
原文:WPF解决按钮上被透明控件遮盖时无法点击问题 IsHitTestVisible="False" 在控件上设置如上属性即可,即可让透明控件不触发点击效果
-
记录下帮助一位网友解决的关于android子控件的onTouch或onClick和父OnTouch 冲突的问题。
前三天收到位网友的私信求助,问题大概如标题所示.具体是下面的情况,个人感觉,这个问题挺有趣,也会在实际项目开发中很常见.不想看前奏的请直接跳至解决方法. 问题原型: 父控件是自定义的 LinearLa ...
-
解决嵌入WinForm的WPF控件无法显示图片问题
解决办法是在控件初始化时,通过下面方法再次加载图片: ucCanvas.CreateCoordinateImage.Source = GetImageIcon(global::MainApplicat ...
-
解决UIScrollView,UIImageView等控件不能响应touch事件的问题
关于UIScrollView,UIImageView等控件不能响应touch事件,主要涉及到事件响应者链的问题,如果在UIScrollView,UIImageView等控件添加了子View,这样事件响 ...
-
解决WPF两个图片控件显示相同图片因线程占用,其中一个显示不全的问题
在做项目的过程中遇到这样一个问题,下面提出一种解决方法,主要思想是图片的Copy,如还有其他方法,欢迎交流. 在前端图片控件绑定显示时,使用转换器进行转义绑定 (1)转换器: public cla ...
-
解决bootstrap-table表头filter-control select控件被遮挡显示不全的问题
[本文出自天外归云的博客园] 在使用bootstrap-table的extension——filter-control时(对应表格的data-filter-control="true&quo ...
-
解决Jquery对input file控件的onchange事件只生效一次的问题
如题,解决办法的代码如下: 1. $('#fileId').live('change',function(){ //逻辑添加.... }); 2. $('#fileId').change(functi ...
-
解决easy ui 1.4datebox控件不能清空的问题
用easy ui遇到这个问题,在网上找到了解决方案,不过是1.3.6版本的.现提供1.4版本的修改的具体位置和代码. 我们用的是这个 修改位置:12739行,添加代码: , { text: funct ...
随机推荐
-
理解Docker(6):若干企业生产环境中的容器网络方案
本系列文章将介绍 Docker的相关知识: (1)Docker 安装及基本用法 (2)Docker 镜像 (3)Docker 容器的隔离性 - 使用 Linux namespace 隔离容器的运行环境 ...
-
修改hosts文件,修改后不生效怎么办
当你在打开浏览器的情况下修改hosts文件时,关闭浏览器时系统才会释放掉hosts文件占用的那部分内存,我们再次打开浏览器访问就发现已经生效了. ps:ipconfig /flushdns # ...
-
ABAP BDC
REPORT程序中用BDC录入 DATA: GS_BDC TYPE BDCDATA, GT_BDC TYPE TABLE OF BDCDATA, GS_MSG TYPE BDCMSGCOLL, GT_ ...
-
C# WinForm窗口最小化到系统托盘
* C# WinForm窗口最小化到系统托盘http://hi.baidu.com/kfxtgtqyapouyze/item/8ccfdcd5a174a7312a35c7c3 主要功能:(1).程序启 ...
-
java.lang.NumberFormatException错误及解决方法
java.lang.NumberFormatException 一般由Integer.valueOf(String param)或者Integer.parseInt(String param)引起 不 ...
-
Struts2中文件上传下载实例
1.单文件上传 jsp页面: <!-- 单文件上传 --> <form action="Fileupload.action" method="post& ...
-
nginx 番外----添加第三方模块
#第三方模块需要先进行下载,然后再编译时指定文件目录 1.查看当前编译模块 root@nginx sbin]# ./nginx -V #查看当前添加模块 nginx version: nginx/ b ...
-
mysql第二次安装失败的解决方法
1首先在控制面板中将名字与mysql有关的逐一的卸载. 2 然后找到mysql安装目录将mysql文件夹全部删掉,即使是空的文件夹也要删掉. 3打开C:\ProgramData,找到MySQL文件夹, ...
-
批量查询";_mget";
1.不同index的批量查询GET /_mget{ "docs":[{ "_index":"test_index1", "_typ ...
-
how to Use the Tampermonkey API from the Chrome console
1.Create the following script: // ==UserScript== // @name Exports some GM functions // @namespace Wh ...