您的位置:首页 > 编程语言 > C#

ZedGraph图表控件 X轴显示时间 C#

2013-08-23 15:08 761 查看
private void CreateGraph(ZedGraphControl
zgc)


{


//zgc.Controls.Clear();


GraphPane myPane = zgc.GraphPane;

//添加新的控件前先将面板上已经存在的控件清除。


myPane.CurveList.Clear();


myPane.GraphObjList.Clear();
// Set the titles and axis labels


myPane.Title.Text = "指数趋势";


myPane.XAxis.Title.Text = "序号";


myPane.YAxis.Title.Text = "指数";


DateTime dt;


String[] szx = new String[dataGridView3.RowCount];//X轴的日期数组


Double[] szy = new Double[dataGridView3.RowCount];//Y轴的数据数组


for (int i = 0; i < dataGridView3.RowCount;
i++)


{


//list.Add(i, Convert.ToDouble(dataGridView3[2,
i].Value.ToString()));


dt = (DateTime)dataGridView3[3,i].Value;


szx[i] = dt.ToString("MM-dd hh:mm:ss");//按照02-29 18:00:00显示


szy[i] = Convert.ToDouble(dataGridView3[2,
i].Value.ToString());


}


myPane.XAxis.Type = AxisType.Text;




// Generate a blue curve with circle symbols, and "My Curve 2" in
the legend

//添加X轴、Y轴的数据到面板上,但是由于AddCurve方法没有匹配的参数,所以第二个X轴想显示
//时间数据时,要先设置为null,然后在下面单独添加。


LineItem myCurve = myPane.AddCurve("指数", null, szy, Color.Blue,
SymbolType.Circle);


myPane.XAxis.Scale.TextLabels = szx;//添加日期到X轴


// Fill the area under the curve with a white-red gradient at 45
degrees


myCurve.Line.Fill = new Fill(Color.White, Color.White, 45F);


// Make the symbols opaque by filling them with white


myCurve.Symbol.Fill = new Fill(Color.White);


// Fill the axis background with a color gradient


myPane.Chart.Fill = new Fill(Color.White,
Color.LightGoldenrodYellow, 45F);


// Fill the pane background with a color gradient


myPane.Fill = new Fill(Color.White, Color.FromArgb(220, 220, 255),
45F);


// Calculate the Axis Scale Ranges


zgc.AxisChange();


zgc.Refresh();


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: