2017-07-02 14 views
0

SQLデータベースからExcelスプレッドシートを作成するアプリケーションを構築し、アプリケーションを作成しました。それはもともと3つのシリーズを持っていた、次のコードは素晴らしい作品です。しかし、私は現在、セカンダリ軸で異なるスケールの2つの新しいシリーズを追加するよう求められています。範囲を追加しましたが、Excel interopを使用してセカンダリ軸を追加することはできません。C#Excel Interopを使用してセカンダリ軸を追加する

誰もこれを前にやったことがありますか?もしそうなら、私は何が欠けていますか?

ChartObjects xlCharts = (Excel.ChartObjects)mSheet.ChartObjects(Type.Missing); 

ChartObject myChart = (Excel.ChartObject)xlCharts.Add(358, (double)xlsRange.Top, 650, 350); 
myChart.Name = "myCool_Chart"; 
Chart chartPage = myChart.Chart; 
chartPage.ChartType = XlChartType.xlLine; 
Series series = myChart.Chart.SeriesCollection().Add(dSheet.Range["$F$2:$H$124,$P$2:$Q$124"]);//F thru H is left axis and P thru Q should be secondary axis    
series.XValues = dSheet.Range["$C$2:$C$124"];// Quart and Year values on bottom axis    
chartPage.SeriesCollection(1).Name = "My first series"; 
chartPage.SeriesCollection(2).Name = "My Second Series"; 
chartPage.SeriesCollection(2).Format.Line.ForeColor.RGB = (int)XlRgbColor.rgbDarkOrange;    
chartPage.SeriesCollection(3).Name = "My Third Series"; 
chartPage.SeriesCollection(4).Name = "My fourth Series"; //this series should be secondary 
chartPage.SeriesCollection(5).Name = "My fifth Series"; //this series should be secondary 

答えて

2

あなたはAxisGroupプロパティを使用することができます。

chartPage.SeriesCollection(4).Name = "My fourth Series"; //this series should be secondary 
chartPage.SeriesCollection(5).Name = "My fifth Series"; //this series should be secondary 
chartPage.SeriesCollection(4).AxisGroup = XlAxisGroup.xlSecondary //2 
chartPage.SeriesCollection(5).AxisGroup = XlAxisGroup.xlSecondary //2 
+0

必要だったまさに!!!!! –

関連する問題