25

In ASP.NET Column Chart, when the chart size is small some axis labels are not shown.

Question: How can I force all the label to show even if they have to overlap?

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
Y2theZ
  • 10,162
  • 38
  • 131
  • 200
  • Can you quickly give a background for the problem – V4Vendetta Sep 27 '11 at 09:39
  • Hi, I am drawing a column chart using ASP.NET charting. I have 10 points to draw. the width of the chart is 300px. The axis label of some points is not showing due to the lack of space. I was wondering if I can force it to show even if there is not enough space. Thanks. Hope I was clear – Y2theZ Sep 27 '11 at 09:45
  • Try setting the `Interval` property to 1, this should force it to show the labels – V4Vendetta Sep 27 '11 at 09:47
  • Yes, Thank you very much. Add it as an answer so I can Accept it. – Y2theZ Sep 27 '11 at 10:43
  • To make it more clear ` chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1;` – NoWar Oct 06 '17 at 03:45

1 Answers1

52

Set the Interval property for the Axis to 1, this will enforce it to display all the available labels irrespective of the space limitation.

V4Vendetta
  • 37,194
  • 9
  • 78
  • 82
  • 10
    Great tip, +1. For those arriving by Google like me, Interval can be found at `ChartAreaID.AxisX.LabelStyle.Interval=1` or at `ChartID.Areas("myChartAreaName").AxisX.LabelStyle.Interval=1` – EvilDr Feb 07 '13 at 10:05
  • 4
    or even here... ' – EvilDr Feb 07 '13 at 10:08
  • 2
    Those coming here looking for a MVC solution: http://stackoverflow.com/questions/8703049/set-interval-in-chart-net-mvc3 – mxmissile Aug 29 '13 at 14:30
  • 1
    This answer has its limitations. If you interval=1 it will display a label even when no data exists. i.e. If you have a date range as an x-axis it will interval the dates by 1 day even though the day doesn't exist. – Joe Stellato Oct 01 '14 at 14:08
  • 8
    Another place it can found is `chart.ChartAreas[0].AxisX.LabelStyle.Interval = 1;` if you have added a chart are using `chart.ChartAreas.Add(new ChartArea());` – Mark_Gibson Jun 26 '15 at 08:32
  • If this does not work, set the axis major tick mark interval to 1 as well. See here: "The Interval property of a major tick mark, grid line or label of the axis has priority over the Interval property setting of the Axis object." https://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.axis.interval(v=vs.110).aspx – Rob Sep 23 '16 at 14:24
  • 1
    @EvilDr, your comment helps, after adding '.LabelStyle.' then it works, previously i was just '.AxisY.Internal', which does not do anything without Prefix .LabelStyle.' – visual Aug 04 '17 at 03:34