Spire.Presentation is a professional PowerPoint® compatible library that enables developers to create, read, write, modify, convert and Print PowerPoint documents. Get free and professional technical support for Spire.Presentation for .NET, Java, Android, C++, Python.

Thu Jul 28, 2022 2:40 pm

Hi,
I want to update scatter chart data. I'm able to do this but the scatter chart label design changes. I want to keep that design and I want to update just data (X values, Y values and Labels)
How can I achieve that?

expected-output.pptx - PowerPoint.png


Template and expected output file:
template_and_expected_output_file.zip


Sample Code:

Code: Select all
using Spire.Presentation;
using System.Linq;
using Spire.Presentation.Charts;
using System;
using System.Drawing;
using Spire.Presentation.Drawing;

namespace PptxTester
{
    class Program
    {
        static void Main(string[] args)
        {
            UpdateScatterChartData();
        }

        private static void UpdateScatterChartData()
        {
            //Load template presentation
            Presentation templatePresentation = new Presentation();
            templatePresentation.LoadFromFile("template-scatter.pptx");

            //Create New Presentation
            Spire.Presentation.Presentation presentation = new Spire.Presentation.Presentation();
            presentation.Slides.RemoveAt(0);

            //Get slide from template presentation. index:1
            ISlide cloneSlide = templatePresentation.Slides.ToArray().ElementAtOrDefault(0);

            //---
            //Get Chart                       
            IChart chart = cloneSlide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart") as IChart;

            chart.ChartData.Clear(0, 0, 100, 100);

            chart.ChartData[0, 0].Text = "X-Values";
            chart.ChartData[0, 1].Text = "Y-Values";
            chart.ChartData[0, 2].Text = "Labels";

            chart.ChartData[1, 0].Value = 0.2442116868798236;
            chart.ChartData[1, 1].Value = 0.0387971403069604;
            chart.ChartData[1, 2].Text = "Trustworthy";

            chart.ChartData[2, 0].Value = 0.2554208011760382;
            chart.ChartData[2, 1].Value = 0.0193438734246104;
            chart.ChartData[2, 2].Text = "Themselves";

            chart.ChartData[3, 0].Value = 0.1486585814038956;
            chart.ChartData[3, 1].Value = 0.0548347854424534;
            chart.ChartData[3, 2].Text = "Talked About";

            chart.ChartData[4, 0].Value = 0.2307975009187799;
            chart.ChartData[4, 1].Value = 0.0387878010163053;
            chart.ChartData[4, 2].Text = "Reliable";

            chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];
            chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"];

            chart.Series[0].XValues = chart.ChartData["A2", "A5"];
            chart.Series[0].YValues = chart.ChartData["B2", "B5"];
            chart.Series[0].DataLabelRanges = chart.ChartData["C2", "C5"];

            for (int i = 0; i < 5; i++)
            {
                ChartDataLabel dataLabel = chart.Series[0].DataLabels.Add();
                dataLabel.ID = i;
                dataLabel.ShowDataLabelsRange = true;
            }

            //Set the X - axis invisible and Y - axis type is none;
            chart.PrimaryValueAxis.IsVisible = false;
            chart.SecondaryValueAxis.ChartEffectFormat.Line.FillType = FillFormatType.None;

            presentation.Slides.Append(cloneSlide);

            //Save and launch to view the PPTX document.
            presentation.SaveToFile("UpdateScatterChartData_01.pptx", Spire.Presentation.FileFormat.Pptx2010);
        }
    }
}

omur.ertanis
 
Posts: 22
Joined: Mon Feb 21, 2022 6:49 am

Fri Jul 29, 2022 10:33 am

Hello,

Thanks for your inquiry.
To better achieve your demand, I made some adjustments to your code as shown in the following. However, at present, the modified "text" value of the result document cannot be automatically updated. It needs to manually open datasource in the result document to update them. Anyway, I have logged this issue to our bug tracking system with ticket SPIREPPT-2027. Our development team will further investigate and fix it. I will keep you informed as soon as there is any progress. Sorry for the inconvenience.

Sincerely,
William
E-iceblue support team
Code: Select all
            //Load template presentation
            Presentation templatePresentation = new Presentation();
            templatePresentation.LoadFromFile(@"template-scatter.pptx");
            //Create New Presentation
            Spire.Presentation.Presentation presentation = new Spire.Presentation.Presentation();
            presentation.Slides.RemoveAt(0);
            //Get slide from template presentation. index:1
            ISlide cloneSlide = templatePresentation.Slides.ToArray().ElementAtOrDefault(0);
            //Get Chart                       
            IChart chart = cloneSlide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart") as IChart;
            chart.ChartData.Clear(0, 0, 100, 100);
            chart.ChartData[1, 0].Value = 0.2442116868798236;
            chart.ChartData[1, 1].Value = 0.0387971403069604;
            chart.ChartData[1, 2].Text = "Trustworthy";
            chart.ChartData[2, 0].Value = 0.2554208011760382;
            chart.ChartData[2, 1].Value = 0.0193438734246104;
            chart.ChartData[2, 2].Text = "Themselves";
            chart.ChartData[3, 0].Value = 0.1486585814038956;
            chart.ChartData[3, 1].Value = 0.0548347854424534;
            chart.ChartData[3, 2].Text = "Talked About";
            chart.ChartData[4, 0].Value = 0.2307975009187799;
            chart.ChartData[4, 1].Value = 0.0387878010163053;
            chart.ChartData[4, 2].Text = "Reliable";
            presentation.Slides.Append(cloneSlide);
            //Save and launch to view the PPTX document.
            presentation.SaveToFile(@"UpdateScatterChartData_01.pptx", Spire.Presentation.FileFormat.Pptx2010);
User avatar

William.Zhang
 
Posts: 194
Joined: Mon Dec 27, 2021 2:23 am

Mon Aug 01, 2022 9:57 am

Hi William,

You have fully understood our requirements and your code makes sense.

Please keep us updated on this ticket as its vital for us.

Thanks

majeed_s
 
Posts: 69
Joined: Thu Mar 25, 2021 4:13 pm

Thu Aug 11, 2022 2:44 am

Hello,

Greetings from E- iceblue.
Glad to inform that we just released Spire.Presentation Pack Version:7.8 which fixed the issue of SPIREPPT-2027, please download it from the following links to test.
Website link:https://www.e-iceblue.com/Download/download-presentation-for-net-now.html
Nuget link: https://www.nuget.org/packages/Spire.Presentation/7.8.0

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 194
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.Presentation