Java
--
Questions
--
Followers
Top Experts
Could you please suggest me an easy to use library for pie chart
I am looking for a dynamic pie chart like this ...
you may look at this sample pie chart. This is the type of pie chart I am looking for.
http://www.conceptdraw.com/How-To-Guide/picture/Percentage-pie-chart-DA-determinations.png
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
http://d3js.org/
I want a very simple and easy to use solution for showing a pie chart like this ..
http://www.conceptdraw.com/How-To-Guide/picture/Percentage-pie-chart-DA-determinations.png
I am very much comfortable with jquery. But I guess Jquery does not have pie chart.
Does D3.js can help in this regard ? I am already using Jquery in my web application ....I don't want to use another third party library unless this requirement is filled.
You can use JFreeChart for this. Here are some tutorial howto use it
http://www.jfree.org/
http://www.programming-free.com/2012/07/jfreechart-create-auto-refreshing-pie.html
http://thinktibits.blogspot.com/2011/05/jfreechart-servlet-example-tutorial-pie.html
http://www.java2s.com/Code/Java/Chart/CatalogChart.htm
And these are pure HTML/JavaScript/JQuery
http://www.jqchart.com/jquery/chart/ChartTypes/PieChart
http://www.jqplot.com/tests/pie-donut-charts.php
http://www.chartjs.org/
Regards,
Tomas Helgi






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
one slice is cut out in this example .... can we keep it same as other slices.
Read the Doc section :)
I guess that has something to do with the
explodedSlices: [5],
keywords.
In the example you see the China data (no 5 in the data-array) exploded.
So if you omit the explodeSlices line no slice will be cut out. Likewise if you put
explodedSlices: [1,5],
both data/slices for United Kingdom and China will be cut out.
Regards,
Tomas Helgi
I don't see any pie chart in D3.js .
There are many examples of D3.js pie charts.
Go to the D3.js site and hit examples, you will find a humongous range of examples.

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I have this code ..
DefaultPieDataset myServletPieChart = new DefaultPieDataset();
myServletPieChart.setValue("Maths", 74);
myServletPieChart.setValue("Physics", 87);
myServletPieChart.setValue("Chemistry", 62);
myServletPieChart.setValue("Biology", 92);
myServletPieChart.setValue("English", 51);
JFreeChart mychart = ChartFactory.createPieChart("",myServletPieChart,true,true,false);
mychart.setBack
response.setContentType("image/png"); /* Set the HTTP Response Type */
ChartUtilities.writeChartAsPNG(out, mychart, 400, 300);
This generated output like this ...
https://drive.google.com/file/d/0B-XtIZwNPaowSEh6V0hmdU9aeXRJMlM4THBhUmhJMURkc0tz/view?usp=sharing
But I want to generate output like this...
https://drive.google.com/file/d/0B-XtIZwNPaowS09jLXpxVHR0ck9fUHR1dHBLQkpmVmpUQkVF/view?usp=sharing
Could you please suggest what code I may need to add in my existing snippet ?
This examples show you how you can customize the colors of the slices
http://thinktibits.blogspot.com/2011/05/jfreechart-pie-chart-example-java.html
https://javabeanz.wordpress.com/2007/08/06/creating-pie-charts-using-custom-colors-jfreechart/
ANd this shows how to set the background color using the ColorConfigurator
http://thinktibits.blogspot.com/2013/01/JFreeChart-Chart-Backgroud-Color-Alpha-Java-Example-Program.html
REgards,
Tomas Helgi
I am using this
mychart.getPlot().setBackgroundPaint(new Color(255,255,255,0));
This sets background as transparent....good.But you missed another part I asked in JFreechart. I require the texts to be inside the slice.
How do I achieve this ?
please see again my desired output :
https://drive.google.com/file/d/0B-XtIZwNPaowS09jLXpxVHR0ck9fUHR1dHBLQkpmVmpUQkVF/view?usp=sharing
see the text "Physics" , "Maths" , "English" etc are inside the slice. How do I achieve this ?






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Maybe this helps
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSimpleLabels(true)
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/plot/PiePlot.html#setSimpleLabels%28boolean%29
Otherwise for the labels you should look at PieSectionLabelGenerator
You will probably need to implement/extend that class for your needs.
http://www.ktipsntricks.com/data/ebooks/java/jfreechart-1.0.12-A4.pdf
Regards,
Tomas Helgi
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSimpleLabels(true);
This worked fine. Thank you.
Now I want to change the color of each slices of my choice.
Could you please tell how to achieve this ?
I dont like default color of slices.
This is achived by using this
plot.setSectionPaint("Appl
plot.setSectionPaint("Oran
I gave you an example on that in my earlier post :)
This one
https://javabeanz.wordpress.com/2007/08/06/creating-pie-charts-using-custom-colors-jfreechart/
Regards,
Tomas Helgi

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
My present code is ..
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("XXXXXXXXXXXXXXX", 40);
dataset.setValue("yyyyyyyy", 30);
dataset.setValue("ZZZZZZZZZZZZZZZZZZZZZZ", 30);
JFreeChart mychart = ChartFactory.createPieChart("",dataset,true,true,false);
mychart.getPlot().setBackgroundPaint(new Color(255,255,255,0));
PiePlot plot = (PiePlot) mychart.getPlot();
plot.setSimpleLabels(true);
response.setContentType("image/png");
ChartUtilities.writeChartAsPNG(out, mychart, 400, 300);
As you see I have 3 different slice in this code.
Now how do I give
slice XXXXXXXXXXXXXXX to color yellow
slice yyyyyyyy to color pink
slice ZZZZZZZZZZZZZZZZZZZZZZ to color black
I don't understand where to fit your code into my existing snippet. Could you please take a look at it.
Thanks






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Java
--
Questions
--
Followers
Top Experts
Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.