Hi,
I am experiencing an issue whereby the labels for a scatter chart are shown even though they are outside of the current axis limits that have been set. The normal behaviour of PowerPoint is that these labels would be hidden unless the axis is set to include them. Below is an example of code that replicates this issue and I have attached an example output. I am using Aspose Slides for .Net C# and version 17.12.1.
Many thanks.
scatter.zip (34.0 KB)
//create PPT document.
Presentation presentation = new Presentation();
// Get slides from presentation.
ISlideCollection slides = presentation.Slides;
// Set slide to first slide.
ISlide slide = presentation.Slides[0];
// Add a clustered bar chart.
IChart chart = slide.Shapes.AddChart(ChartType.ScatterWithMarkers, 20, 100, 600, 400);
// Getting the default chart data worksheet index
int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
IChartDataWorkbook worksheet = chart.ChartData.ChartDataWorkbook;
// Delete demo series
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
chart.ChartData.ChartDataWorkbook.Clear(0);
// Create some dummy data (will be taken from excel in final version)
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("Product", typeof(string));
table.Columns.Add("X", typeof(decimal));
table.Columns.Add("Y", typeof(decimal));
table.Rows.Add("Product 1", 0.89, -0.54);
table.Rows.Add("Product 2", 0.89, 0.7);
table.Rows.Add("Product 3", 0.77, -1.81);
table.Rows.Add("Product 4", -1.46, -0.72);
table.Rows.Add("Product 5", -0.93, 1.78);
table.Rows.Add("Product 6", -1.56, 1.47);
table.Rows.Add("Product 7", -0.59, 1.95);
table.Rows.Add("Product 8", -1.47, 0.67);
table.Rows.Add("Product 9", -1.27, 1.55);
// Add new categories.
for (int i = 0; i < table.Rows.Count; i++)
{
chart.ChartData.Categories.Add(worksheet.GetCell(defaultWorksheetIndex, i + 1, 0, table.Rows[i].Field<string>(0)));
}
// Add new series.
chart.ChartData.Series.Add(worksheet.GetCell(defaultWorksheetIndex, 0, 1, "X"), chart.Type);
// Label second column.
chart.ChartData.ChartDataWorkbook.GetCell(defaultWorksheetIndex, 0, 2).Value = "Y";
// Take first chart series
IChartSeries series = chart.ChartData.Series[0];
// Add the data to the series.
for (int i = 0; i < table.Rows.Count; i++)
{
series.DataPoints.AddDataPointForScatterSeries(worksheet.GetCell(defaultWorksheetIndex, i + 1, 1, table.Rows[i].Field<decimal>(1)),
worksheet.GetCell(defaultWorksheetIndex, i + 1, 2, table.Rows[i].Field<decimal>(2)));
}
// Set marker style
for (int i = 0; i < table.Rows.Count; i++)
{
series.DataPoints[i].Marker.Symbol = MarkerStyleType.X;
}
// Add labels
for (int i = 0; i < table.Rows.Count; i++)
{
IDataLabel label = series.DataPoints[i].Label;
IPortion portion = new Portion();
portion.Text = table.Rows[i].Field<string>(0);
label.TextFrameForOverriding.Text = "";
IParagraph paragraph = label.TextFrameForOverriding.Paragraphs[0];
paragraph.Portions.Add(portion);
label.DataLabelFormat.ShowSeriesName = false;
label.DataLabelFormat.ShowPercentage = false;
label.DataLabelFormat.ShowLegendKey = false;
label.DataLabelFormat.ShowCategoryName = false;
label.DataLabelFormat.ShowBubbleSize = false;
// Change the font colour.
portion.PortionFormat.FillFormat.FillType = FillType.Solid;
portion.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
// Change the font.
portion.PortionFormat.LatinFont = new FontData("Arial");
portion.PortionFormat.FontHeight = 10;
}
// Clean up the chart
// Remove legend
chart.HasLegend = false;
// Remove gridlines
chart.Axes.VerticalAxis.MajorGridLinesFormat.Line.FillFormat.FillType = FillType.NoFill;
// Remove axis values and tick marks.
chart.Axes.VerticalAxis.TickLabelPosition = TickLabelPositionType.None;
chart.Axes.VerticalAxis.MajorTickMark = TickMarkType.None;
chart.Axes.HorizontalAxis.TickLabelPosition = TickLabelPositionType.None;
chart.Axes.HorizontalAxis.MajorTickMark = TickMarkType.None;
// Add a line around the plot area
chart.PlotArea.Format.Line.FillFormat.FillType = FillType.Solid;
chart.PlotArea.Format.Line.FillFormat.SolidFillColor.Color = Color.Black;
// Save the file.
string filePath = System.IO.Path.GetTempPath() + "/scatter.pptx";
presentation.Save(filePath, SaveFormat.Pptx);
// Open the file
System.Diagnostics.Process.Start(filePath);<a class="attachment" href="/uploads/default/10143">scatter.zip</a> (34.0 KB)