C# 改变我的价值

C# 改变我的价值,c#,.net,charts,mschart,C#,.net,Charts,Mschart,我有一张MS图表。 我的代码如下: chart.Series[chartType].Points.DataBindXY(xValues, xCaption, yValues, yCaption); chart.ChartAreas[0].AxisX.LabelStyle.Format = "CustomAxisXFormat"; chart.FormatNumber += new EventHandler<FormatNumberEventArgs>(chart_FormatNumb

我有一张MS图表。 我的代码如下:

chart.Series[chartType].Points.DataBindXY(xValues, xCaption, yValues, yCaption);
chart.ChartAreas[0].AxisX.LabelStyle.Format = "CustomAxisXFormat";
chart.FormatNumber += new EventHandler<FormatNumberEventArgs>(chart_FormatNumber);
xvalue
yvalue
是整数数组。
我遇到的问题是,如果
xValues=int[]{1,2,3}
,当
chart\u FormatNumber
处理事件时,值(
e.Value
)将更改为
{2,3,4}

因此,必须在那里进行减法运算,使其成为正确的值。

有人能告诉我发生了什么和/或如何阻止MSChart更改我的值吗?

好的,经过一番深思熟虑后,我知道发生了什么。我提供的x参数是int。MS图表将+1和-1添加到x轴范围。我提供的x值是
xValues=int[]{1,2,3}
。在
chart\u FormatNumber()
中,我得到了
{0,1,2,3,4}
,这让我很生气。

我测试了它,它在我的机器上运行良好。事实上,如果我移除Subtraction,标签会正确显示。您应该发布一个小但完整的示例来重现问题(如果单个帖子太长,请使用),感谢您尝试重现此问题。我能够找到我的问题的原因。见下面我的答案。
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));
    }
}