作者:可乐加芬达61158 | 来源:互联网 | 2023-01-16 10:14
我正在创建一个VSTO加载项,其中包括为某些年度数据创建折线图.该数据每周包含数据点.我希望横轴可以按月分组,如下图所示:
然而,我无法在VSTO文件中找到关于这是否可能的任何内容.据我所知,系列只为X轴采用一维值数组.有人对这个有经验么?
1> Frederik Han..:
在Microsoft论坛的帮助下,我找到了一个解决方案(MSDN Thread).
对于其他想知道如何做到这一点的人来说,这就是我最终的结果:
Chart chart = slide.Shapes.AddChart(XlChartType.xlLine).Chart;
Excel.Workbook wb = (Excel.Workbook) chart.ChartData.Workbook;
Excel.Worksheet ws = wb.Worksheets[1];
ws.ListObjects["Table1"].Resize(ws.Range["A1:C13"]);
ws.Range["B1"].Value = "X";
ws.Range["A2"].Value = "2015";
ws.Range["A3:A7"].ClearContents();
ws.Range["A8"].Value = "2016";
ws.Range["A9:A13"].ClearContents();
ws.Range["B2"].Value = "7/15/2015";
ws.Range["B3"].Value = "8/15/2015";
ws.Range["B2:B3"].AutoFill(Destination: ws.Range["B2:B13"]);
ws.Range["B2:B13"].NumberFormat = "d-mmm";
ws.Range["C1"].Value = "Y";
ws.Range["C2"].Value = "100";
ws.Range["C3"].Value = "150";
ws.Range["C2:C3"].AutoFill(Destination: ws.Range["C2:C13"]);
(chart.SeriesCollection(1) as Series).Delete();
Series series = chart.SeriesCollection(1) as Series;
series.Values = "=Sheet1!$C$2:$C$13";
series.XValues = "=Sheet1!$A$2:$B$13";