Create stylish charts in Java eg with JFreeChart

11,291

Solution 1

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

There you can find many samples (you need to download a JFreeChart Demo (web start)). After some work with jFreeChart, I was thinking about moving to EasyChart (follow: http://www.objectplanet.com/easycharts/examples.html), but it looks very similar to jFreeChart actually. JFreeChart is quite easy to write, that I don't know about EasyChart.

But according to your question, there is no problem to change a Font, LineRenderer or anything from desing in JFreeChart, so you can modify it to look exactly like the one you've posted from JavaScript.

Solution 2

I had the same issue.

This code makes JFreeChart look like Highcharts (currently only barcharts are supported). It could easily 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

Solution 3

Try out XChart. XChart is a light-weight Java library for plotting data that would be a potential alternative to JFreeChart. Its focus is on simplicity and doesn't have every capability that JFreeChart has, but it offers a rich set of charting features including Themes to apply different "skins" to a chart. You can easily create your own Theme by implementing an interface and applying it to a Chart by calling chart.setTheme(myTheme). The jar is only ~86 KB as of the 2.0.0 release, and it has no dependencies. It's licensed under Apache 2.0 and is hosted on Github. Some screenshots can be found here. Disclaimer: I'm the lead devloper of the project.

enter image description here

Solution 4

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

Take a look at JavaFX 2.0

Share:
11,291
user1043466
Author by

user1043466

Updated on July 03, 2022

Comments

  • user1043466
    user1043466 almost 2 years

    What's the best way to create great looking charts in Java? It looks like the main option for charting is JFreeChart, but unfortunately by default they come out looking quite plain.

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

    The javascript ones look nicer - they have smooth lines, nice font by default, and just overall look good compared to JFreeChart which looks very plain.

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

  • user1043466
    user1043466 over 12 years
    I assumed there was a way to change most of the style like the font and line rendering - I guess I was hoping for some sample code of really great looking charts to save me from having to play around with it too much. The showcase charts in the web start demo of JFreeChart are a good start though, they ought to use screenshots of those on their sample page.
  • trashgod
    trashgod over 12 years
    See also this answer, as well as org.jfree.chart.annotations.
  • ruX
    ruX about 11 years
    Really impressed about xchart. Highly recommend to everyone who need simple graph tool. Thank you for your work!