简体   繁体   中英

MSChart changing my value

I have an MS Chart. 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.
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} .
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?

Ok, after some head scratching, I figured out what was happening. I was supplying my x parameters are int. MS chart was adding +1 and -1 to the x axis range. The x values I was providing was xValues = int[]{1,2,3} . In chart_FormatNumber() I was getting {0,1,2,3,4} which was throwing me off.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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