Scatter chart labels showing when outside of axis limits

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)

@mmr-jef,

I have observed the sample code and generated chart shared by you. Can you please share the expected output presentation that you ought to generate using Aspose.Slides or which should be desired presentation generated from above code. Please share with us so that we may proceed further to help you.

Hi, what I need is a chart that when you change the axis the labels for the data points that are now outside of the plot area are not shown. At the moment they still appear outside of the plot area (as in slide 2 of the example I sent). If I were to set the chart up manually in PowerPoint then this doesn’t happen, the labels are hidden.

@mmr-jef,

I regret to share that I am unable to understand the issue shared by you. The code sample that you have shared produce the output presentation which has similar slide as shared by you. Can you please share the working sample code that is reproducing the issue on your end along with desired output presentation that is achieved through PowerPoint but is not getting possible using Aspose.Slides. We really wish to help you further and required elaboration of issue on your end.

Ok, I have amended the code to set the horizontal and vertical axis max and min. You can see that some of the labels from the datapoints that should no longer be seen as they are outside of the plot area are still showing when they should not be. I could just skip adding a label if the data point is outside the limits, but what if my end user wants to change the axis manually, the datapoint would no longer have a label. Hope this helps clarify.

Many thanks for looking.

scatter.zip (34.8 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;

        // Change axis
        chart.Axes.VerticalAxis.IsAutomaticMaxValue = false;
        chart.Axes.VerticalAxis.IsAutomaticMinValue = false;
        chart.Axes.HorizontalAxis.IsAutomaticMinValue = false;
        chart.Axes.HorizontalAxis.IsAutomaticMaxValue = false;
        chart.Axes.VerticalAxis.MaxValue = 2.5;
        chart.Axes.VerticalAxis.MinValue = 0;
        chart.Axes.HorizontalAxis.MinValue = -2;
        chart.Axes.HorizontalAxis.MaxValue = 0;

        // Save the file.
        string filePath = System.IO.Path.GetTempPath() + "/scatter.pptx";
        presentation.Save(filePath, SaveFormat.Pptx);

        // Open the file
        System.Diagnostics.Process.Start(filePath);

@mmr-jef,

I have observed the issue shared by you and have been able to reproduce the issue specified. An issue with ID SLIDESNET-39685 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be automatically notified once the issue will be fixed.

The issues you have found earlier (filed as SLIDESNET-39685) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by mudassir.fayyaz