2016-03-18 1 views
-1

У меня просто фиктивный данные, генерирующий эта Excel таблица:Как добавить ярлыки на куски пирога, которые достаточно велики, чтобы их содержать, и рядом с теми, которые нет?

enter image description here

Это код:

object misValue = System.Reflection.Missing.Value; 
//add data 
_xlSheet.Cells[11, 11] = ""; 
_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); //10, 80, 300, 250); 
Excel.Chart chartPage = myChart.Chart; 

chartRange = _xlSheet.get_Range("K11", "O15"); 
chartPage.SetSourceData(chartRange, misValue); 
chartPage.ChartType = Excel.XlChartType.xlPieExploded; // xl3DPie; xlPie; xlColumnClustered; 

Что мне нужно сделать, чтобы добавить метки на пирог куски, достаточно велики, чтобы содержать их, и наклеиваются рядом с теми, которые нет, со стрелками, указывающими на подходящую деталь пирога?

ответ

0

Добавление меток так просто, как это:

chart.ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowPercent, Excel.XlDataLabelsType.xlDataLabelsShowLabel, true, false, false, true, false, true); 

В контексте:

object misValue = System.Reflection.Missing.Value; 

_xlSheet.Cells[12, 11] = "John"; 
_xlSheet.Cells[12, 12] = "80"; 
_xlSheet.Cells[12, 13] = "165"; 
_xlSheet.Cells[12, 14] = "45"; 

_xlSheet.Cells[13, 11] = "Paul"; 
_xlSheet.Cells[13, 12] = "78"; 
_xlSheet.Cells[13, 13] = "72"; 
_xlSheet.Cells[13, 14] = "6"; 

_xlSheet.Cells[14, 11] = "George"; 
_xlSheet.Cells[14, 12] = "182"; 
_xlSheet.Cells[14, 13] = "180"; 
_xlSheet.Cells[14, 14] = "165"; 

_xlSheet.Cells[15, 11] = "Ringo"; 
_xlSheet.Cells[15, 12] = "7"; 
_xlSheet.Cells[15, 13] = "8"; 
_xlSheet.Cells[15, 14] = "6"; 

Excel.Range chartRange; 

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

chartRange = _xlSheet.Range[_xlSheet.Cells[12, 11], _xlSheet.Cells[15, 14]]; 
chart.SetSourceData(chartRange, misValue); 
chart.ChartType = Excel.XlChartType.xlPieExploded; 
chart.ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowPercent, 
Excel.XlDataLabelsType.xlDataLabelsShowLabel, true, false, false, true, false, true); 

Он производит это изысканно назначил графический достойный ученик Пикассо:

enter image description here

+0

Я все еще хочу знать, как добавить строку, которая соединяет части, которые слишком малы для содержат ярлык с метками «выноски», хотя ... –