Creating stylish graphs in Java, for example, using JFreeChart

What is the best way to create great graphics in Java? It seems that the main option for building charts is JFreeChart, but unfortunately they look pretty simple by default.

Compare the JFreeChart sample: http://www.jfree.org/jfreechart/images/PriceVolumeDemo1.png with one of the Javascript chart libraries, for example http://www.highcharts.com/demo/spline-symbols/grid or http: / /people.iola.dk/olau/flot/examples/graph-types.html

Javascript looks better - they have smooth lines, a good default font, and just the overall look is good compared to JFreeChart, which looks very simple.

Is there a chart library built on top of JFreeChart that looks good by default, or maybe some sample code to make a normal JFreeChart chart (like a line chart) great?

+6
source share
4 answers

http://www.jfree.org/jfreechart/samples.html

You can find many samples here (you need to download the JFreeChart demo (web start)). After some work with jFreeChart, I thought about switching to EasyChart (follow it: http://www.objectplanet.com/easycharts/examples.html ), but in fact it is very similar to jFreeChart. JFreeChart is pretty easy to write that I don't know about EasyChart.

But according to your question, there is no problem changing the font, LineRenderer, or anything you need to create in JFreeChart, so you can change it to look the same as the one you published from JavaScript.

+3
source

I had the same problem.

This code makes JFreeChart look like Highcharts (currently only barcodes are supported). It could be made more efficient :)

String fontName = "Lucida Sans"; JFreeChart chart = ChartFactory.createBarChart(null, "", "", dataset, PlotOrientation.VERTICAL, false, true, false ); StandardChartTheme theme = (StandardChartTheme)org.jfree.chart.StandardChartTheme.createJFreeTheme(); theme.setTitlePaint( Color.decode( "#4572a7" ) ); theme.setExtraLargeFont( new Font(fontName,Font.PLAIN, 16) ); //title theme.setLargeFont( new Font(fontName,Font.BOLD, 15)); //axis-title theme.setRegularFont( new Font(fontName,Font.PLAIN, 11)); theme.setRangeGridlinePaint( Color.decode("#C0C0C0")); theme.setPlotBackgroundPaint( Color.white ); theme.setChartBackgroundPaint( Color.white ); theme.setGridBandPaint( Color.red ); theme.setAxisOffset( new RectangleInsets(0,0,0,0) ); theme.setBarPainter(new StandardBarPainter()); theme.setAxisLabelPaint( Color.decode("#666666") ); theme.apply( chart ); chart.getCategoryPlot().setOutlineVisible( false ); chart.getCategoryPlot().getRangeAxis().setAxisLineVisible( false ); chart.getCategoryPlot().getRangeAxis().setTickMarksVisible( false ); chart.getCategoryPlot().setRangeGridlineStroke( new BasicStroke() ); chart.getCategoryPlot().getRangeAxis().setTickLabelPaint( Color.decode("#666666") ); chart.getCategoryPlot().getDomainAxis().setTickLabelPaint( Color.decode("#666666") ); chart.setTextAntiAlias( true ); chart.setAntiAlias( true ); chart.getCategoryPlot().getRenderer().setSeriesPaint( 0, Color.decode( "#4572a7" )); BarRenderer rend = (BarRenderer) chart.getCategoryPlot().getRenderer(); rend.setShadowVisible( true ); rend.setShadowXOffset( 2 ); rend.setShadowYOffset( 0 ); rend.setShadowPaint( Color.decode( "#C0C0C0")); rend.setMaximumBarWidth( 0.1); 

enter image description here

+11
source

Try XChart . XChart is a lightweight Java data-building library that would be a potential alternative to JFreeChart. Its main focus is on simplicity and does not have all the features that JFreeChart has, but offers a rich set of graphical display functions, including themes for applying different β€œskins” to the chart. You can easily create your own theme by implementing the interface and applying it to the chart by calling chart.setTheme(myTheme) . The flag is only ~ 86KB from version 2.0.0, and it has no dependencies. It is licensed under Apache 2.0 and is hosted on Github . Some screenshots can be found here . Disclaimer: I am the lead developer of the project.

enter image description here

+9
source

http://javafx.com/about-javafx/

Take a look at JavaFX 2.0

+2
source

Source: https://habr.com/ru/post/902359/


All Articles