2012-07-11 96 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}這是拋棄我。