i'm creating a line chart from a dictionary values. Key is a long date time string and the value is a double value. So excel looks something like this:
我正在从字典值创建折线图。 Key是一个长日期时间字符串,值是一个double值。所以excel看起来像这样:
9:22:39 AM 3.41
上午9:22:39 3.41
9:22:40 AM 3.91
上午9:22:40 3.91
9:22:41 AM 7.81
上午9:22:41 7.81
9:22:42 AM 2.44
上午9:22:42 2.44
9:22:43 AM 1.56
上午9:22:43 1.56
When I create the chart, time is on the Y axis and double values on the X axis. I want doubles to be the Y axis and time the X axis.
创建图表时,时间位于Y轴上,倍数值位于X轴上。我希望双精度数为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;
In SetSourceData I tried both using columns and rows (the second argument), however it doesn't solve the problem. Any ideas how can I fix this?
在SetSourceData中,我尝试了使用列和行(第二个参数),但它没有解决问题。任何想法如何解决这个问题?
1 个解决方案
#1
0
Let's say the time is B1:B5
and the double values is A1:A5
, please try this code.
假设时间是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");
#1
0
Let's say the time is B1:B5
and the double values is A1:A5
, please try this code.
假设时间是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");