如何在我的Excel饼图上创建自定义颜色? 我的饼图有5个切片。以下是我的源代码。
using Excel = Microsoft.Office.Interop.Excel;
Excel.Range chartRange;
Excel.ChartObjects xlCharts = (Excel.ChartObjects)xlWorkSheet.ChartObjects(Type.Missing);
Excel.ChartObject myChart = (Excel.ChartObject)xlCharts.Add(10, 80, 500, 350);
Excel.Chart chartPage = myChart.Chart;
chartRange = xlWorkSheet.get_Range("A3", "B7");
chartPage.ChartStyle = 209;
chartPage.HasTitle = true;
chartPage.ChartTitle.Text = "HeaderText Title";
chartPage.SetSourceData(chartRange, misValue);
chartPage.ChartType = Excel.XlChartType.xl3DPieExploded;
chartPage.Elevation = 35;
chartPage.ApplyDataLabels(Excel.XlDataLabelsType.xlDataLabelsShowLabelAndPercent ,false, true, true, false, true, false, true, true, Separator:System.Environment.NewLine);
xlWorkBook.SaveAs(saveAsLocation);
xlWorkBook.Close(true, misValue, misValue);
xlApp.Quit();
答案 0 :(得分:1)
您可以像这样更改饼图中每个点的// $all=
array (
0 =>
array (
1 =>
array (
'ED' => 60,
'EN' => 64,
'MT' => 44,
'MZ' => 47,
),
),
1 =>
array (
2 =>
array (
'ED' => 43,
'EN' => 50,
'MT' => 92,
'MZ' => 90,
),
),
)
//$fscores=
array (
1 =>
array (
'score' => 215,
'farray' => true,
'tarray' => true,
),
2 =>
array (
'score' => 275,
'farray' => false,
'tarray' => true,
),
)
:
ColorIndex
以下是可用颜色的完整列表msdn
ColorIndex属性可以包含0到56之间的有效整数参数,用于生成颜色。
答案 1 :(得分:0)
我相信您可以更改系列点格式的ForeColor
属性。类似的东西:
var series = (Excel.SeriesCollection)chartPage.SeriesCollection();
var points = (Excel.Points)series.Item(1).Points();
points.Item(1).Format.Fill.ForeColor.RGB = (int)Excel.XlRgbColor.rgbRed;
points.Item(2).Format.Fill.ForeColor.RGB = (int)Excel.XlRgbColor.rgbBlue;
......等等。