如何在 PowerPoint 中更改单个图表元素颜色的颜色

How to change color of individual chart elements color in powerpoint

我有一个问题,假设一个图表(包含所有需要的数据)已经插入到 powerpoint 幻灯片中。现在我想做的是如果有人点击图表标题或 bars/columns 或图例或图表背景,该元素的背景颜色应更改为黑色。 在 word 应用程序中,我可以用

做同样的事情
application.Selection.InlineShapes[1].Fill.ForeColor.RGB = setColor;

如何在 powerpoint 中做同样的事情。

我在 powerpoint 中尝试的是:

application.ActiveWindow.Selection.ShapeRange[1].Fill.BackColor.RGB = 0;

但这总是会改变图表背景的颜色,并且 Selection.ShapeRange[1].Name 总是 "placeholder"。

只想改变单个元素的颜色。如果用户单击 1 个条形图,该条形图的颜色应变为黑色,如果单击图表标题,则其他元素不应发生类似的变化,只有背景应发生变化。我是 .net 的新手,对此有帮助。我想我可以解释我的担忧。 我最后尝试的是

ColorStyle colorstyle2 = MyAddin.AddinModule.CurrentInstance.SelectedColorStyle;
int setColor = ColorTranslator.ToOle(System.Drawing.Color.FromArgb(colorstyle2.R, colorstyle2.G, colorstyle2.B));
int position = app.ActiveWindow.Selection.ShapeRange.ZOrderPosition;
Slide slide2 = (Slide)app.ActiveWindow.View.Slide;// SELECTS CHART FROM SHAPE RANGE AS SELECTION HAS SHAPERANGE not shape
powerPoint.Shape s = slide2.Shapes[position];
if (s.HasChart==MsoTriState.msoTrue)
{
    object cht = s.GetType().InvokeMember("Chart", BindingFlags.GetProperty, null, (object)s, null);
    object chtFormat = cht.GetType().InvokeMember("Format", BindingFlags.GetProperty, null, (object)cht, null);
    object chtFill = cht.GetType().InvokeMember("Fill", BindingFlags.GetProperty, null, (object)chtFormat, null);
    object chtBackcolor = chtFill.GetType().InvokeMember("Backcolor", BindingFlags.GetProperty, null, (object)chtFill, null);
    object[] args = { 0 };//also used {0} here
    object chtRGB = chtBackcolor.GetType().InvokeMember("RGB", BindingFlags.SetProperty, null, (object)chtBackcolor, args);
}

我已经在许多论坛上发布了这个问题,但似乎没有 solution.Although 我有一个解决办法 属性 chart.GetChartElement 像

一样使用它
int ElementId = -1, arg1 = -1, arg2 = -1;    
chart.GetChartElement(X, Y, ref ElementId, ref arg1, ref arg2) 
//in which 
//X is relative position of element wrt to chart 
// similarly Y
var chartitem = (powerPoint.XlChartItem)ElementId;
switch (chartitem)
{
 case powerPoint.XlChartItem.xlDataLabel:break;
 case powerPoint.XlChartItem.xlChartArea:break;
 case powerPoint.XlChartItem.xlSeries:break;
 case powerPoint.XlChartItem.xlChartTitle:break;
 case powerPoint.XlChartItem.xlDataTable:break;
 case powerPoint.XlChartItem.xlMajorGridlines:break;
 case powerPoint.XlChartItem.xlMinorGridlines:break;
 case powerPoint.XlChartItem.xlAxisTitle:break;
 case powerPoint.XlChartItem.xlPlotArea:break;
 case powerPoint.XlChartItem.xlAxis:break;
 case powerPoint.XlChartItem.xlLegendEntry:break;
 case powerPoint.XlChartItem.xlLegendKey:break;
 case powerPoint.XlChartItem.xlLegend:break;
 default: break;
}

agr1 和 arg2 提供了额外的信息,例如点击了哪个 series/data 标签和哪个点。结果准确率为 90%,因为它取决于点击的位置。