格式化Microsoft图表控件X子类别的轴标签类似于在Excel中生成的图表 [英] Formatting Microsoft Chart Control X Axis labels for sub-categories to be like charts generated in Excel

查看:1742
本文介绍了格式化Microsoft图表控件X子类别的轴标签类似于在Excel中生成的图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到问题,尝试复制在Microsoft Excel 2007中生成的图表使用Microsoft图表控件for .NET

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

图表显示的是TOP每年的5个条目(每个月可以有不同的5条目),然后显示一些指标的细目

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

我可以获得数据完美,问题归结为这样的事实,在Excel图表中它已格式化X轴标签如下图所示:

这是我们如何设置轴格式,以便每个月的名称只列出该月份的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: 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.

但是我不知道如何使用Microsoft图表控件重现这个,当我使用相同的数据为图表控件它格式化X轴为(忽略颜色等):

我绑定了数据,使XAxis值为January AAA-BBB ,我想我也许需要将月份部分分成一些其他轴值,可以单独格式化/分组。

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): 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.

推荐答案

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

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

这篇关于格式化Microsoft图表控件X子类别的轴标签类似于在Excel中生成的图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆