Basic Bar Chart Demo Example Code

the highcharts java api

public Highchart generate() {

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 xAxi = new XAxis();
xAxi.categories(new ArrayList(Arrays.asList(“Africa”, “America”, “Asia”, “Europe”, “Oceania”)));
chartOptions.xAxis().add(xAxi);

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

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().setJsonString(“((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 2012”);
seriesBar.dataAsArrayNumber(new ArrayList(Arrays.asList(1052, 954, 4250, 740, 38)));
chartOptions.series().add(seriesBar);

return highChart;

}