Accepted answer

add viewportsize and zoomfactor in your phantomjs page:

await'viewportsize', { height: 1600, width: 3600 });
await'zoomfactor', 4);

and add in your html head template

  window.devicepixelratio = 4;


i can confirm that the @devtrong response is working with phantomjs 2.1.1

the only difference is that i set in my settings file:

    page.viewportsize = { width: 3600, height: 1600 };
    page.zoomfactor = 4;

note: its very important to set in you html this part:

  window.devicepixelratio = 4;
<//script> (fix the script tag)


chart.js now has the parameter "devicepixelratio". this allows you to increase the resolution directly in chart.js. (normal 96dpi. target 300dpi; 300/96 = 3.125)

      devicepixelratio: 3



try setting the zoom factor using a higher dpi for paper in relation to screen dpi:

page.zoomfactor = 300 / 96;   // or use / 72

must be set after page size is defined.

you could also check out this answer:
poor quality of png images drawn into html canvas


for phantom 2, i rendered the charts with a large canvas to get the resolution up and then converted it into a png finally destroying and removing the old canvas and replacing them with an image with responsive css classes. adjusting the knobes on the canvas width and height in addition to chart.js options will get you a perfect render. we were able to get our rendering speed up with the approach (alternative to svg renders) and the file size down.


<div class="container">
  <!-- generated images -->
  <img id="someidimage" class="img-responsive"></img>

  <!-- temporary canvas -->
  <canvas id="someid" width="2000" height="600"></canvas>    


 * _plot() plot with chart.js
 * @param {function} callback
 function _plot(callback) {
  var config = {}; // some chart.js config
  var id = 'someid';
  var el = document.queryselector('#' + id);
  var el2d = el.getcontext('2d');

  // plot instance
  var instance = new chart(el2d, config);

  // generate and append image
  document.queryselector('#' + id + 'image').setattribute('src', el.todataurl('image/png'));

  // destroy instance

  // callback
  if (callback) {

Related Query

More Query from same tag