Context: Java swing application generating a chart using JFreeChart. The chart is a CombinedDomainXYPlot (using XYBarRenderer) that on the X-axis has a timeline based on PeriodAxis.
Problem: I can't remove the vertical gridlines (not the tickmarks related to the time periods) that separate days.
What I tried is: combinedPlot.setDomainGridlinesVisible(false) which doesn't work (see image below).
Any hint would be more than welcome!
Thx,
Thomas
After some additional research I found the mistake: for CombinedDomainXYPlot the setDomainGridlinesVisible(false) needs to be called on the subplots:
List<XYPlot> subplots = (List<XYPlot>) combinedPlots.getSubplots();
for (XYPlot p:subplots) p.setDomainGridlinesVisible(false);
Related
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();
I am working with AndroidPlot since about one year to display different Diagrams in my app.
Now I am working with BarCharts, the charts are finished but how can I make corners rounded?
I found some results for lines:
How to make line with rounded (smooth) corners with AndroidPlot
I tried already:
BarFormatter formatter1,formatter2, formatter3;
formatter1.getBorderPaint().setStrokeJoin(Paint.Join.ROUND);
formatter1.getFillPaint().setStrokeJoin(Paint.Join.ROUND);
doesn't seems to have any impact.
then I tried:
XYPlot plot; //Initialized with UI-Diagrammm above
...
plot.setBorderStyle(XYPlot.BorderStyle.ROUNDED,5f,5f);
Does anyone had the problem already and got an answer how to do this.
Thanks for Help,
Franzi
Bars are rendered by Androidplot's BarRenderer class which uses the Canvas.drawRect(...) method to draw individual bars. In order to get rounded edges it would either need to call Canvas.drawRoundRect or possibly even better, draw each bar as a path using Path.lineTo(...) and Path.arcTo(...) methods so that only the top of the bars are rounded. This functionality unfortunately does not exist yet but you could open a feature request if you want.
Or you could implement it yourself by creating a custom renderer that extends BarRenderer and overriding drawBar(...). Documentation available here
I created a line chart:
But I want it to make it looks like this. I also don't know what kind of chart is this.
I want to make also have a shadow and circle nodes in it. Just like this:
How can I do this? By the way I'm displaying the chart in the webpage as PNG image format if it is relevant to my question. Thanks in advance.
For info, the sample chart you are trying to replicate is included in the JFreeChart demo collection. The complete source code for the demos is included with the JFreeChart Developer Guide. You could save yourself some time and your company some money by asking them to buy the JFreeChart Developer Guide, it's not so expensive. On to the answer...
The shadow effect you are looking for can be added to any CategoryPlot or XYPlot by setting the shadow generator:
plot.setShadowGenerator(new DefaultShadowGenerator());
It looks nice, but be aware that it requires rendering the chart as a bitmap so it won't play so nicely if you are exporting your charts to SVG or PDF or other vector formats.
The shapes on the lines can be added by changing attributes on the renderer you are using (LineAndShapeRenderer in this case).
LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);
The setBaseShapesVisible() method sets the default (or 'base') flag value for all series. You can override that default on a per-series basis if you want to. You may also want to tweak the colors being used...by default all the shapes are drawn and filled using the series color, but there are flags that can be set to make the renderer use the series fill and series outline colors (which is done in the example to get the white fill in the shapes).
The JFreeChart renderers are very configurable, so I suggest you spend some time looking through the API documentation to see what is possible.
Here's your solution:
LineAndShapeRenderer renderer
= (LineAndShapeRenderer) plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setDrawOutlines(true);
renderer.setUseFillPaint(true);
renderer.setBaseFillPaint(Color.white);
renderer.setSeriesStroke(0, new BasicStroke(3.0f));
renderer.setSeriesOutlineStroke(0, new BasicStroke(2.0f));
renderer.setSeriesShape(0, new Ellipse2D.Double(-5.0, -5.0, 10.0, 10.0));
I am using JFreeChart in my java application.
Problem
I want to plot a XYAreaChart whose domain axis (x-axis) should scroll horizontally automatically when we start plotting the data.
I saw the same thing in TimeSeriesCharts but I don't want any timeSeriesChart. I just want the scrolling x-axis.
You'll need to create your own SlidingXYDataset that implements XYDataset in a manner similar to how SlidingCategoryDataset implements CategoryDataset.
Addendum: As noted in a comment, a typical implementation can be found here.
I have drawn a XY chart using jfree. Now i want to add zoom functionality to it. This must be done using a slider at the bottom of the chart. How can i add zoom functionality, the likes of which is present in Windows Photo Viewer?
Also, i would like to show the current Y-value of the graph as a tooltip when the user hovers his mouse over the plotted line. I am not getting much ideas.
Please help.
Thanks in advance
XYPlot et al. implement the Zoomable interface, which allows ChartPanel to control zooming. I'd think you could use these methods in your slider's ChangeListener.
I would like to show the current Y-value of the graph as a tooltip…
You can enable tool tips, as shown in this example.