Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

charts printed using am5 library appear blurry in the PDF #1605

Closed
nitinsdev01 opened this issue Jul 8, 2024 · 15 comments
Closed

charts printed using am5 library appear blurry in the PDF #1605

nitinsdev01 opened this issue Jul 8, 2024 · 15 comments
Labels
enhancement Feature request

Comments

@nitinsdev01
Copy link

nitinsdev01 commented Jul 8, 2024

Using below code with exporting library (https://cdn.amcharts.com/lib/5/plugins/exporting.js), we are getting blurry charts in PDF that is being printed using aspose. Can we do something to get better quality charts in PDF as UI. @martynasma Please suggest.

for (let i = 1; i <= 3; i++) {
try {
var divId = 'chartdiv' + i;
var root = eval('root' + 1);
var exporting = amSplugins_exporting.Exporting.new(root, {
pngOptions: {
quality: 0.8,
maintainPixelRatio: true
}
});
promise.push(exporting.export("png"));
var node = $("#" + divId)[0];
var elem = $("< img/>")[0];
elem.id = "img" + divId;
node.appendChild(elem);
}
catch (e) { }
}

@martynasma
Copy link
Collaborator

You may set quality to a higher number:
https://www.amcharts.com/docs/v5/concepts/exporting/exporting-images/#Image_quality

Also upscale the size using minWidth and minHeight settings:
https://www.amcharts.com/docs/v5/concepts/exporting/exporting-images/#Sizing_exported_image

@nitinsdev01
Copy link
Author

nitinsdev01 commented Jul 15, 2024

You may set quality to a higher number: https://www.amcharts.com/docs/v5/concepts/exporting/exporting-images/#Image_quality

Also upscale the size using minWidth and minHeight settings: https://www.amcharts.com/docs/v5/concepts/exporting/exporting-images/#Sizing_exported_image

I tried the suggested solutions, however It didn't worked and charts are still printing blurry. Adding the code below for reference:

for (let i = 1; i <= 3; i++) {
try {
var divId = 'chartdiv' + i;
var root = eval('root' + 1);
var exporting = amSplugins_exporting.Exporting.new(root, {
pngOptions: {
quality: 1, //tried 2,3 and 5 too
minWidth: 1000, //tried width: am5.p100 too
maxWidth: 2000
}
});
promise.push(exporting.export("png"));
var node = $("#" + divId)[0];
var elem = $("< img/>")[0];
elem.id = "img" + divId;
node.appendChild(elem);
}
catch (e) { }
}

@martynasma
Copy link
Collaborator

The next thing to try is enabling pixel ratio:
https://www.amcharts.com/docs/v5/concepts/exporting/exporting-images/#Pixel_ratio

@nitinsdev01
Copy link
Author

Used this one as well, still getting blurry charts in PDF.

@martynasma
Copy link
Collaborator

Is perhaps your source chart very small in size?

@nitinsdev01
Copy link
Author

No charts are not small in size, charts are given width of parents div which is 100% of container.
In above sample code we have mentioned that too. PFB line below for reference

minWidth: 1000, //tried width: am5.p100 too

Here p100 states for 100 percent of parent div

@martynasma
Copy link
Collaborator

minWidth and related settings accept only absolute values, so percent ones won't work.

Try setting both minWidth and minHeight to even higher values.

@nitinsdev01
Copy link
Author

nitinsdev01 commented Jul 30, 2024

Tried 1000, 1500 and even 2000 but that didn't made quality of the charts any better.

Can we print charts as canvas elements itself using am5 ?

When we are using am4, we get SVG in UI and are able to convert to high quality images in print version. However there is no such method available for printing canvas version in am5 as is with high quality.

@martynasma

@abhay-jain03
Copy link

abhay-jain03 commented Aug 5, 2024

@martynasma I am also getting same issue. Even, I had tried to export canvas/svg using the above code for downloading pdf which use aspose library.

`
var promise = [];
for (let i = 1; i <= 3; i++) {
try {
var divId = 'chartdiv' + i;
var root = eval('root' + 1);
var exporting = amSplugins_exporting.Exporting.new(root, {
canvasOptions: {
quality: 0.8,
maintainPixelRatio: true
}
});
promise.push(exporting.export("canvas"));
var node = $("#" + divId)[0];
var elem = $("< canvas/>")[0];
elem.id = "img" + divId;
node.appendChild(elem);
}
catch (e) { }
}

Promise.all(promise).then(function (values) {
var count = 0;
for (let j = 1; j <= 3; j++) {
var nod = $("#chartdiv" + j)[0];
if (nod) {
var imgNode = $("#imgchartdiv" + j)[0];
if (imgNode) {
$("#imgchartdiv" + j).insertAfter(values[count]);
count++;
}
}
}
})

`

@habu23183
Copy link

@martynasma Even i am facing same issue.

@prachi7049
Copy link

prachi7049 commented Aug 5, 2024

@martynasma Experiencing the same issue at my end as well, PDF generated via aspose is not clear enough

@martynasma
Copy link
Collaborator

OK, so here's a very small test case:
https://codepen.io/team/amcharts/pen/zYVzNpX/33f29eb2ab1b0e0018982aea995ad496?editors=0010

It has two small charts:

  1. The first one exports PDF blurry.
  2. The second has minWidth: 2000 set so PDF exports crisp.

Do you have the same results?

image
image

@nitinsdev01
Copy link
Author

Using minWidth: 2000 helped to generate better quality, however the file size almost got double.
Reducing minWidth to even 1900 or 1800 reduces the size but quality as well. Is there any new code update in amcharts5 (in comparison with amcharts4) where we can reduce the file size without hampering quality of charts.

@martynasma
Copy link
Collaborator

Perhaps we can add a PDF setting to not try and fit the image into the width of the page.

This would solve the bullriness issue as well as size because smaller charts would display smaller, without need to upscale them.

Let us experiment with this a little, and get back to you.

@martynasma martynasma added enhancement Feature request in next release Implemented. Available soon. and removed question labels Aug 6, 2024
@martynasma
Copy link
Collaborator

Fixed in 5.10.1.

[5.10.1] - 2024-08-09

Added

  • fillGradient setting added to Label.

Changed

  • Exporting a PDF will now check image size and will not scale it up to fit page size if it's smaller. It will still scale dowwn the image to fit in the page.

Fixed

  • Memory leak with axis ranges on LineSeries fixed.
  • PieSeries tick was not visible if pie had two equal slices.
  • root.nonce was not being added to all dynamically-loaded stylesheets.
  • A stack overflow could occur when auto-zooming a ValueAxis in some very rare cases.

Full change log.

Download options.

Make sure you clear your browser cache after upgrading. And feel free to contact us again if you are still experiencing this issue.

@martynasma martynasma removed the in next release Implemented. Available soon. label Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request
Projects
None yet
Development

No branches or pull requests

5 participants