2
我需要使用兩個不相鄰列中的兩個範圍創建圖表,並在代碼中定義哪個範圍將採用X軸和Y軸。在C#中使用非相鄰列的數據創建Excel圖表
例如:兩個範圍M3:M15
和K3:K15
我需要X軸的值是從K3
到K15
,和Y軸的值是從M3
到M15
。
我有兩個相鄰列創建圖表代碼:
string start_chart_values = "M3";
int stop_chart_line_calc = 1 + num_of_rows_to_copy;
string stop_chart_values = "L" + stop_chart_line_calc.ToString();
double chart_location = stop_chart_line_calc * 12;
Excel.Range chartRange;
Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(2, chart_location, 300, 250);
Excel.Chart chartPage = myChart.Chart;
Excel.Axis yAxis = chartPage.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary);
yAxis.ScaleType = Excel.XlScaleType.xlScaleLogarithmic;
chartRange = xlWorkSheet.get_Range(start_chart_values, stop_chart_values);
chartPage.SetSourceData(chartRange);
chartPage.ChartType = Excel.XlChartType.xlXYScatterSmooth;
chartPage.ChartWizard(Source: chartRange, Title: "Recommended Blood Pressure", CategoryTitle: "Students Age", ValueTitle: "Blood Pressure");
遺憾的是這段代碼是不夠的,因爲我需要選擇自己的代碼中的X軸Y軸的價值和能力。
如何更改代碼,以便我可以在代碼中定義哪些範圍將採用X軸和Y軸?
在此先感謝