繁体   English   中英

从C#恢复图表的X和Y轴

[英]Reverting X and Y axes of a chart from C#

我正在根据词典值创建折线图。 键是长日期时间字符串,值是双精度值。 所以excel看起来像这样:

3.41上午9:22:39

上午9:22:40 3.91

上午9:22:41 7.81

上午9:22:42 2.44

1.56:9:22:43

创建图表时,时间在Y轴上,而双精度值在X轴上。 我希望将double用作Y轴并将X轴作为时间。

Excel.ChartObjects xlCharts = (Excel.ChartObjects)newWorkSheet.ChartObjects(Type.Missing);
Excel.ChartObject chart = (Excel.ChartObject)xlCharts.Add(10, 80, 300,250);             
Excel.Chart chartPage = chart.Chart;

Excel.Range chartRange = newWorkSheet.get_Range("B1", "A" + row);
chartPage.SetSourceData(chartRange, Type.Missing);
chartPage.ChartType = Excel.XlChartType.xlLine;
chartPage.HasLegend = false;

在SetSourceData中,我尝试同时使用列和行(第二个参数),但是并不能解决问题。 任何想法我该如何解决?

假设时间为B1:B5 ,双精度值为A1:A5 ,请尝试以下代码。

Excel.ChartObjects xlCharts = (Excel.ChartObjects)newWorkSheet.ChartObjects(Type.Missing);
Excel.ChartObject chart = (Excel.ChartObject)xlCharts.Add(10, 80, 300,250);             
Excel.Chart chartPage = chart.Chart;

Excel.Range chartRange = newWorkSheet.get_Range("A1:A5");
chartPage.SetSourceData(chartRange, Type.Missing);
chartPage.ChartType = Excel.XlChartType.xlLine;
chartPage.HasLegend = false;

Series series = (Series)(chart.Chart.SeriesCollection(1));
series.XValues = newWorkSheet.get_Range("B1:B5");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM