ZedGraph⿏标悬停
C# code
private void 曲线图_Load(object sender, EventArgs e)
{
myPane.Title.Text = "测试";
myPane.XAxis.Title.Text = "时间";
myPane.YAxis.Title.Text = "温度";
myPane.XAxis.MajorGrid.IsVisible = true;
myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f);
TextObj text = new TextObj(
"缩放:⿏标滚轮\n移动:⿏标中键\n菜单:⿏标右键",
0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom);
text.FontSpec.StringAlignment = StringAlignment.Near;
myPane.GraphObjList.Add(text);
zg1.IsShowHScrollBar = true;
zg1.IsShowVScrollBar = true;
zg1.IsAutoScrollRange = true;
zg1.IsScrollY2 = true;
zg1.IsShowPointValues = true; //⿏标悬停提⽰
string[] labelsy = { "0", "10", "20", "30", "40" };
myPane.YAxis.Scale.TextLabels = labelsy;
myPane.YAxis.MajorGrid.IsVisible = true;
myPane.YAxis.MinorGrid.IsVisible = true;
myPane.YAxis.MajorTic.IsBetweenLabels = false;
//⼿动添加⿏标悬停节点事件
zg1.PointValueEvent += new ZedGraphControl.PointValueHandler(MyPointValueHandler);
zg1.GraphPane.YAxis.ScaleFormatEvent += new Axis.ScaleFormatHandler(YScaleFormatEvent);
}
//⿏标悬停节点事件
private string MyPointValueHandler(ZedGraphControl sender, GraphPane pane, CurveItem curve, int iPt) {
PointPair pt = curve[iPt];
panereturn www.doczj/doc/a118026785.html
bel.Text + "是" + pt.Y.ToString("f1") + "° \n时间是" + pt.X.ToString() + "";
}
private void button4_Click(object sender, EventArgs e)
{
string sql = "select H_dataTime,s_4 from HistoryLog"; DataTable dt = SqlDbHelper.Query(sql).Tables[0]; DataRowCollection dr = dt.Rows;
int count = dt.Rows.Count;
for (int i = 0; i < count; i++)
{
double x = (double)new XDate(DateTime.Parse(dr[i][0].ToString())); double y = double.Parse(dr[i][1].ToString());
list.Add(x, y);
}
LineItem myCurve = myPane.AddCurve("温度",
list, Color.Red, SymbolType.Diamond);
myPane.XAxis.Type = AxisType.Date;
myPane.XAxis.Scale.FontSpec.Angle = 15;
zg1.AxisChange();
zg1.Refresh();
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。