How to create a pie chart in presentation

I am referring to the bar chart code to create a pie chart but i am getting error I have made some modifications

     using GemBox.Presentation;
     using spreedsheetCharts =  GemBox.Spreadsheet.Charts;
     using spreedsheet =  GemBox.Spreadsheet;

     // Add new PowerPoint presentation slide.
     // If using the Professional version, put your GemBox.Presentation serial key below.
    ComponentInfo.SetLicense("FREE-LIMITED-KEY");

    // If using the Professional version, put your GemBox.Spreadsheet serial key below.
    SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

        var firstLastSlidesPresentation= new PresentationDocument();

        var slide = firstLastSlidesPresentation.Slides.AddNew(SlideLayoutType.Custom);

        // Add simple PowerPoint presentation title.
        var textBox = slide.Content.AddTextBox(ShapeGeometryType.Rectangle,
            116.8, 20, 105, 10, GemBox.Presentation.LengthUnit.Millimeter);

        textBox.AddParagraph().AddRun("New presentation with chart element.");

        // Create PowerPoint chart and add it to slide.
        var chart = slide.Content.AddChart(GemBox.Presentation.ChartType.Bar,
            49.3, 40, 240, 120, GemBox.Presentation.LengthUnit.Millimeter);

        // Get underlying Excel chart.
        spreedsheetCharts.ExcelChart excelChart = (spreedsheetCharts.ExcelChart)chart.ExcelChart;
        spreedsheet.ExcelWorksheet worksheet = excelChart.Worksheet;

        // Add data for Excel chart.
        worksheet.Cells["A1"].Value = "Name";
        worksheet.Cells["A2"].Value = "John Doe";
        worksheet.Cells["A3"].Value = "Fred Nurk";
        worksheet.Cells["A4"].Value = "Hans Meier";
        worksheet.Cells["A5"].Value = "Ivan Horvat";

        worksheet.Cells["B1"].Value = "Salary";
        worksheet.Cells["B2"].Value = 3600;
        worksheet.Cells["B3"].Value = 2580;
        worksheet.Cells["B4"].Value = 3200;
        worksheet.Cells["B5"].Value = 4100;

        // Select data.
        excelChart.SelectData(worksheet.Cells.GetSubrange("A1:B5"), true);
        
        firstLastSlidesPresentation.save("somename.pptx")

error -

‘ExcelChart’ does not contain a definition for ‘Worksheet’ and no accessible extension method ‘Worksheet’ accepting a first argument of type ‘ExcelChart’ could be found (are you missing a using directive or an assembly reference?)

please help me with this issue

Hi Tejas,

What version of GemBox.Spreadsheet are you using?
Can you try again using the current latest version:

Does this solve your issue?

If the problem remains, please send us a small Visual Studio project that reproduces your issue so that we can investigate it.

Regards,
Mario

one quick question, the code is correct right to create a pie chart?

The code will create a bar chart.
For a pie chart you need to use this:

var chart = slide.Content.AddChart(GemBox.Presentation.ChartType.Pie,
    49.3, 40, 240, 120, GemBox.Presentation.LengthUnit.Millimeter);

we cannot use free key for both presentation and spreedsheet in same code? it is giving error

probably you are using old key something like this.

{“The serial key is not valid. You are probably using serial key for an older version of the product. Please renew your license to continue using this version, or use an older version.”}

One more thing, the previous error is gone once i updated the version as you suggested , we were using 41 for spreedsheet and now i have updated to 49

You can use the FREE-LIMITED-KEY in both components. Your error message indicates that you’re using an older license key with the newer version of GemBox.Spreadsheet.

I believe that somewhere you are calling SpreadsheetInfo.SetLicense method with the license key for GemBox.Spreadsheet 4.1, which no longer works when you upgraded to the latest GemBox.Spreadsheet 4.9.

So after upgrading to a new version we will have to buy another key even if the one we bought has time for expiration?

What do you mean by this?

Note that GemBox.Spreadsheet 4.1 has not been supported since 2019.
If you have a newer license then you have a newer serial key that you should be able to use with the newer version of GemBox.Spreadsheet.

To tell you anything for sure, I would suggest you submit a support ticket using the following link:
https://support.gemboxsoftware.com/new-ticket
You can write us your serial key and send us a small Visual Studio project so that we can investigate the exact version of GemBox.Spreadsheet that you’re using.

Hi Mario, thank you for all your support. The issue is fixed with the version related solution you mentioned. If there is anything else I will right it in forum. Thanks again. Appreciate your help.