我有一个有日期和数据的表。导出列表时,其数据显示为
11/1/10|1
11/2/10|2
11/3/10|16
我只是想根据这些数据创建一个折线图,但是当我看到它是否被绘制时,图形永远不会被绘制,也有办法将x轴从0-100编号更改为日期列出了吗?
private void CreateGraph_DataSource(ZedGraphControl zedGraphControl1)
{
string project = listBox1.SelectedItem.ToString();
string sql = "select date,datasize from dbo.x where project = '"+project+"' order by date";
DataTable projects = null;
SqlDataAdapter dataadapt = null;
SqlConnection con = new SqlConnection("Data Source= W ;Initial Catalog= ding;Integrated Security= SSPI");
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
cmd.ExecuteNonQuery();
projects = new DataTable();
dataadapt = new SqlDataAdapter(cmd);
dataadapt.Fill(projects);
con.Close();
GraphPane myPane = zedGraphControl1.GraphPane;
myPane.Title.Text = project;
myPane.YAxis.Title.Text = "Size";
myPane.XAxis.Title.Text = "Date";
DataSourcePointList dsp = new DataSourcePointList();
dsp.DataSource = projects;
dsp.XDataMember = "Date";
dsp.YDataMember = "DataSize";
LineItem myCurve = myPane.AddCurve("DataSize", dsp, Color.DarkViolet);
myCurve.Line.Fill = new Fill(Color.Red, Color.White);
LineItem myCurve2 = myPane.AddCurve("Date", dsp, Color.DarkViolet);
myCurve2.Line.Fill = new Fill(Color.Green, Color.White);
myCurve.Line.Width = 2.0F;
myCurve2.Line.Width = 2.0F;
zedGraphControl1.AxisChange();
myPane.XAxis.Type = AxisType.Date;
}
编辑:
很抱歉,它看起来似乎是图形,但缩放非常糟糕,有没有办法将缩放设置为开始?
解决。
答案 0 :(得分:1)
您需要告诉ZedGraph轴是日期类型:
myPane.XAxis.Type = AxisType.Date;
虽然它没有使用DataSource,但使用Date Axis Type时有tutorial。