格式化Microsoft Chart Control X轴子类别的标签与Excel中生成的图表类似

时间:2023-01-27 20:24:37

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

我试图通过使用.Net的Microsoft图表控件复制已在Microsoft Excel 2007中生成的图表时遇到问题

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

该图表显示了当年每月的前5个条目(每个月可能有不同的5个条目),然后显示某些指标的细分

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 Chart Control X轴子类别的标签与Excel中生成的图表类似 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.

我可以完美地获得数据,问题归结为这样一个事实:在Excel图表中它已经格式化了X轴标签,如下图所示:我们希望轴的格式如何,以便每个月的名称只是对于该月的5个子类别列出一次。

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 X轴子类别的标签与Excel中生成的图表类似 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.

但是我不知道如何使用Microsoft Chart Control重现这一点,当我使用相同的数据进行图表控制时,它将X轴格式化为(忽略颜色等):我绑定了数据,以便XAxis值为“1月AAA-BBB”,我想我可能需要将Month部分分成另一个可以单独格式化/分组的轴值。

Any help would be appreciated.

任何帮助,将不胜感激。

1 个解决方案

#1


8  

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

我设法使用一系列CustomLabel,我手动定位在正确的“部分”下。

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

#1


8  

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

我设法使用一系列CustomLabel,我手动定位在正确的“部分”下。

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