zedgraphcontrol显示Y轴对应点数值,急求啊!

wenchuan408 2014-11-06 02:05:58

如上图为什么那条曲线,上每个点不显示Y轴的值啊,代码如下
GraphPane myPane = zgc.GraphPane;

// Set the titles and axis labels
myPane.Title.Text = "最近10个月的汇率趋势";
myPane.XAxis.Title.Text = "日期";
myPane.YAxis.Title.Text = "汇率";
myPane.XAxis.Title.IsVisible = false;
myPane.YAxis.Title.IsVisible = false;
myPane.XAxis.MajorGrid.IsVisible = true; //珊格子
myPane.YAxis.MajorGrid.IsVisible = true;

Double[] y = new Double[10];
string[] x = new string[10];

string cmdstr2 = "SELECT TOP 10 [汇率日期],[汇率单价] FROM [Process Cost].[dbo].[汇率List] order by [添加日期] desc";
SqlConnection con2 = new SqlConnection(connstr);
con2.Open();
SqlDataAdapter dap2 = new SqlDataAdapter(cmdstr2, con2);
DataSet ds2 = new DataSet();
dap2.Fill(ds2);
if (ds2.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds2.Tables[0].Rows.Count; i++)
{
y[i] = Convert.ToDouble(ds2.Tables[0].Rows[i][1].ToString());
x[i] = ds2.Tables[0].Rows[i][0].ToString();
}
}
con2.Close();
con2.Dispose();

// Hide the legend
myPane.Legend.IsVisible = true;

// Add a curve
LineItem curve = myPane.AddCurve("汇率走势图", null, y, Color.Red, SymbolType.Diamond);
curve.Line.Width = 2.0F;
curve.Line.IsAntiAlias = true;
curve.Symbol.Fill = new Fill(Color.White);
curve.Symbol.Size = 12;

// Fill the axis background with a gradient
myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, Color.ForestGreen), 45.0F);

// Offset Y space between point and label
// NOTE: This offset is in Y scale units, so it depends on your actual data
const double offset = 1.0;

// Loop to add text labels to the points
for (int i = 0; i < y.Length; i++)
{
// Get the pointpair
PointPair pt = curve.Points[i];

// Create a text label from the Y data value
TextObj text = new TextObj(pt.Y.ToString(""), pt.X, pt.Y + offset, CoordType.AxisXYScale, AlignH.Left, AlignV.Center);
text.ZOrder = ZOrder.A_InFront;

// Hide the border and the fill
text.FontSpec.Border.IsVisible = false;
text.FontSpec.Fill.IsVisible = false;
//text.FontSpec.Fill = new Fill( Color.FromArgb( 100, Color.White ) );
// Rotate the text to 90 degrees
text.FontSpec.Angle = 60; //字体倾斜度
myPane.GraphObjList.Add(text);
}

myPane.BarSettings.Type = BarType.SortedOverlay;
// Leave some extra space on top for the labels to fit within the chart rect
//myPane.YAxis.Scale.MaxGrace = 0.2;

myPane.XAxis.Type = AxisType.Text;
myPane.XAxis.Scale.TextLabels = x;
myPane.XAxis.Scale.FontSpec.Size = 13; //x线字体
myPane.XAxis.Scale.FontSpec.Angle = 60;//x线字体倾斜度
// Calculate the Axis Scale Ranges
zgc.AxisChange();

这个红色标记部分,就是循环获取每个点的值,代码没错啊,就是实际效果图死活不显示,为什么啊???
...全文
390 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
独孤侠客 2014-11-06
  • 打赏
  • 举报
回复
记得。net有个chart控件很方便来着,这个没用过。。。
wenchuan408 2014-11-06
  • 打赏
  • 举报
回复
能不能直接让他显示出来啊,不用用鼠标移到线上,才显示!
xian_wwq 2014-11-06
  • 打赏
  • 举报
回复
zedgraph的右键菜单中有“显示节点数据” 这样鼠标移到线上就可以显示数据了

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧