2012-07-11 92 views
0

我有一个MS图表。 我的代码如下:MSChart改变我的价值

chart.Series[chartType].Points.DataBindXY(xValues, xCaption, yValues, yCaption); 
chart.ChartAreas[0].AxisX.LabelStyle.Format = "CustomAxisXFormat"; 
chart.FormatNumber += new EventHandler<FormatNumberEventArgs>(chart_FormatNumber); 

然后

private void chart_FormatNumber(object sender, FormatNumberEventArgs e) 
{ 
    if (e.ElementType == ChartElementType.AxisLabels && 
     e.Format == "CustomAxisXFormat") 
    { 
     e.LocalizedValue = string.Format("{0:hh tt}", new DateTime(1, 1, 2, (int)e.Value, 0, 0).AddHours(-1)); 
    } 
} 

xValuesyValues是被整数的阵列。
我遇到的问题是,如果xValues = int[]{1,2,3},当chart_FormatNumber处理事件时,值(e.Value)更改为{2,3,4}
所以必须做一个减法,使其成为正确的值。
有人可以告诉我发生了什么和/或如何阻止MSChart改变我的价值观?

+0

我测试了它,它在我的机器上正常工作。事实上,如果我删除了小部件,标签就会正确显示。您应该发布一个小而完整的示例来重现问题(如果单个帖子太长,请使用http://pastebin.com/) – digEmAll 2012-08-05 08:33:27

+0

感谢您尝试重现此问题。我能找到我的问题的原因。请参阅下面的答案。 – Anish 2012-08-05 15:43:13

回答

1

好的,在一些头部划伤之后,我想清楚发生了什么事。我供应我的x参数是int。 MS图表在x轴范围内添加+1和-1。我提供的x值是xValues = int[]{1,2,3}。在chart_FormatNumber()我得到了{0,1,2,3,4}这是抛弃我。