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?