发布:2024/5/5 22:03:36作者:管理员 来源:本站 浏览次数:312
DevExpress ChartControl折线图简单使用
1、界面放一个panel控件
2、定义一个DataTable 存储数据
3、获取数据后放在DataTable
DataTable 定义:
DataTable res_data = new DataTable();
res_data.Columns.Add(“id”, Type.GetType(“System.Int32”));
res_data.Columns.Add(“ljbh”, Type.GetType(“System.String”));
res_data.Columns.Add(“sbbh”, Type.GetType(“System.String”));
res_data.Columns.Add(“cpxh”, Type.GetType(“System.String”));
res_data.Columns.Add(“qb”, Type.GetType(“System.String”));
res_data.Columns.Add(“chazhi”, Type.GetType(“System.Double”));
res_data.Columns.Add(“chazhi_lilun”, Type.GetType(“System.Double”));
res_data.Columns.Add(“rq”, Type.GetType(“System.String”));
//由于数据中的日期颗粒度太粗,所以有可能存在重复的,重复的devexpress控件会自动取平均值,不符合我的要求。所以我把X坐标修改为ID数值了。
private void display_Line()
{
ChartControl lineChart = new ChartControl();
Series series1 = new Series("差值趋势图", ViewType.Line);
ArrayList al_scz1 = new ArrayList();
for (int i = 0; i < res_data.Rows.Count; i++)
{
al_scz1.Add(Convert.ToDouble(res_data.Rows[i]["chazhi"].ToString()));
}
al_scz1.Sort();
double tenp = Convert.ToDouble(al_scz1[al_scz1.Count - 1].ToString());
double max_scz1 = tenp < 0 ? tenp / 3 : tenp * 3;
double min_scz1 = Convert.ToDouble(al_scz1[0].ToString()) * 3;
for (int i = 0; i < res_data.Rows.Count; i++)
{
//DateTime aa = Convert.ToDateTime(res_data.Rows[i]["rq"].ToString());
int aa = Convert.ToInt32(res_data.Rows[i]["id"].ToString());
string scz1 = res_data.Rows[i]["chazhi"].ToString();
series1.Points.Add(new SeriesPoint(aa, scz1));
}
lineChart.Series.Add(series1);
series1.ArgumentScaleType = ScaleType.Numerical;
AxisRange DIA = (AxisRange)((XYDiagram)lineChart.Diagram).AxisY.Range;
XYDiagram diagram = (XYDiagram)lineChart.Diagram;
diagram.AxisX.Title.Alignment = StringAlignment.Center;
diagram.AxisX.Title.Text = "加工时间";
diagram.AxisX.Title.Font = new Font("Tahoma", 14, FontStyle.Bold);
DIA.SetMinMaxValues(min_scz1, max_scz1);
diagram.AxisY.Title.Alignment = StringAlignment.Center;
diagram.AxisY.Title.Text = "标准坐标和实际坐标差值";
diagram.AxisY.Title.Font = new Font("Tahoma", 14, FontStyle.Bold);
((XYDiagram)lineChart.Diagram).EnableAxisXZooming = true;
lineChart.Titles.Add(new ChartTitle());
lineChart.Titles[0].Text = "实际差值趋势图";
lineChart.Dock = DockStyle.Fill;
lineChart.Refresh();
this.panel1.Controls.Add(lineChart);
}
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4