2014-01-20 75 views
2

enter image description here我想添加一個額外的數據系列圖表這顯示了CPU的閾值,我可以得到的範圍和創建的圖形沒有門檻,但我不知道如何將閾值添加到圖表。 我需要創建另一個圖表對象嗎?我可以使用現有的,只需添加新的範圍?如何添加額外的系列到Excel圖表使用C#

Threshold values

你是如何創建的圖表? - 見下面的代碼。 此圖表是否已經在Excel文件中創建,並且您想要在Excel文件中修改圖表?是圖表已經在Excel文件中。

Excel.ChartObjects sCPUChart; Excel.ChartObject sCPUChartObjects;門檻

C55 = 0 
    C56 = 1 
    D55 = 75 
    D56 = 75 

我不知道如何刪除出現在圖表 2個附加軸如果我註釋掉 -

 sCPUChart = sDBSheet.ChartObjects(Type.Missing); 
     sCPUChartObjects = sCPUChart.Add(49, 15, 360, 215); 

     Excel.Chart sChartCPU; 

     sChartCPU = sCPUChartObjects.Chart; 
     sChartCPU.SetSourceData(cpuChartRange, Missing.Value); 
     sChartCPU.ChartWizard(Source: cpuChartRange, Gallery: Excel.XlChartType.xlLine, Format: 2, HasLegend: true); 
     sChartCPU.Location(Excel.XlChartLocation.xlLocationAsObject, sDBSheet.Name); 

     //CPU Chart Axis 
     Excel.Axis xSChartCPUAxis; 
     xSChartCPUAxis = sChartCPU.Axes(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlPrimary); 


     Excel.Axis ySChartCPUAxis; 
     ySChartCPUAxis = syChartCPU.Axes(Excel.XlAxisType.xlValue, Excel.XlAxisGroup.xlPrimary); 
     ySChartCPUAxis.HasMajorGridlines = true; 
     ySChartCPUAxis.MaximumScaleIsAuto = true; 

     //Set Summary CPU Series 
     Excel.Series sCPUSeries = sChartCPU.SeriesCollection(1); 
     sCPUSeries.Name = "CPU"; 


//------- 
// this is where I am having my issue 
//I don't know how to add the threshold line to the graph with the existing graph being displayed 

     //sChartCPU.set_HasAxis(Excel.XlAxisType.xlCategory, Excel.XlAxisGroup.xlSecondary, true); 
     //summaryChartCPU.SetSourceData(summaryMemThreshold, Type.Missing); -- things break 
     //------- 
I have now done the following: 


    Excel.SeriesCollection threshold = sChartCPU.sseriesCollection(); 
    Excel.Series line = threshold.NewSeries(); 
    line.Formula = "=SERIES(Summ!$D$54,Summ!$C$55:$C$56,Summ!$D$55:$D$56)"; 
    line.ChartType = Excel.XlChartType.xLScatterLinesNoMarkers; 


when the threshold line is created I have the following 

with new series

我在細胞D54值line.ChartType,那麼軸是正確的,但我只得到一個閾值數據點??我不明白爲什麼。

+0

您是如何創建圖表的?該圖表是否已經在Excel文件中創建,並且您想要在Excel文件中修改圖表? – Amber

回答

2
var series = (SeriesCollection) yourChart.SeriesCollection(); 
var line = series.NewSeries(); 

line.Name = "CPU Threshhold"; 
//line.Values = ...; 
//line.XValues = ...; 

//formatting 
+0

所以我試過這個,'Excel.SeriesCollection threshold = sChartCPU.SeriesCollection(); Excel系列line = threshold.NewSeries(); line.values =「75,75」;'但是我得到line.values錯誤 – user3168684