我在尝试使用 Microsoft Chart Control for .Net 复制在 Microsoft Excel 2007 中生成的图表时遇到问题
图表显示了一年中每个月的前 5 个条目(每个月可能有不同的 5 个条目),然后显示了一些指标的分割
我可以完美地获取数据,问题归结为在 Excel 图表中它已格式化 X 轴标签,如下图所示: 这就是我们希望对轴进行格式化的方式,以便每个月份名称仅针对该月的 5 个子类别列出一次。
但我不知道如何使用 Microsoft 图表控件重现这一点,当我对图表控件使用相同的数据时,它会将 X 轴格式化为(忽略颜色等): 我绑定(bind)了数据,以便 XAxis 值为“January AAA-BBB”,我想我可能需要将月份部分分离到其他一些可以单独格式化/分组的轴值中。
如有任何帮助,我们将不胜感激。
最佳答案
我已经设法使用了一系列 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"
}
关于c# - 将子类别的 Microsoft Chart Control X 轴标签格式化为类似于 Excel 中生成的图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4858734/