简体   繁体   English

MSChart改变了我的价值

[英]MSChart changing my value

I have an MS Chart. 我有一张MS图表。 My code is the following: 我的代码如下:

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

Then 然后

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 and yValues are are arrays of ints. xValuesyValues是整数数组。
The problem I am having is, if xValues = int[]{1,2,3} , when chart_FormatNumber handles the event, the values ( e.Value ) change to {2,3,4} . 我遇到的问题是,如果xValues = int[]{1,2,3} ,则在chart_FormatNumber处理事件时,值( e.Value )更改为{2,3,4}
So have to do a subtraction there to make it the correct value. 因此,必须在其中进行减法以使其具有正确的值。
Can somebody tell me what is going on and/or how to stop MSChart from changing my values? 有人可以告诉我发生了什么事和/或如何阻止MSChart更改我的值吗?

Ok, after some head scratching, I figured out what was happening. 好吧,在挠头之后,我弄清楚了发生了什么。 I was supplying my x parameters are int. 我提供的x参数是int。 MS chart was adding +1 and -1 to the x axis range. MS图表在x轴范围内添加了+1和-1。 The x values I was providing was xValues = int[]{1,2,3} . 我提供的x值是xValues = int[]{1,2,3} In chart_FormatNumber() I was getting {0,1,2,3,4} which was throwing me off. chart_FormatNumber()我得到{0,1,2,3,4} ,这使我失望。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM