I want to replace numbers (1, 2, 3, ...) on the X Axis of the chart with the corresponding month name.
This is my actual chart:
On the DataView
that populates the Series
I have the "MONTH" column that contains values from 1 to 12.
I also had to manually set the Minimum
and Maximum
value to 0 and 13, otherwise I lose the first and last column because of a lack of space between the beginning of the first X Axis column and the Y Axis and between the last X Axis column end of Chart area.
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisX IsStartedFromZero="True" Title="Mese"
TitleFont="Segoe UI, 10pt, style=Bold" IsLabelAutoFit="False" LineColor="Gray"
Minimum="0" Maximum="13">
<MajorGrid LineColor="LightGray" />
<LabelStyle Font="Segoe UI, 9pt" />
</AxisX>
</asp:ChartArea>
</ChartAreas>
So, if I replace the int values with month names I also need to remove the Min and Max parameters, but I want to keep the space like it is now.
I tried with some solutions suggested here and elsewhere but with no results. The easiest, most effective and immediate seemed to be this:
Chart1.ChartAreas[0].AxisX.LabelStyle.Format = "MMM";
but it doesn't work. Instead I get "MMM" string in place of the integer values.
Is it possible to intercept the DataBind
event like on a GridView, to replace the integer values with month names?