Anish
Anish

Reputation: 3172

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?

Upvotes: 0

Views: 513

Answers (1)

Anish
Anish

Reputation: 3172

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.

Upvotes: 1

Related Questions