Issue with ChartObject height - values get changed

Hi,

I am displaying the excel chart object on word builder. Since the chart dimensions is more,
I am setting the width and height for the chart object.
Ex: myChart.ChartObject.Height = 300;
myChart.ChartObject.WidthInch = 6.75;

wordBuilder.InsertImage(myChart.ToImage());

When the graph is displayed on word, the values on y axis seem to be wrong in some scenarios.

Ex: If the chart object has the below values on y axis,
0, 10,000 20,000 30,000 40,000 50,000 60,000 70,000 80,000 90,000

In the Word report, the graph has the below values
0, 20,000 40,000 60,000 80,000 100,00(instead of 100,000)

I dont understand why the value is changed to 100,00 instead of 100,000?

Waiting for the reply

Thanks,
Sharanya

Hi,


Thank you for your comments.

Can you please elaborate your query and let us know which version of Aspose.Cells are you using? We recommend you to download and use this latest fix of Aspose.Cells for .NET v7.2.1.6. It will be more helpful for us if you can share your source excel file and source code that you are using to achieve this. If you can also accompany your reply with the help of some screenshots, it will be easy for us to reproduce the issue.

Hi,

Thanks for your posting and using Aspose.Cells for .NET

Please download and try the latest version:
Aspose.Cells
for .NET v7.2.1.6
and let us know your feedback.

We will need your sample project creating a chart to look into this issue.

Please note:

If the chart’s image is created fine, but changing its dimension on wordBuilder.InsertImage() method, then it is the issue of Aspose.Words and not the issue of Aspose.Cells.


Hi,

Thank you for the quick reply. With the version v7.2.1.6 also, the issue still persists.
Attched chart.png is the chart used for adding to word doc.

The code I used is:

myChart.ChartObject.Height = 300;
myChart.ChartObject.WidthInch = 6.75;
myChart.ValueAxis.TickLabels.NumberFormat = “#,##0”;

wordBuilder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
wordBuilder.InsertParagraph();
wordBuilder.MoveTo(wordBuilder.CurrentParagraph.PreviousSibling);
wordBuilder.InsertImage(myChart.ToImage());
wordBuilder.InsertParagraph();
wordBuilder.MoveTo(wordBuilder.CurrentParagraph);

Attached wordReport.png is the word doc generated with the graph. You can see the value “100,00” instead of "100,000"

Thanks a lot
Sharanya

Hi,


Thanks for your feedback.

Can you please export and save your chart as an image using Chart.toImage method, and show us that bitmap. This will show us if the intermediate chart is generated fine or not, and we can figure out the issue. You can follow this link for sample code of exporting chart to image.

Hi,

Attached is the image that is generated by mychart.toImage() method. Hope this helps you

Thanks,
Sharanya

Hi Sharanya,


Thank you for providing us the supporting image file.

To replicate the issue at our end and forward it to our development team, Please provide us your full sample test project that we could run at our end and investigate the issue. We would also like to hear from you if you are trying to add the image as an OLE object or as a Picture. We appreciate your cooperation in this regard.

Hi,

Attached is the application and the input files.
I am converting the excel chart to image by chart.toImage() method and then then adding this image to the word document.

Please let me know if you need any information in this regard and also I would like to mention that it s bit urgent as we have production release next week

Thanks for understanding

-Sharanya

Hi,


Thanks for your supporting files and please accept my apologies for delayed response. I was able to reproduce the issue with your input Excel file using the following lines of code:

//Open the workbook
Workbook myWorkbook = new Workbook(“J:\chart.xlsx”);

//Obtain the chart from the first worksheet
Chart myChart = myWorkbook.Worksheets[0].Charts[0];

//Set the height of the chart
myChart.ChartObject.Height = 300;

//Set the width of the chart
myChart.ChartObject.WidthInch = 6.75;

//Format value and Category Axis as required
myChart.ValueAxis.TickLabels.NumberFormat = “#,##0”;
myChart.CategoryAxis.TickLabels.RotationAngle = 45;

//Export the image for testing
myChart.ToImage(“E:\chart.png”, System.Drawing.Imaging.ImageFormat.Png);

//Save the workbook as well for testing
myWorkbook.Save(“E://chartOutput.xlsx”);

The issue can be observed as in the attached chart.png file. I have also saved the workbook for testing purpose and found that inside the workbook, chart is fine after resizing.

I am forwarding this issue to our development team for further investigation and have also logged your additional comments in our database. We will update you once we get any information regarding this issue from our development team. The issue has been logged as: CELLSNET-40726.

Hi,


We have fixed the bug that the maximum scale of y axis is wrong.


Please download and try the latest fix: Aspose.Cells for .NET v7.2.1.7

Thank you very much for the library. That fixed my issue.



I have one more doubt. Please refer my earlier input files attachment.

You can see that the values on y axis are numbers(chart.xlsx). When I put it into word, the format of the number is in decimal. So I had to give the number format “#,##0” explicitly.

Cannot figure out why the the numbe format is not taken by word

Again, Thank you so much. Waiting for your reply

-Sharanya


Hi Sharanya,

Thank you for your feedback.

If the display/export using Aspose.Cells is fine now, then it’s not an issue at Aspose.Cells end. This seems to be something related to Aspose.Words. I think you are embedding the chart as an image using Word, is it so?

Hi,

Export is fine only if I give the number format “#,##0”. Please find attached ConsoleApplication1.zip which has the complete code to replicate the issue.
Also, find Inputfiles.zip which has the input files

Please let me know if you need anything from me.

Thanks a lot,
Sharanya

Hi,


Thank you for providing the supporting material. We will get back to you after looking into these.

Hi,


After further investigation, we find that it is not an issue. In order to achieve a particular number format, you have to set the number format explicitly. If you see in the intermediate exported chart image, the numbers are displayed normally (without any format) if you don’t set the number format. The same image is included in the Word and you see the Y-Axis values in plain number format. So, I think its necessary that you set the number format according to your needs before using it. You can also observe this thing in MS-Excel if you insert a very simple column chart and observe the Y-Axis values format. I have attached a reference Screenshot for this purpose, where I have created a simple column chart in Excel.
sharanya:
Hi,

Export is fine only if I give the number format "#,##0". Please find attached ConsoleApplication1.zip which has the complete code to replicate the issue.
Also, find Inputfiles.zip which has the input files

Please let me know if you need anything from me.

Thanks a lot,
Sharanya
Hi,

I have looked into your issue and found you are using older version. Please download and use the latest version: Aspose.Cells for .NET v7.2.1.9 It is working fine

Please see the code below as you can see the generated chart image is fine. The number format is appearing fine on Y-axis.

I have extracted the code from your console application project.

C#

string filePath = @"F:\Shak-Data-RW\Downloads\Inputfiles\chart.xlsx";

Workbook workbook = new Workbook(filePath);

Worksheet worksheet = workbook.Worksheets[0];

Chart myChart = worksheet.Charts[0];

myChart.ChartObject.Height = 300;
myChart.ChartObject.WidthInch = 6.75;

myChart.CategoryAxis.TickLabels.RotationAngle = 45;

myChart.ToImage(filePath + ".out.png", System.Drawing.Imaging.ImageFormat.Png);

Hi,

If you observe in my attached chart.xlsx, there is a number format([=0]0;[<10]0.0#;#,##0). So the numbers are displayed as comma separated values.
But my intermediate exported chart image has the y axis values as decimal format. My understanding is that it has to be in comma separated format.
Please correct me if I am wrong

Thanks,
Sharanya

Hi,

Could you please fix the above image (chart.xlsx.out.png) using Ms-Paint and attach it here.

It will help us quickly sort out your issue.

Hi,

Thank you so much. This solved my problem. I hope this build also has the fix for my earlier problem(problem is mentioned in the earlier posts in the same thread). ie.,
If the chart object has the below values on y axis,
0, 10,000 20,000 30,000 40,000 50,000 60,000 70,000 80,000 90,000

In the Word report, the graph has the below values
0, 20,000 40,000 60,000 80,000 100,00(instead of 100,000)

I get this kind of report very rare. So cannot produce at my end.

Thanks a lot,
Sharanya

Hi,

It’s good to know your problem is resolved.

If you find any other problem or have some unanswered questions, please feel free to post.

We will help you asap.