question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pie chart looks weird

See original GitHub issue

testimage This is what I get when trying to get a pie chart. The code:

var chartJsOptions = {
  type: 'pie',
  data: {
    datasets: [
      {
        data: [10, 10, 20, 30, 40],
        backgroundColor: ['red', 'orange', 'yellow', 'green', 'blue'],
        label: 'Dataset 1'
      }
    ],
    labels: ['Red', 'Orange', 'Yellow', 'Green', 'Blue']
  },
  options: {}
};

var chartNode = new ChartjsNode(800, 600);
return chartNode
  .drawChart(chartJsOptions)
  .then(() => {
    // chart is created

    // get image as png buffer
    return chartNode.getImageBuffer('image/png');
  })
  .then(buffer => {
    Array.isArray(buffer); // => true
    // as a stream
    return chartNode.getImageStream('image/png');
  })
  .then(streamResult => {
    // using the length property you can do things like
    // directly upload the image to s3 by using the
    // stream and length properties
    streamResult.stream; // => Stream object
    streamResult.length; // => Integer length of stream
    // write to a file
    return chartNode.writeImageToFile('image/png', './testimage.png');
  });```

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SeanLMcCulloughcommented, Nov 13, 2017

I’ve found a temporary workaround.

It seems the problem has to do with the math relating to chart.js finding the inner circumference of the pie chart arcs. You can see in the example at the start of this thread that it’s giving up on rendering the arc origin.

What you can do, is set a really tiny number for the cutout percentage to trick the math into doing something. Tested under Windows 10 and Server 2016

var chartJsOptions = {
	type: 'pie',
	data: {
		datasets: [{
			data: [10, 10, 20, 30, 40],
			backgroundColor: ['red', 'orange', 'yellow', 'green', 'blue'],
			label: 'Dataset 1'
		}],
		labels: ['Red', 'Orange', 'Yellow', 'Green', 'Blue']
	},
	options: {
		cutoutPercentage: 0.00000001
	}
};
0reactions
SeanLMcCulloughcommented, Nov 13, 2017

Can confirm, Windows 10 results in the same issue. My chart config works on the test website.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The issue with pie chart - From data to Viz
Bad by definition ... A pie chart is a circle divided into sectors that each represent a proportion of the whole. It is...
Read more >
38 Hilarious Pie Charts That Are Absolutely True - Bored Panda
But take a look at this list, compiled by Bored Panda, for a totally different type of pie chart. Whether exposing the truth...
Read more >
My pie chart does not reflect the correct percentage (excel)
A pie chart shows (when % is chosen) sections whose total area is 100%, and each section's area is a relative portion of...
Read more >
A Complete Guide to Pie Charts | Tutorial by Chartio
Pie charts are a common but often misused visualization to show division of a whole into parts. Learn how to get the most...
Read more >
Weird pie charts on R using ggplot - Stack Overflow
I am struggling to represent some of my data as a pie chart. The pie chart is not circular, but rather comprised of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found