C# Excel 图表改变颜色
我正在尝试将图表系列的线条颜色更改为“无”。我尝试设置颜色和标记属性,但程序出错。
我的代码:
Excel.ChartObjects _ChartObjects = (Excel.ChartObjects)(oSheet1.ChartObjects(Missing.Value));
Excel.ChartObject _ChartObject = _ChartObjects.Add(170, 0, 400, 300);
Excel.Chart _Chart = _ChartObject.Chart;
Excel.Range oRng1;
oRng1 = oSheet1.get_Range("A1","E55");
_Chart.SetSourceData(oRng1, Excel.XlRowCol.xlColumns);
_Chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLineMarkers;
oWB.ShowPivotChartActiveFields = true;
//_Chart.ChartTitle.Font.Size = 12;
_Chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementDataTableWithLegendKeys);
_Chart.DataTable.Font.Size = 6;
oWB.ShowPivotChartActiveFields = false;
_Chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementPrimaryValueAxisTitleRotated);
_Chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementLegendNone);
//_Chart.Legend.Delete();
_Chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementPrimaryValueAxisTitleNone);
_Chart.Location(Excel.XlChartLocation.xlLocationAsNewSheet, "Tax Weekly Term-Chart");
Excel.SeriesCollection seriesCollection = (Excel.SeriesCollection)_Chart.SeriesCollection(Type.Missing);
Excel.Series series = (Excel.Series)seriesCollection.Item(4);
需要代码将系列的颜色设置为“无”。任何建议都会有用。
I am trying to change the line color of the chart series to None. I tried setting the color and the marker property but the program errors out.
My code:
Excel.ChartObjects _ChartObjects = (Excel.ChartObjects)(oSheet1.ChartObjects(Missing.Value));
Excel.ChartObject _ChartObject = _ChartObjects.Add(170, 0, 400, 300);
Excel.Chart _Chart = _ChartObject.Chart;
Excel.Range oRng1;
oRng1 = oSheet1.get_Range("A1","E55");
_Chart.SetSourceData(oRng1, Excel.XlRowCol.xlColumns);
_Chart.ChartType = Microsoft.Office.Interop.Excel.XlChartType.xlLineMarkers;
oWB.ShowPivotChartActiveFields = true;
//_Chart.ChartTitle.Font.Size = 12;
_Chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementDataTableWithLegendKeys);
_Chart.DataTable.Font.Size = 6;
oWB.ShowPivotChartActiveFields = false;
_Chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementPrimaryValueAxisTitleRotated);
_Chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementLegendNone);
//_Chart.Legend.Delete();
_Chart.SetElement(Microsoft.Office.Core.MsoChartElementType.msoElementPrimaryValueAxisTitleNone);
_Chart.Location(Excel.XlChartLocation.xlLocationAsNewSheet, "Tax Weekly Term-Chart");
Excel.SeriesCollection seriesCollection = (Excel.SeriesCollection)_Chart.SeriesCollection(Type.Missing);
Excel.Series series = (Excel.Series)seriesCollection.Item(4);
Need code to set the color of the series to None.Any suggestions would be useful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此代码可以根据每个切片的图例标签设置电子表格中所有饼图的切片颜色:
此代码可以设置条形图颜色:
也许可以帮助您!
This code can set the colours of the slices of all the pie charts in my spreadsheet based on each slice's legend's label:
And this code can set barchart colours:
Maybe could help you!