Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting Microsoft Chart Control X Axis labels for sub-categories to be like charts generated in Excel

I am having issues attempting to replicate a chart that has been generated in Microsoft Excel 2007 by using the Microsoft Chart Control for .Net

The chart is showing the TOP 5 entries for each Month (each month could have a different 5 entries) of the year and then showing a breakdown of some metrics

I can get the data perfectly fine, the issue comes down to the fact that in the Excel chart it has formatted the X-Axis labels as shown in the following image: Microsoft Excel 2007 Chart Which is how we want the axis formatted so that each Month name is only listed once for the 5 sub categories that are for that month.

But I do not know how to reproduce this using the Microsoft Chart Control, when I use the same data for the chart control it formats the X-Axis as (ignore colors and such): Microsoft Chart Control version I have bound the data so that the XAxis value is "January AAA-BBB", I'm thinking that maybe I need to separate out the Month portion into some other axis value that can be formatted/grouped separately.

Any help would be appreciated.

like image 640
Kyro Avatar asked Feb 01 '11 03:02

Kyro


People also ask

How do I create an X-axis category in Excel?

From the Design tab, Data group, select Select Data. In the dialog box under Horizontal (Category) Axis Labels, click Edit. In the Axis label range enter the cell references for the x-axis or use the mouse to select the range, click OK. Click OK.


1 Answers

I have managed to use a series of CustomLabel's that I manually position to be under the correct "sections".

foreach (string monthName in monthNames)
{
    CustomLabel monthLabel = new CustomLabel(startOffset, endOffset, monthName, 1,     LabelMarkStyle.Box);
    theChart.ChartAreas["Default"].AxisX.CustomLabels.Add(monthLabel);
    //increment startOffset and endOffset enough to position the next label
    //under the correct "section"
}
like image 158
Kyro Avatar answered Nov 02 '22 23:11

Kyro