Basic Bar Chart Demo Example Code

the highcharts java api


Below is the Java code needed to create the Highcharts Basic Bar demo chart from their website.
The Java getter/setter naming convention for method names is also supported.

This example chart is also viewable in the demo web application available on the demo page.

public Highchart configure() {
    Highchart highChart = new Highchart();
    ChartOptions chartOptions = highChart.getChartOptions();
    chartOptions.chart().type(ChartType.BAR);
    chartOptions.title().text("Historic World Population by Region");
    chartOptions.subtitle().text("Source: Wikipedia.org");

    XAxis xAxis = new XAxis();
    xAxis.categories(new ArrayList(Arrays.asList("Africa", "America", "Asia", "Europe", "Oceania")));
    xAxis.title().text(null);
    chartOptions.xAxis().add(xAxis);

    YAxis yAxis = new YAxis();
    yAxis.min(0).title().text("Population (millions)").align(TitleAlign.HIGH);
    yAxis.labels().overflow(LabelsOverflow.JUSTIFY);
    chartOptions.yAxis().add(yAxis);

    chartOptions.tooltip().valueSuffix(" millions");
    chartOptions.plotOptions().bar().dataLabels().enabled(true);
    chartOptions.credits().enabled(false);

    chartOptions.legend().layout(Layout.VERTICAL).align(HorizontalAlign.RIGHT)
        .verticalAlign(VerticalAlign.TOP).x(-40).y(80).floating(true)
        .borderWidth(1).shadowAsBoolean(true)
        .backgroundColor().setColorValue("((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF')");
		
    SeriesBar seriesBar = new SeriesBar();
    seriesBar.name("Year 1800");
    seriesBar.dataAsArrayNumber(new ArrayList(Arrays.asList(107, 31, 635, 203, 2)));
    chartOptions.series().add(seriesBar);
		
    seriesBar = new SeriesBar();
    seriesBar.name("Year 1900");
    seriesBar.dataAsArrayNumber(new ArrayList(Arrays.asList(133, 156, 947, 408, 6)));
    chartOptions.series().add(seriesBar);
		
    seriesBar = new SeriesBar();
    seriesBar.name("Year 2000");
    seriesBar.dataAsArrayNumber(new ArrayList(Arrays.asList(814, 841, 3714, 727, 31)));
    chartOptions.series().add(seriesBar);
		
    seriesBar = new SeriesBar();
    seriesBar.name("Year 2016");
    seriesBar.dataAsArrayNumber(new ArrayList(Arrays.asList(1216, 1001, 4436, 738, 40)));
    chartOptions.series().add(seriesBar);
		
    return highChart;
}

HyJavaCharts

The HyJavaCharts Java API is up to date with the latest version of Highcharts and fully supports all chart types and chart options in Highcharts v5.x and v6.x. Current versions supported are: