在圖的節點處,我想顯示節點的細節。
我把X軸上的提示信息改成了時間格式。
當鼠標懸停時,顯示的內容會發生變化。pt的值。ToString()是壹長串十進制值。
這裏是所有的鼠標操作技巧。
如果您仍然不明白,請打開事件面板。
壹個接壹個。下面有中文解釋。
C#代碼
私有void graph _Load(對象發送方,EventArgs e)
{
我的窗格。Title . Text = " test
我的窗格。XAxis . Title.Text = " time
我的窗格。YAxis . title . text = " temperature ";
我的窗格。XAxis . major grid . is visible = true;
我的窗格。Chart.Fill =新填充(顏色。白色,彩色。淺灰色,45.0 f);
TextObj text = new TextObj(
"縮放:鼠標滾輪\ n移動:鼠標中鍵\ n菜單:鼠標右鍵",
0.05f,0.95f,坐標類型。圖表分數,阿利根。左,阿利根夫。底部);
文字。font spec . string alignment = string alignment。近;
我的窗格。GraphObjList.Add(文本);
zg1。IsShowHScrollBar = true
zg1。IsShowVScrollBar = true
zg1。IsAutoScrollRange = true
zg1。IsScrollY2 = true
zg1。IsShowPointValues = true//鼠標懸停提示
string[] labelsy = { "0 "," 10 "," 20 "," 30 "," 40 " };
我的窗格。YAxis . scale . text labels = labelsy;
我的窗格。ya xis . major grid . is visible = true;
我的窗格。ya xis . minor grid . is visible = true;
我的窗格。ya xis . major TIC . is between labels = false;
//手動添加鼠標懸停節點事件。
zg1。PointValueEvent +=新ZedGraphControl。PointValueHandler(MyPointValueHandler);
zg1。graph pane . ya xis . scaleformatevent+=新坐標軸。ScaleFormatHandler(YScaleFormatEvent);
}
//鼠標懸停節點事件
私有字符串MyPointValueHandler(ZedGraphControl發送方,GraphPane窗格,CurveItem曲線,int iPt)
{
點對pt =曲線[iPt];
返回曲線。Label.Text+"是"+pt . y . tostring(" f 1 ")+" \ n time是"+pt。x . ToString()+" ";
}
私有void按鈕4_Click(對象發送方,EventArgs e)
{
string sql = "select H_dataTime,s _ 4 from history log ";
數據表dt = SqlDbHelper。查詢(sql)。表[0];
DataRowCollection dr = dt。行;
int計數= dt。行數。計數;
for(int I = 0;我& lt數數;i++)
{
double x =(double)new XDate(DateTime。Parse(dr[i][0]。ToString()));
雙y =雙。Parse(dr[i][1]。ToString());
列表。Add(x,y);
}
Lineitem mycurve = mypane。addcurve("溫度",
列表,顏色。紅色,符號類型。鉆石);
我的窗格。XAxis.Type = AxisType。日期;
我的窗格。XAxis . scale . font spec . angle = 15;
zg1。axis change();
zg1。刷新();
}