Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting chart axis labels

Tags:

c#

mschart

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.

like image 671
SlimPDX Avatar asked Aug 02 '13 20:08

SlimPDX


People also ask

How do I change the vertical axis labels in Excel?

Add or change the position of vertical axis label Click the chart, and then click the Chart Layout tab. Under Axes, click Axes > Vertical Axis, and then click the kind of axis label that you want.


1 Answers

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")

like image 198
DasKrümelmonster Avatar answered Sep 18 '22 14:09

DasKrümelmonster