Hello,
I am trying to create a column chart with two value axis on it, this works well but when I try to add a title to the second value axis I get an 'Object reference not set to instance of an object' error.
See sample code:
ChartEx ch = sld.Shapes.AddChart(Aspose.Slides.Pptx.Charts.ChartTypeEx.Line, 30, 100, 330, 220);
ChartDataCellFactory fact = ch.ChartData.ChartDataCellFactory;
ch.ChartData.Series.Clear();
ch.ChartData.Categories.Clear();
int[] series1Data = new int[] { 1, 1, 1, 1 };
int[] series2Data = new int[] { 2, 2, 2, 2 };
string[] categoryLabels = new string[] { "A", "B", "C", "D" };
ChartSeriesEx series1 = ch.ChartData.Series[ch.ChartData.Series.Add(fact.GetCell(0, 0, 1, "series 1"), ChartTypeEx.ClusteredColumn)];
for (int i = 0; i < series1Data.Length; i++)
series1.Values.Add(fact.GetCell(0, (i + 1), 1, series1Data[i]));
ChartSeriesEx series2 = ch.ChartData.Series[ch.ChartData.Series.Add(fact.GetCell(0, 0, 2, "series 2"), ChartTypeEx.Line)];
for (int i = 0; i < series2Data.Length; i++)
series2.Values.Add(fact.GetCell(0, (i + 1), 2, series2Data[i]));
for (int i = 0; i < categoryLabels.Length; i++)
ch.ChartData.Categories.Add(fact.GetCell(0, (i + 1), 0, categoryLabels[i]));
ch.SecondValueAxis.IsVisible = true;
series2.PlotOnSecondAxis = true;
ch.ValueAxis.HasTitle = true;
ch.ValueAxis.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 10;
ch.ValueAxis.Title.Text.Text = "series 1";
ch.ValueAxis.Title.Text.Paragraphs[0].Portions[0].PortionFormat.FontHeight = 8;
// --- CODE THAT PRODUCES ERROR ---
ch.SecondValueAxis.HasTitle = true;
ch.SecondValueAxis.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 10;
ch.SecondValueAxis.Title.Text.Text = "series 2";
ch.SecondValueAxis.Title.Text.Paragraphs[0].Portions[0].PortionFormat.FontHeight = 8;
// --- END ---
ch.CategoryAxis.TextProperties.Paragraphs[0].ParagraphFormat.DefaultPortionFormat.FontHeight = 8;