Formatting chart axis labels

SlimPDX picture SlimPDX · Aug 2, 2013 · Viewed 56.8k times · Source

I'm making some charts in C# Visual Studio 2010 and I had a quick (hopefully simple) question about formatting the labels on the X-Axis. I searched SO and Google for an answer and I'm pretty sure it has to do with simply editing the LabelStyle.Format for a chart area... But I can't figure it out! Okay, too much information, let me get on with the question

In short, my chart needs to have mileage on the x-axis and it ranges from 0 to 240,000. I would really like to spruce it up a bit and have a 'K' instead of the trailing 3 zeroes. Example: 60K, 120k, 180K, 240K.

Answer

DasKrümelmonster picture DasKrümelmonster · Aug 2, 2013

Set the LabelStyle.Format property accordingly:

chart1.ChartAreas[0].AxisX.LabelStyle.Format = "{0:0,}K";

Documentation is here: http://msdn.microsoft.com/en-us/library/0c899ak8.aspx (Section: "The ',' Custom Specifier")