2016-03-21 5 views
0

私はこのコードの基本的なExcelのグラフを生成しています:Excelチャートが円グラフに対応していない凡例を生成するのはなぜですか?

object misValue = System.Reflection.Missing.Value; 
//add data 
_xlSheet.Cells[11, 11] = "PhooBar"; 
_xlSheet.Cells[11, 12] = "Student1"; 
_xlSheet.Cells[11, 13] = "Student2"; 
_xlSheet.Cells[11, 14] = "Student3"; 

_xlSheet.Cells[12, 11] = "Term1"; 
_xlSheet.Cells[12, 12] = "80"; 
_xlSheet.Cells[12, 13] = "65"; 
_xlSheet.Cells[12, 14] = "45"; 

_xlSheet.Cells[13, 11] = "Term2"; 
_xlSheet.Cells[13, 12] = "78"; 
_xlSheet.Cells[13, 13] = "72"; 
_xlSheet.Cells[13, 14] = "60"; 

_xlSheet.Cells[14, 11] = "Term3"; 
_xlSheet.Cells[14, 12] = "82"; 
_xlSheet.Cells[14, 13] = "80"; 
_xlSheet.Cells[14, 14] = "65"; 

_xlSheet.Cells[15, 11] = "Term4"; 
_xlSheet.Cells[15, 12] = "75"; 
_xlSheet.Cells[15, 13] = "82"; 
_xlSheet.Cells[15, 14] = "68"; 

Excel.Range chartRange; 

Excel.ChartObjects xlCharts = (Excel.ChartObjects)_xlSheet.ChartObjects(Type.Missing); 
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(468, 160, 348, 268); 
Excel.Chart chartPage = myChart.Chart; 

chartRange = _xlSheet.get_Range("K11", "O15"); // K == 11, O == 15 
chartPage.SetSourceData(chartRange, misValue); 
chartPage.ChartType = Excel.XlChartType.xlPieExploded; 

私はラベルの配置hereを制御について質問があります。

enter image description here

ISTMチャートエンジンの伝説は、パイと一致する必要があること:

は今、私は4つのパイ片が、伝説上の5つの項目がある理由を知りたいです。どうしたんだ?このようにコードを変更することにより

+0

あなたの伝説4つの項目あるので、紫の一つは、「」1 .. – BugFinder

+1

が、それはこのためのものではないだろうか? _xlSheet.Cells [11、11] = "" ;; – Ian

+1

'_xlSheet.Cells [11、11] =" ";' foo'と言ってあなたの伝説に 'foo'を入れます... –

答えて

0

、パイ及び凡例は対応する:

object misValue = System.Reflection.Missing.Value; 
//add data 
_xlSheet.Cells[12, 11] = "Term1"; 
_xlSheet.Cells[12, 12] = "80"; 
_xlSheet.Cells[12, 13] = "65"; 
_xlSheet.Cells[12, 14] = "45"; 

_xlSheet.Cells[13, 11] = "Term2"; 
_xlSheet.Cells[13, 12] = "78"; 
_xlSheet.Cells[13, 13] = "72"; 
_xlSheet.Cells[13, 14] = "60"; 

_xlSheet.Cells[14, 11] = "Term3"; 
_xlSheet.Cells[14, 12] = "82"; 
_xlSheet.Cells[14, 13] = "80"; 
_xlSheet.Cells[14, 14] = "65"; 

_xlSheet.Cells[15, 11] = "Term4"; 
_xlSheet.Cells[15, 12] = "75"; 
_xlSheet.Cells[15, 13] = "82"; 
_xlSheet.Cells[15, 14] = "68"; 

Excel.Range chartRange; 

//return; 

Excel.ChartObjects xlCharts = (Excel.ChartObjects)_xlSheet.ChartObjects(Type.Missing); 
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(468, 160, 348, 268); 
Excel.Chart chartPage = myChart.Chart; 

chartRange = _xlSheet.Range[_xlSheet.Cells[12, 11], _xlSheet.Cells[15, 14]]; 

をI「は範囲[]」より効率的かつ容易ツーGROKに「get_Range」から、現在存在します1:パイ片と伝説の間に1の対応関係:

enter image description here

+0

ねえ、あなたはこれを解決します。すばらしいです! ;) – Ian

関連する問題