如何在大到足以容纳它们的饼子上添加标签,并在不能容纳大饼的饼子上添加标签? [英] How can I add labels onto the pie pieces that are large enough to contain them, and alongside those that aren't?

查看:137
本文介绍了如何在大到足以容纳它们的饼子上添加标签,并在不能容纳大饼的饼子上添加标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有简单的虚假数据可以生成此Excel图表:

I've got simple bogus data that generates this Excel Chart:

这是代码:

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;

我该怎么做才能将标签添加到足够大的饼图上,以容纳它们,而在不包含标签的饼图上添加标签,并用箭头指向相应的饼图?

What do I need to do to add labels onto the pie pieces that are large enough to contains them, and labels alongside those that aren't, with arrows pointing to the appropriate pie piece?

推荐答案

添加标签就像这样简单:

Adding labels is as easy as this:

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);

它产生的这种精美的图形值得毕加索的门徒使用:

It produces this exquisitely appointed graphic worthy of a disciple of Picasso:

这篇关于如何在大到足以容纳它们的饼子上添加标签,并在不能容纳大饼的饼子上添加标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆