2个回答
展开全部
我在c# winform项目中用到ZedGraph做曲线图,
在曲线图的节点,我要显示节点的详细信息。
我把X轴的提示信息改成时间格式,
鼠标悬停时显示的内容就变了pt.X.ToString()的值就是一串很长的小数值
这里有所有鼠标的动作提示。
如果还不明白就打开事件面板。
一个一个的看。下面有中文解释的。
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 = ;
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];
return curve.Label.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();
}
在曲线图的节点,我要显示节点的详细信息。
我把X轴的提示信息改成时间格式,
鼠标悬停时显示的内容就变了pt.X.ToString()的值就是一串很长的小数值
这里有所有鼠标的动作提示。
如果还不明白就打开事件面板。
一个一个的看。下面有中文解释的。
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 = ;
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];
return curve.Label.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();
}
2011-05-06
展开全部
我帮你吧
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询