HyJavaCharts Quick Start Guide

the java api for highcharts

OVERVIEW

The HyJavaCharts Java library is a pure Java wrapper for the Highcharts JavaScript library. It allows your Java-based web applications to configure Highcharts charts using only Java methods. There is no need to write any JavaScript.

The library will generate the required JavaScript code that Highcharts needs to render the charts.

To define the contents of a chart, you simply have to instantiate the Highchart class and use its setter methods to define the chart options and chart data as required.

HOW TO USE THE LIBRARY

Java

Include the HyJavaCharts jar in your project.

Configure your chart and generate the JavaScript code for the global and chart options.

Highchart hc = new YourBarChart().configure();
String globalOptionsJs = hc.globalOptionsToJs();
String chartOptionsJs = hc.chartOptionsToJs();

The YourBarChart class will look something like this:

public class YourBarChart {

    public Highchart configure() {
        Highchart highChart = new Highchart();
        ChartOptions chartOptions = highChart.getChartOptions();

        chartOptions.getChart().setType(ChartType.BAR);
        chartOptions.getTitle().setText("Historic World Population by Region");
        chartOptions.getSubtitle().setText("Source: Wikipedia.org");

        set all your required chart options......

        return highChart;
    }

}
JavaScript

Include required JavaScript on your page as per Highcharts documentation.

Highcharts.setOptions(${globalOptionsJs});
Highcharts.chart('container', ${chartOptionsJs});

Your Java code will pass the globalOptionsJs and chartOptionsJs strings to the markup variables ${globalOptionsJs} and ${chartOptionsJs}.
The method used to pass the generated chart options from the java to the web page will vary depending on your Java web framework.

Web Page

Your markup will look something like this:

<script src=https://code.highcharts.com/highcharts.js></script>

<div id="container" style="min-width: 310px; max-width: 800px; height: 400px; margin: 0 auto"></div>

<script>
Highcharts.setOptions(${globalOptionsJs});
Highcharts.chart('container', ${chartOptionsJs});
</script>

That is all that is required to get a working Bar chart example.

The Java API’s fully support all chart types and chart options in Highcharts v5.x, v6.x, v7.x, v8.x, v9.x;  Highcharts Stock v8.x, v9.x and ApexCharts v3.x.


Current versions supported are:

HyJavaCharts

HyJavaStock

HyJavaApex

Start the HyJavaCharts demo Java web application


Start the HyJavaStock demo Java web application


Start the HyJavaApex demo Java web application


Start the HyJavaImages demo Java web application