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));
}
}
xValues
和yValues
是被整數的陣列。
我遇到的問題是,如果xValues = int[]{1,2,3}
,當chart_FormatNumber
處理事件時,值(e.Value
)更改爲{2,3,4}
。
所以必須做一個減法,使其成爲正確的值。
有人可以告訴我發生了什麼和/或如何阻止MSChart改變我的價值觀?
我測試了它,它在我的機器上正常工作。事實上,如果我刪除了小部件,標籤就會正確顯示。您應該發佈一個小而完整的示例來重現問題(如果單個帖子太長,請使用http://pastebin.com/) – digEmAll 2012-08-05 08:33:27
感謝您嘗試重現此問題。我能找到我的問題的原因。請參閱下面的答案。 – Anish 2012-08-05 15:43:13