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.

Sun Jun 28, 2015 2:41 pm

I am trying to figure out how to create a Bubble Chart. This is what I have so far, but it doesn't work.
Code: Select all
 Presentation pres = new Presentation();
            RectangleF rect1 = new RectangleF(0, 0, 700, 500);
            IChart chart = pres.Slides[0].Shapes.AppendChart(ChartType.Bubble, rect1, false);
            chart.ChartTitle.TextProperties.Text = "Bubble Chart";
            chart.ChartTitle.TextProperties.IsCentered = true;
            chart.ChartTitle.Height = 30;
            chart.HasTitle = true;

            Double[] xdata = new Double[] { 7.7, 8.9, 1.0, 2.4 };
            Double[] ydata = new Double[] { 15.2, 5.3, 6.7, 8 };
            Double[] A = new Double[] { 1.1, 2.4, 3.7, 4.8 };


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

            for (Int32 i = 0; i < xdata.Length; ++i)
            {
                chart.ChartData[i + 1, 0].Value = xdata[i];
                chart.ChartData[i + 1, 1].Value = ydata[i];
                chart.ChartData[i + 1, 2].Value = A[i];
            }
            chart.Series.Clear();
            chart.Categories.Clear();
            chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"];

            chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];

            chart.Series[0].XValues = chart.ChartData["A2", "A5"];
            chart.Series[0].YValues = chart.ChartData["B2", "B5"];
            chart.Series[0].Bubbles.Add("AAA");
            chart.Series[0].Bubbles[0].Value = chart.ChartData["C2", "C5"];
            pres.SaveToFile(@"..\..\result.pptx", FileFormat.Pptx2007);


can you give me a sample, thanks.

liuzihui
 
Posts: 2
Joined: Wed Apr 08, 2015 2:24 am

Mon Jun 29, 2015 8:21 am

Hello,

Thanks for your inquiry.
Please refer to the below code:
Code: Select all
           Presentation pres = new Presentation();
            RectangleF rect1 = new RectangleF(0, 0, 700, 500);
            IChart chart = pres.Slides[0].Shapes.AppendChart(ChartType.Bubble, rect1,false);
            chart.ChartTitle.TextProperties.Text = "Bubble Chart";
            chart.ChartTitle.TextProperties.IsCentered = true;
            chart.ChartTitle.Height = 30;
            chart.HasTitle = true;

            Double[] xdata = new Double[] { 7.7, 8.9, 1.0, 2.4 };
            Double[] ydata = new Double[] { 15.2, 5.3, 6.7, 8 };
            Double[] A = new Double[] { 1.1, 2.4, 3.7, 4.8 };


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


            for (Int32 i = 0; i < xdata.Length; ++i)
            {
                chart.ChartData[i + 1, 0].Value = xdata[i];
                chart.ChartData[i + 1, 1].Value = ydata[i];
                chart.ChartData[i + 1, 2].Value = A[i];
            }
            chart.Series.Clear();
            chart.Categories.Clear();
           
            chart.Categories.CategoryLabels = chart.ChartData["A2", "A5"];
            chart.Series.SeriesLabel = chart.ChartData["B1", "B1"];           
            chart.Series[0].XValues = chart.ChartData["A2", "A5"];
            chart.Series[0].YValues = chart.ChartData["B2", "B5"];
                     
            chart.Series[0].Bubbles.Add(chart.ChartData["C2"]);
            chart.Series[0].Bubbles.Add(chart.ChartData["C3"]);
            chart.Series[0].Bubbles.Add(chart.ChartData["C4"]);
            chart.Series[0].Bubbles.Add(chart.ChartData["C5"]);
                                         
            pres.SaveToFile(@"result.pptx", FileFormat.Pptx2010);

If there are any questions, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon Jun 29, 2015 1:42 pm

Hi,

That solved the problem, thanks!

liuzihui
 
Posts: 2
Joined: Wed Apr 08, 2015 2:24 am

Tue Jun 30, 2015 1:15 am

Hello,

Thanks for your feedback. Please feel free to contact us if you have any questions.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.Presentation