C#Excel图表与自定义X轴 [英] C# Excel Chart with custom X-Axis

查看:1053
本文介绍了C#Excel图表与自定义X轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自两列的图表。在列A中是一些结果%值,并且在B中有对应的值的名称。

i have a chart from two columns. In Column A are some result % values and in B i have the corresponding Name to the value.

A   B   
90  Test1   
82  Test2   
66  Test3 

我希望A值为Y轴并已经管理,但我不能得到从B到X轴标签的名称。

I want the A values as Y axis and already managed that, but i can´t get the names from B to the X-Axis labels.

Range chartRange;
Worksheet xlWorkSheet = (Worksheet)xlWorkBook.Worksheets[1];

ChartObjects xlCharts = (ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
ChartObject myChart = (ChartObject)xlCharts.Add(10, 80, 300, 250);
Chart chartPage = myChart.Chart;

chartRange = xlWorkSheet.get_Range("A1:B"+movieCount.ToString(), Type.Missing);
chartPage.SetSourceData(chartRange, misValue);
chartPage.ChartType = XlChartType.xlColumnClustered;


推荐答案

您必须适应这些设置,否则您的xvalues将只是一个计数:

You will have to adapt to these settings, otherwise your xvalues will be just a count:

 chartPage.SetSourceData Range("A2:A4"), xlRows
 chartPage.SeriesCollection(1).XValues = Range("B2:B4")

 chartPage.SetSourceData Range("A2:A4"), xlColumns
 chartPage.SeriesCollection(1).XValues = Range("B2:B4")

maby有另一种方式,但作为一个快速的解决方案,这将工作在VBA - 所以它也应该,当你适应它的C#版本。

maby there is a another way, but as a quick solution, this would work in VBA - so it should too, when you adapt it to your C# version.

这篇关于C#Excel图表与自定义X轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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