Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Aug 24, 2022 1:02 pm

Hi,

I created a chart in Spire.XLS and saved it as an image.
The resulting image is different from the one shown in the Excel file: the legend has inverted the order, and now the second series is listed first:
screenshot spire.png
screenshot spire.png (154.69 KiB) Viewed 2024 times

I did a few tests, and found out that the problem only occurs when the second series does not use the primary axis.

Here is the code:
Code: Select all
        int count = 10;

        Workbook workbook = new Workbook();
        workbook.CreateEmptySheets(1);

        Worksheet sheet = workbook.Worksheets[0];

        Chart chart = sheet.Charts.Add(ExcelChartType.ScatterLine);
        chart.DataRange = sheet.Range[2, 1, count + 2, 1];
        chart.SeriesDataFromRange = false;
        chart.Legend.Position = LegendPositionType.Top;

        chart.LeftColumn = 5;
        chart.TopRow = 2;
        chart.RightColumn = 13;
        chart.BottomRow = 22;

        sheet.Range[1, 1].Value = "X";
        sheet.Range[1, 2].Value = "Y1";
        sheet.Range[1, 3].Value = "Y2";

        for (int i = 0; i < count; i++)
        {
            sheet.Range[(i + 2), 1].NumberValue = i;
            sheet.Range[(i + 2), 2].NumberValue = i * i;
            sheet.Range[(i + 2), 3].NumberValue = i + 3;
        }

        chart.PrimaryCategoryAxis.Title = "X";

        chart.Series[0].Name = "Y1";
        chart.Series[0].CategoryLabels = sheet.Range[2, 1, count + 1, 1];
        chart.Series[0].Values = sheet.Range[2, 2, count + 1, 2];
        chart.Series[0].UsePrimaryAxis = true;

        chart.Series.Add();

        chart.Series[1].Name = "Y2";
        chart.Series[1].CategoryLabels = sheet.Range[2, 1, count + 1, 1];
        chart.Series[1].Values = sheet.Range[2, 3, count + 1, 3];
        chart.Series[1].UsePrimaryAxis = false; //if this line is commented, the problem goes away

        //Save and Launch Excel
        workbook.SaveToFile("chart.xlsx");

        Image image = workbook.SaveChartAsImage(sheet, 0);
        image.Save("chart.png", ImageFormat.Png);


Thanks for the support,

Francesco

f.mazzurco
 
Posts: 12
Joined: Thu Aug 30, 2018 7:57 am

Thu Aug 25, 2022 9:11 am

Hello f.mazzurco,

Thanks for your inquiry.
I did reproduce your problem. I have logged the issue into our bug tracking system with the ticket SPIREXLS-4098. Our Dev team will do more investigations to fix it. Once there is any update, I will inform you asap. Sorry for the inconvenience caused.

Sincerely,
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Fri Oct 21, 2022 1:36 am

Hello,

Thanks for your patience!
Glad to inform you that we just released Spire.XLS Pack Version:12.10 which fixes the issue with SPIREXLS-4098. Please download the new version from the following links to test.
Website download link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget download link: https://www.nuget.org/packages/Spire.XLS/12.10.1

Sincerely,
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Thu Oct 27, 2022 10:45 am

Hi,

I tried the hotfix and indeed it solves the problem.
However, in the meantime our 1-year period of free hot fixes has expired.
It does not seem fair that I am forced to renew my license to get the fix for a bug that I reported before expiration.

Can I be contacted by your sales team?

Thanks,

Francesco

f.mazzurco
 
Posts: 12
Joined: Thu Aug 30, 2018 7:57 am

Fri Oct 28, 2022 7:58 am

Hello,

Thanks for your feedback.
Our sales team has sent an email to your email address to solve your problem, please note that check.

Sincerely,
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Return to Spire.XLS