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.

Thu Sep 23, 2021 11:13 am

Hi,

Following this tutorial...
"How-to-Create-a-Combination-Chart-in-Excel-in-C-VB.NET"

When saving chart to image using [chart.SaveToImage("result.png");] the chart appears different to the chart that is in excel (line marker series goes to the back of the column series).

How can I achieve the same chart/look in the image as it appears in excel?

Thanks
Attachments
result.png
result.png (11.87 KiB) Viewed 4397 times

Ish_techedge
 
Posts: 13
Joined: Thu Sep 23, 2021 10:30 am

Fri Sep 24, 2021 3:19 am

Hello Ismail,

Thanks for your feedback.
I have noticed the issue, and logged it into our issue tracking system with the ticket SPIREXLS-3461. Sorry for the inconvenience caused. We will notify you once it is resolved.
Feel free to contact us if you have any issues.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Sep 27, 2021 9:07 am

Thanks for your reply.

FYI, issue also exists when saving to stream...

chart.SaveToImage(stream)
or
stream = workbook.SaveChartAsImage(sheet, 0);

Ish_techedge
 
Posts: 13
Joined: Thu Sep 23, 2021 10:30 am

Mon Sep 27, 2021 9:21 am

Yes, I also found that. Thanks for your notice.

Have a nice day!
Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu Nov 04, 2021 9:54 am

Hi,

Any update on this issue resolution?

Also found that saving the chart several times eventually causes an error...

"Object reference not set to an instance of an object."

Other errors I've come across
"Unable to allocate pixels for the bitmap."
"Parameter is not valid."

for (int i = 0; i < 10; i++)
{
ch.SaveToImage(@"c:\tmp\result" + i.ToString() + ".png");
/*
MemoryStream msChart = new MemoryStream();
ch.SaveToImage(msChart);
msChart.Dispose();
*/
}

Is there a workaround to resolve this?

Thanks

Ish_techedge
 
Posts: 13
Joined: Thu Sep 23, 2021 10:30 am

Thu Nov 04, 2021 10:11 am

Hello Ismail,

Thanks for your inquiry.
SPIREXLS-3461 just has been fixed. Next, our test team will build a new version and test the fix. When new version is released, I will inform you.
For the new issue, I will do an investigation and get back to you.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Nov 05, 2021 1:45 am

Hello Ismail,

For new issue, I did a test according to your description, but did not reproduce it. I am using Spire.XLS Pack(Hotfix) Version:11.10.5. If you don't use the version, please have a try.
Here is my test code:
Code: Select all
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("data.xlsx");
            Worksheet sheet = workbook.Worksheets[0];

            //add a chart based on the data from A1 to D5
            Chart chart = sheet.Charts.Add();
            chart.DataRange = sheet.Range["A1:D5"];
            chart.SeriesDataFromRange = false;

            //set position of chart
            chart.LeftColumn = 6;
            chart.TopRow = 1;
            chart.RightColumn = 12;
            chart.BottomRow = 13;

            //apply different chart type to different series
            var cs1 = (ChartSerie)chart.Series[0];
            cs1.SerieType = ExcelChartType.ColumnClustered;
            var cs2 = (ChartSerie)chart.Series[1];
            cs2.SerieType = ExcelChartType.ColumnClustered;
            var cs3 = (ChartSerie)chart.Series[2];
            cs3.SerieType = ExcelChartType.LineMarkers;

            //add a secondary axis to chart
            chart.SecondaryCategoryAxis.IsMaxCross = true;
            cs3.UsePrimaryAxis = false;


            for (int i = 0; i < 10; i++)
            {
                chart.SaveToImage(@"D:\result\" + i.ToString() + ".png");
                /*
                MemoryStream msChart = new MemoryStream();
                ch.SaveToImage(msChart);
                msChart.Dispose();
                */
            }



Sincerely,
Amy
E-iceblue support team
Attachments
data.zip
(5.63 KiB) Downloaded 262 times
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Nov 05, 2021 3:23 pm

Hi Amy.

I have tried with Spire.XLS Pack(Hotfix) Version:11.10.5.

The problem still exists for me... I tested the code in a web api project.

It always seems to be on the 5th attempt call to "chart.SaveToImage" that it crashes with an error:

Message: "Object reference not set to an instance of an object."
Source: Spire.XLS (or sometimes Spire.PDF even though this is not installed or being used).

Thanks

Ish_techedge
 
Posts: 13
Joined: Thu Sep 23, 2021 10:30 am

Mon Nov 08, 2021 2:22 am

Hi Ismail,

Thanks for your feedback.
I created a web api project and did a test, but still didn't replicate your issue. In order to help me replicate and investigate it, could you please share your web api project? You could upload the file to the DropBox or OneDrive and then share the download link with us.

Thank you for your assistance in advance.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Nov 15, 2021 3:27 pm

Hi Amy,

Please find web api project in link below

https://1drv.ms/u/s!ApEtJtXHPmzjhCi39VZHEYcfqMV5?e=oIkfXY

API call: "https://localhost:portnumber/api/spire"

Hopefully you will be able to replicate the error I'm getting.

Thanks

Ish_techedge
 
Posts: 13
Joined: Thu Sep 23, 2021 10:30 am

Tue Nov 16, 2021 10:24 am

Hi Ismail,

Thanks for your sharing your project.
Unfortunately, I failed to run your project and it threw the below error. I tried to find some help online, but nothing worked. I will continue to manage to solve it so that I can run your project and reproduce your issue successfully.
error.png
error.png (23.58 KiB) Viewed 3115 times


I will keep you updated on it.

Sincerely,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Nov 16, 2021 12:30 pm


Ish_techedge
 
Posts: 13
Joined: Thu Sep 23, 2021 10:30 am

Wed Nov 17, 2021 9:11 am

Hi Ismail,

Thanks for your assistance.
I have run your project successfully by installing dotnet-hosting-2.2.8-win.exe and changing <Platforms>AnyCPU;x86</Platforms> to <Platforms>AnyCPU</Platforms>.
I still did not reproduce your issue. The process completed without any error and all output images were fine.

What's your OS environment? If it is 32bit, could you please do a test in a 64bit OS?

Sincerely,
Amy
E-iceblue support team
Attachments
run successfully.png
run successfully.png (10.85 KiB) Viewed 3070 times
output.png
output.png (28.65 KiB) Viewed 3070 times
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Nov 17, 2021 10:19 am

Hi Amy,

My OS environment is 64bit, Visual Studio Pro 2017.
Attachments
ProjRef.png
Project references
ProjRef.png (21.47 KiB) Viewed 3068 times
AnyCPU.png
Platform: AnyCPU
AnyCPU.png (23.58 KiB) Viewed 3068 times
x86.png
Platform: x86
x86.png (33.17 KiB) Viewed 3068 times

Ish_techedge
 
Posts: 13
Joined: Thu Sep 23, 2021 10:30 am

Thu Nov 18, 2021 6:51 am

Hi Ismail,

Thanks for your reply.
I installed a Visual Studio Pro 2017 and ran your project again. But I still ran successfully. My OS environment is Windowns 10 64bit.
Do you have this issue when running on all your computers?

Sincerely,
Amy
E-iceblue support team
Attachments
OS environment.png
OS environment.png (22.59 KiB) Viewed 3046 times
VS2017 run successfully.png
VS2017 run successfully.png (42.1 KiB) Viewed 3046 times
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.XLS

cron