How to display values within pie chart sector - java

I am using JFreeChart to create pie charts. Values are displayed outside pie chart sectors as labels. I want to display the values within the pie sectors. How can I achieve this. Please can any one help me?

Use setSimpleLabels(), as shown below; org.jfree.chart.demo.PieChartDemo1 is a good starting point.
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSimpleLabels(true);

If you are using createPieChart3D to create Pie chart, following URL will be helpful to you.
http://www.java2s.com/Code/Java/Chart/JFreeChartPieChart3DDemo1.htm
What I know is, showing values inside is default feature of the chart. If you're unable to do so it seems that you have changed the default way.

Related

Android donut chart fill with multiple colors based on timestamp

I am looking for a chart which will show one circle around that time like 12:00, 01:00 like. Which fills with some colors based on time of activity.
I found this link Create Doughnut Chart Similar to Google Fit but it isn't fit for my requirements.
Please find image below. This is how I am expecting the chart.
Here these colors represent some activity based on timings. I have a set of data with a timestamp and it's activity type.
Can anyone suggest to me how I can draw this chart? Is there any example for this?
Edit
I found this link http://www.androidtrainee.com/draw-android-clock-pie-chart-with-animation/ to draw clock pie view. But stuck at point to set width and fill color like in above image. Right now it's fill different color based on time in full circle. But how do I set width to this clock to fill color and center part blank to show 08:40?
Since these are very specific requirements, it is likely that you will have to create your own custom view on Android. The SO you linked has a few promising libraries linked including fit-chart. The documentation isn't great, but it seems to support adding chart parts with values in 1% steps.
So you would only need to convert your duration data into percent of the circle by using 60 minutes or 12 hours as 100%.
Here is the relevant usage part of fit-chart:
Collection<FitChartValue> values = new ArrayList<>();
values.add(new FitChartValue(30f, 0x2d4302)); // 30f seems to represent 30%
final FitChart fitChart = (FitChart)findViewById(R.id.fitChart);
fitChart.setValues(values);
Another library that looks promising is MPAndroidChart that supports a detailed Pie Chart.
Regarding taking time into account: There are plenty of tutorials on how to draw an analogue clock that should include calculation on how to position the texts around the circle. Here is one SO creating a CustomClock View with multiple tutorials linked.
Regarding setting up your custom view, this 2d-donut-chart tutorial drawing a chart based on Path.arcTo covers all the needed steps.
If you need further help it would be helpful if you add your data structure and what you already tried. But I hope with these libraries and tutorials you can create your desired view.
Regarding updated question: I would suggest that you create your own custom view. My best suggestion is to continue by comparing the ClockPieView.onDraw with the draw methods of the other libraries I mentioned that do draw a doughnut graph with a hole. Research how text can be rendered as part of the onDraw with your specific positioning.
Heres a list of jQuery extensions to do this:
http://www.jquerybyexample.net/2014/02/jquery-html5-library-circular-piechart-graph.html
You can customize the Pie chart of MPAndroidChart library to create this. Here is a similar one created using it.
Here you will find the documentation of the library and this demo application is also helpful.
Here is a sample code you can try out after adding MPAndroid chart library to your project.
List<PieEntry> entries = new ArrayList<>();
//add data entries, 100 will be considered as a full circle
entries.add(new PieEntry(50, ""));
entries.add(new PieEntry(25, ""));
entries.add(new PieEntry(25, ""));
PieDataSet pieDataSet = new PieDataSet(entries, "");
PieChart pieChart1 = (PieChart)rootView.findViewById(R.id.pie_chart1);
pieChart.setMaxAngle(360);
//You can customize the pie chart in many ways to suit your need
pieChart.setCenterTextRadiusPercent(84);
pieChart.setRotationEnabled(false);
pieChart.setRotationAngle(180);
pieChart.setHoleRadius(60f);
pieChart.setDescription(null);
pieChart.setHoleColor(ContextCompat
.getColor(context,R.color.colorTransparent));
pieChart.setBackgroundColor(ContextCompat.getColor(context,
R.color.colorTransparent));
pieChart.setTouchEnabled(false)
pieChart.setDrawCenterText(true);
pieChart.setCenterTextColor(Color.BLACK);
pieChart.setCenterTextSize(16f);
pieChart.setCenterText(status);
//Add animation (optional)
pieChart.animateY(1500);
pieChart.invalidate();

How to Remove label on pie chart

I have Created Pie Chart using PhilJay MPAndroidChart but i do not want Text and figure written on pie chart it should be beside of pie chart with color an description with figure. now it display at downside without figure.
To remove x-Values use pieChart.setDrawSliceText(false).
To remove y-Values use pieChart.getData().setDrawValues(false).
pieChart.setDrawSliceText(false) has been deprecated so use pieChart.setDrawEntryLabels(false) instead

Draw scatter plot with crosshair on each data points in iReport

Is it possible to draw scatter chart with horizontal and vertical line on the specific data-point in iReport or any other reporting tool except Excel?
Sure, as iReport Charts are based on the JFreeChart Library and you can bind a ChartCustomizer to your chart in iReport, that should not be a big problem.
Search google for these catchwords and you'll get ahead.

How to zoomout barchart using highchart?

I want to zoomout my barchart x-axis values.
I am dynamically created barchart from database values using struts2,my x-axis data is like city,population
etc.I want to do zoom my barchart data.
please provide me any solution
Thank You.
You can use setExtremes function which allows ot define set range on xAxis.
http://api.highcharts.com/highcharts#Axis.setExtremes()

Setting label and value of the chart

I am creating pie charts using JFreeChart, and I want to set the value and the label seperately like in iReport. In other words, I want the chart to show different results on the pie than in the legend. Is there any way that I can achieve this?
The MessageFormat ArgumentIndex values correspond to the series name, domain and range. You can set a different generator for each series or for all series in the base.
PiePlot plot = (PiePlot) chart.getPlot();
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} {1} {2}"));
Addendum: For PiePlot, the values have a slightly different meaning—series name, value and percentage—as shown here.

Categories

Resources