1
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
            ChartSeriesEx series = chart.ChartData.Series[0];

       for(int i=0;i<9;i++)
       {

            fact.GetCell(0, 0, 1, "Index");
            series.Values[check].Value = 10;
       }

以上是我当前使用 aspose.slides 更新图表的代码。我想知道如何更改代码的代码系列的颜色。

4

1 回答 1

1

我的名字是 Nayyer,我是 Aspose 的开发布道者。

请尝试使用以下设置特定系列填充颜色的代码片段。

ChartSeriesEx series = chart.ChartData.Series[0];
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.FromArgb(32, 202, 250);
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, 40));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 64));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 50));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 4, 1, 1));

但是,您可以考虑查看以下代码片段,因为它可以帮助您理解使用不同图表实体的概念。但首先我想在 X 轴(类别轴)上分享,类别绘制在 Y 轴(值轴)上。您能否通过设置 x 轴和 y 轴的最小/最大值来详细说明您的意思。x 轴仅包含类别名称。其次,以我的拙见,在 PowerPoint 中也无法设置值轴的最小/最大值。您能否以快照的形式分享在 PowerPoint 中设置轴的最小/最大值的方式,我将尝试使用 Aspose.Slides 在我的末端实现相同的方法。请分享这方面的信息,以便我可以进一步帮助您。

以下代码还显示了如何在辅助轴上绘制系列值。

PresentationEx pres;
pres = new PresentationEx();
SlideEx sld = pres.Slides[0];
ChartEx chart = sld.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 0, 0, 500, 500);
chart.ChartTitle.Text.Text = "Sample Title";
chart.ChartTitle.Text.CenterText = true;
chart.ChartTitle.Height = 20;
chart.HasTitle = false;
chart.HasLegend = false;
chart.ChartData.Series[0].Labels.ShowValue = true;

chart.SecondCategoryAxis.IsVisible = true;

int defaultWorksheetIndex = 0;
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "1"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "2"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 3, "3"), chart.Type);
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Age"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Gender"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Status"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 4, 0, "Nationality"));
chart.GapDepth = 200;
//chart.GapWidth = 50 I need to be able to do something similar to this code

ChartSeriesEx series = chart.ChartData.Series[0];
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.FromArgb(32, 202, 250);
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, 40));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 64));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 50));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 4, 1, 1));
series.PlotOnSecondAxis = true;

series = chart.ChartData.Series[1];
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.FromArgb(0, 122, 171);
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 2, 4));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 2, 19));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 2, 50));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 4, 2, 25));
series.PlotOnSecondAxis = true;

series = chart.ChartData.Series[2];
series.Format.Fill.FillType = FillTypeEx.Solid;
series.Format.Fill.SolidFillColor.Color = Color.FromArgb(0, 136, 188);
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 2, 3));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 2, 17));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 2, 0));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 4, 2, 63));

series.PlotOnSecondAxis = true;

chart.GapDepth = 80;//Values in percentage
chart.GapWidth = 250;

pres.Write("D:\\Aspose Data\\Presentation2.pptx");
于 2012-12-06T14:36:02.887 回答