ToImage() and Palette

Hi Cruz,

Please post your created image file and excel file with the following codes :

Workbook workbook = BuildPieChart();
Bitmap bitmap = workbook.Worksheets[1].Charts[0].ToImage();
bitmap.Save(@"PieChart.bmp");
workbook.Save(@"PieChart.xls");

Hi, Warren, sorry for the delayed reply, I’ve been taking care of other issues.

So, I posted the files you wanted. You asked for the PieCharts but my problem concerns the StackedColumnCharts, so just to be sure, I’ve posted both bmp and excel files for both types of charts.

Thanks,
Cruz

Hi Cruz,

I have attached the created image. There's the problem with pie chart. We will check it.

But i could find the problem of the stacked column chart with template file.
Workbook workbook = new Workbook();
workbook.Open("F:\\FileTemp\\StackedColumnChart.xls");

Bitmap bitmap = workbook.Worksheets[1].Charts[0].ToImage();
bitmap.Save("F:\\FileTemp\\StackedColumnChart.bmp", System.Drawing.Imaging.ImageFormat.Bmp);

I think you forgot to attach the image, Warren. :slight_smile:

Hi,

Sorry for my mistake.

Humm, that’s odd… can you send me your latest version of Aspose.Cells? Maybe that’s the problem…

Please try this one.

Ok, this is very weird… I take the same excel file I sent you, use the latest Aspose.Cells version you sent me, execute the exact same piece of code you posted and I still get the problem with the StackedColumnsChart. Do you have anymore ideas?

Hi,

Could you remove all reference for Aspose.Cells,then re-refer to the Aspose.Cells you download from previous post? I think you are using the old version.

I tried it already, still isn’t working…

I was thinking that maybe the problem was the reference I had to Aspose.Chart, but I removed it from the project and all remained the same.

Ah!! Finally I uncovered the bug! :stuck_out_tongue:

It’s a matter of values, that’s why you couldn’t find the problem…

Please try to generate stacked column charts with the code I previously sent you, passing the following data tables:

Test 1:
DataTable table = new DataTable();
DataColumn dc;
for (int i = 0; i < 13; i++)
{
dc = new DataColumn();
table.Columns.Add(dc);
}

table.Rows.Add(new object[] { “”, “Jan”, “Fev”, “Mar”, “Abr”, “Mai”, “Jun”, “Jul”, “Ago”, “Set”, “Out”, “Nov”, “Dez” });
table.Rows.Add(new object[] { “Cinema”, 0, 0, 8847, 214798, 81784, 0, 0, 0, 0, 0, 0, 0 });

This test works fine, the ToImage method returns a perfect bmp of the chart.

Now Test 2:
DataTable table = new DataTable();

DataColumn dc;

for (int i = 0; i < 13; i++)

{

dc = new DataColumn();

table.Columns.Add(dc);

}



table.Rows.Add(new object[] { “”, “Jan”, “Fev”, “Mar”, “Abr”, “Mai”, “Jun”, “Jul”, “Ago”, “Set”, “Out”, “Nov”, “Dez” });

table.Rows.Add(new object[] { “Cinema”, 0, 0, 8847, 214798.1, 81784, 0, 0, 0, 0, 0, 0, 0 });

Notice the values are exactly the same, except the one highlighted in bold. To this value I added 0.1. The ToImage method now returns a different image of the chart. Notice the scale on both images and you’ll see that the simple addition of 0.1 units to the maximum chart value altered the scale of the image. Different values of the decimal places in the maximum value will cause different results. I think that this only happens if the maximum value of the series has decimal places. If you remove them from the greater value but place them in any other value, the scale comes out right.

Can you check this bug and report back to me?

Thanks in advance,
Cruz

Hi Cruz,

Thanks for the details,

We will check and get back to you soon.

Thank you.

Hi,

Can you give a simple excel file like the attachment. Having the file we will figure out the issue soon.

Hi, roger. That file you attached is a perfect example.

If you do this:

Workbook book = new Workbook();
book.Open(“c:\ttt.xls”);
Bitmap bmp = book.Worksheets[0].Charts[0].ToImage();
bmp.Save(“c:\test.bmp”);


Then the result will be the attached image.

If you remove the decimal place in that greater value, the resulting image will be perfect.

Nevertheless, here’s a sample project that creates a workbook from scratch with some sample data, with a chart sheet and then saves a bmp file with the toImage.

Just run it and check the output files

Hi,

It's so strange. Please see the result created with you sample project in my machine.

Please post your created excel file and image file. Please print the value of Cell E3 before you call chart.Tomage() and post here.

I think the bug is caused by sheet.Cells[r, c].PutValue(double.Parse(row[c].ToString())). Please check the value double.Parse(row[4].ToString()). I guess that it do not return 214798.1.

Ok, Warren, here’s what you asked. I totally agree this is very strange… I was reading your post and began thinking if it is a problem with the locale… you see, I’m from Portugal and our decimal characters and such things are different. Also noticed that when I open your result workbook in my office (which by the way is office 2007), i notice that the character “á” in the sheet name appears with a different encoding but okay, that’s normal.

I’m posting you the result sheet created with the exact same code I previously sent you, the resulting toImage and a screencap of the debug, with the value of the E3 cell, using Cell[“E3”].Value to view the value, which is an object containing 214798.1000000000001. Do you think this it?

Also, double.Parse(row[4].ToString()) returns the correct value 214798.1

Thanks for all the attention,
Cruz

Hi Cruz,

Please try this fix.

It's caused by local environment. We have fixed this bug.

Ha! It’s perfect! Thanks Warren. The problem was caused by the difference between our thousands separator and the decimal separator, right? The location is always a tricky issue…

Thanks again!
Cruz

Hi Cruz,

Yes. It's caused by the decimal separator.