A pie chart is a circular chart divided into sectors, each sector (and consequently its central angle and area), is proportional to the quantity it represents. Together, the sectors create a full disk.
IndexLabels describes each slice of pie chart. It is displayed next to each slice. If indexLabel is not provided, label property is used as indexLabel.
Cannot be combined with: Any other Chart type.
Applies To | Attribute | Type | Default | Options/Examples |
---|---|---|---|---|
dataPoint | exploded | Boolean | false | false, true |
dataSeries/ dataPoint | explodeOnClick | Boolean | true | false, true |
dataSeries | startAngle | Number | 0 | 30, -45, 140.. |
dataSeries | fillOpacity | Number | 1 | .2,.4,1 etc |
dataPoint | legendText | String | “dataPoint1” | “apple”, “mango”… |
102 Comments
Not working perctly on IE 10.
If i use attributes fontFamily, fontSize, i can see the Pie in IE, but working perfectly on Chrome
Can you please let me know what you mean by “Not working perfectly”. If you can create a jsfiddle that reproduces the problem, it would be helpful.
not showing output
Hi sunil ,
I needed to give my own explicit colours to the pie chart ,how to do that ??
Custom colorSet will let you do the same https://canvasjs.com/docs/charts/chart-options/colorset/
Greetings – Is it possible to replace a color with an image (JPG,GIF, etc.)?
Except for chart background Images are not supported yet..
i am replacing the value of “y” by 0, then why its “indexLabel” is printing… i am taking a dynamic data, and there is possibility that “y” may have value “0”. please any suggestion…
zero is still a value isn’t it?… All graphs display dataPoints with 0 y value. In case you don’t want it to be displayed, you can either remove it from the series or set its indexLabel to empty string “”
yeap, did it by removing the indexLabel thanks Sunil… another thing i want to know, that i have 3-element and when i am giving 2-element value as “0” the tooltips isn’t displaying for the remaining element…
window.onload = function () {
var chart = new CanvasJS.Chart(“chartContainer”,
{
data: [
{
type: “pie”,
dataPoints: [
{ x: 10, y: 0 },
{ x: 20, y: 0},
{ x: 30, y: 50 },
]
}
]
});
chart.render();
}
Thank you so much!
when i have inserted php code and pie chart is 50-50% then one semi circle is smaller than the other. Why?
Sanjeev,
Here is a jsfiddle that I created with two equal slices and its working fine. Can you please recreate the issue so that we can have a look?
it is working fine in your examples but in my file it is giving some error when start angle is 0,90 or 180, in all other angles it is working fine.
Can you please create a jsfiddle with your data and post it in our forum?… We won’t be able to figure out the problem otherwise.
The error is that one semi circle overlaps the part of another semi circle
can i hide some datapoints making a function like this in legend? i would like to filter my pie chart, thanks !
legend:{
cursor:”pointer”,
itemclick: function(e){
e.dataPoint.visible = false;
chart.render();
}
}
Hello.
How can i change dataPoints.y dynamic , for example by clicking some button that change, for example, Y value for first pie part? I am trying, but there is no success.
Thanks!
Hi,
Yes. Here is an example.
Thank you!
Also i have problem with setting 0 to dataPoints.y? The browser fall when y is zero. Is there any feature of fix for this?
Thanks!
Do you mean to say that you want to set all values to zero? We are not sure how a pie chart should be rendered in that case. If not, can you please explain it with a jsfiddle?
Can we make it as semi circle with 3part combination…?
Hi Amal,
As of now, it’s not possible to draw semi-circle.
How I can work with external data? I have http://devamsizlik.kaankolkoy.net/data.php and I want use it.
Hi,
Link which you have provided us is not showing any data. Any in general you need to make an Ajax request for getting your external data and assign that same on the client side. Before assigning you might have to parse the data if needed and convert it to the format required by CanvasJS.
Here is an example.
I would like to slice the chart by clicking on LegendText. I tried by changing the x and y through itemclick() function of Legend but no luck. Is there any possible solution to it?
Thanks
Amer,
By using exploded property of dataPoints you can slice the chart. Here is an example.
Hi,
Thanks for your help. To anyone who’s interested, here is a jsfiddle example to slice the chart by hovering mouse over each legendText item. http://jsfiddle.net/5o1bs619/3/
Regards
Hi, how do I place 2 charts in page? Only 1 shows up when I insert the codes for both charts
Neo,
For doing the same please refer this example.
Hi, i’ve two pie chart near with different dimension. Is it possible to have with the same height?
Alex,
Size of pie charts are automatically calculated and cannot be set via the options.
Is it possible to have a stroke on each pie slice?
Adam,
This feature is not available as of now.
Is it possible to show the sum of all the y values of datapoints in a fixed div, which is not a tool tip but visible always?
Hello,
In the next version (1.7) we have a new element called Subtitle which can be used to do the same. For now you can workaround this by showing the value outside the chart. You can also overlay the same on top of the chart if required.
how to make editable pie chart? for example,if the coding go live, we don’t have to edit the value in html code. we just edit it live-ly. Please help.
Hi guys,
I am facing a problem in implementing these canvas charts. I am getting this error all the time when I execute “chart.render();” line after populating my chart variable dynamically with appropriate data (say for a simple Pie Chart):
Uncaught TypeError: undefined is not a function
and the error is at line:
canvasjs.min.js:84
I have also posted this question on stackoverflow, here is the question:
http://stackoverflow.com/questions/30699356/uncaught-typeerror-in-rendering-canvasjs-chart
Thanks in advance for your time.
PS: I have carefully examined the dataPoints array (it contains data in valid format as required for the pie chart).
Without looking into your data it is not possible to guess the problem so please either create a jsfiddle with your data or post your data (here or on stack-overflow).
Hi, Is it possible to define the color for each index label?
vaibhav,
Yes, you can use indexLabelFontColor property of dataSeries/ dataPoints.
Is it possible to change the color of the border around each pie slice? I want the border to be more defined.
pauline,
Sorry, this feature is not available yet.
Hi Sunil, if the values for datapoints all 0, the pie chart is shown as blank, which may not be very user friendly, need to show some message. is that possible?
Anu,
This is not possible via the chart API. But given that you have access to dataPoints, you can overlay a custom message at your end when there are not dataPonts available.
Pie chart index label does not show for top most part of the pie when index labels to the left and right are too long in length. Please see the image at this link: http://www.mediafire.com/view/ze55zlwh9s0ua2o/Testing.jpg.
Thank you.
Also, here is my data points if it helps. Thanks again!
var chart = new CanvasJS.Chart(‘chartCanvas’, {
animationEnabled: true, animationDuration: 2000,
exportEnabled: true, exportFileName: ‘Testing’,
zoomEnabled: true,
title: { text: ‘Some Long Text String’ },
data: [{ type: ‘pie’, dataPoints: [
{ y: 290, indexLabel: ‘Some Long Text String’ },
{ y: 94, indexLabel: ‘Some Long Text String’ },
{ y: 84, indexLabel: ‘Some Long Text String’ },
{ y: 70, indexLabel: ‘Some Long Text String’ },
{ y: 69, indexLabel: ‘Some Long Text String’ },
{ y: 53, indexLabel: ‘Some Long Text String’ },
{ y: 51, indexLabel: ‘Some Long Text String’ },
{ y: 48, indexLabel: ‘Some Long Text String’ },
{ y: 47, indexLabel: ‘Some Long Text String’ },
{ y: 47, indexLabel: ‘Some Long Text String’ },
]}]}); chart.render(); chart = {};
codepen sample
http://codepen.io/anon/pen/jbOyGv
Hi, how can I show the percentage of each pie sector on top of them? I know I can show them via the tooltip, but that’s another thing.
I found the answer :) Guys, your plugin is awesome.
Thanks. We are glad that you liked our library.. :-)
defaultly pie chart taking dark gray background…but tried to override using backgroundColor: “#ECF0F1”,,,,still dark gray color is appearing…
We are not able to reproduce the issue. Can you please create a jsfiddle for this. So that we can look into it.
I want to create pie charts dynamically using for loop. is it Possible?
Sometimes i need 4 and sometimes i need 5 so i want create using for loop.
Thanks in advance
Do you want to create pie charts dynamically or update datapoints.
Check this jsfiddle which is dynamically creating pie charts.
Also you can refer this jsfiddle which is dynamically generating datapoints.
Thank you its working fine.
I want to indexLabel load image,how to do that ??
This feature is not available yet.
What is wrong with this code?
https://jsfiddle.net/5t3cb0wk/36/
Thanks!
There is nothing wrong with the code. jsfiddle is refer 1.8.0 Beta. Its a bug in Beta version. This will not be there in 1.8.0GA.
I am trying to save the above example code in text file with .HTML extension and trying to open in IE. It’s not displaying any thing.
Can you please explain me how to open the above example in internet explorer(IE).
I have copied the code and save in ‘piechar.html’ file and trying to open it in IE.
Here relative url is used for linking CanvasJS script file. For running it in your localhost, you have to download canvasjs library and link it locally in your HTML file.
If i wanted to give the total count instead of giving % in the pie chart then how it should be done?
You can use keyword “#total” as shown in this example.
Are we able to make pie chart in 3D model?
Moiez Siddiqui
Its not possible to make pie-chart in 3D-model
legendText: “{indexLabel}” is not working.
Naresh,
legendText: “{indexLabel}” is working fine, here is an example.
Hey Guys how can i display the % or text inside the chart,Instead when you mouse over the chart or when cursor pointer displaying the text.
Hi Reena,
You can use indexLabel: “#percent” to show the percentage. Refer this example
Hi, how can i create a semicircular pie chart, using the above code?
Anwesha,
Here is an example for semicircular pie-chart. And take a look at semicircular doughnut as well.
Thanks, how can i change the css property of any of these element? I need the size of one of the sectors to increase.
Anwesha,
Here size of each sectors depends on it’s y value. So, a larger y value will give you a large sector.
I am working with two parameters here, as one of them increases, it should envelope the other. The radius of one sector should be larger than the other. So, how do i change it?
Is this what you are looking for?? http://jsfiddle.net/canvasjs/2wnm2vxw/
Thx for your afford.
How can I fix the #percent format in 1 decimal place?
Freeman Lo,
You can set percentFormatString: “#0.#”, to format 1 decimal place.
great! it works! Thx!
great! it works! Thx!
Hi Geeks!!
Can I have a Pie chart in which following data satisfy
data value
A 50
B 30
C 20
now there are are two instance of A like A1 and A2 which are 70% and 30% respectively of A. So How I should mention these in pie chart.
one more query,
How to create pie chart with following data—
data value (Time in HH:MM:SS format)
usedtime 1232:23:45
freetime 321:34:54
How should I write y value??
First you need to convert the time into seconds and then make the pie chart using that time. Here is an example for your query.
Here is an example for your query.
Hi
Why there is canvasjs link in every graph. How should i disable that.
thanks
CanvasJS is free for non commercial usage as long as the credit link in the bottom right corner is kept intact.
So to use CanvasJS without the credit link, you would be required to purchase a license. For more info, visit license and EULA.
Can I remove onClick animation?
Mansour,
Are you looking for this?
No. when you click part of pie it changes place. I don’t need it
Mansour,
We just release v1.8.1 Beta with explodeOnClick feature which will allow you to do the same.
thanks
One more question.
How can I send variables of chart by post method to another page?
In CanvasJS, you can refer any of your variable via chart.options. For example you can refer explodeOnClick after initialising, via chart.options.data[0].explodeOnClick and send it to a page, via get/post method.
thanks a lot mahnn!!!
I am using Spring Boot – Thymleaf ;
How to pass parameters from model.addAttribute(,) values to ”y” values..
y: 4181563, indexLabel: “PlayStation 3”
Please anybody provide solution
How to make each legend text to redirect to some link OnClick
Vinay,
You can use window.open() method on legend.itemclick to achieve this. Here is an example.
Hi,
amble to get dynamic pie charts…am displaying pie chart in a ..I want to enlarge(zoom) the chart on mouseover or onlick property…do we have any provision in canvas js for the same?
Vivek,
You can enlarge pie size by setting pie radius inside the function mouseover or click. Here is an example.
If you want to change the size of canvas, you can set width and height of the chart inside onclick function of container.
Do we have functionality to blink pie chart? If yes please reply
Tejas,
You can bring up the blink effect in pie chart either by changing opacity of the dataSeries or by changing the color of the dataSeries on some events on it. Check this example where fillOpacity is changed on mouse-over the dataSeries.