Basic Bar Chart Demo Example Code

the java api for highcharts


Below is the Java code needed to create the Highcharts Basic Bar demo chart from their website.

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.getChart().setType(ChartType.BAR);
	chartOptions.getTitle().setText("Historic World Population by Region");
	chartOptions.getSubtitle().setText("Source: Wikipedia.org");

	XAxis xAxis = new XAxis();
	xAxis.setCategories(Arrays.asList("Africa", "America", "Asia", "Europe", "Oceania"));
	xAxis.getTitle().setText(null);
	chartOptions.getXAxis().add(xAxis);

	YAxis yAxis = new YAxis();
	yAxis.setMin(0).getTitle().setText("Population (millions)").setAlign(TitleAlign.HIGH);
	yAxis.getLabels().setOverflow(LabelsOverflow.JUSTIFY);
	chartOptions.getYAxis().add(yAxis);

	chartOptions.getTooltip().setValueSuffix(" millions");
	chartOptions.getPlotOptions().getBar().getDataLabels().setEnabled(true);
	chartOptions.getCredits().setEnabled(false);

	chartOptions.getLegend().setLayout(Layout.VERTICAL).setAlign(HorizontalAlign.RIGHT)
		.setVerticalAlign(VerticalAlign.TOP).setX(-40).setY(80).setFloating(true)
		.setBorderWidth(1).setShadow(true)
		.getBackgroundColor().setColorValue("((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF')");
		
	SeriesBar seriesBar = new SeriesBar();
	seriesBar.setName("Year 1800");
	seriesBar.setDataAsArrayNumber(Arrays.asList(107, 31, 635, 203, 2));
	chartOptions.getSeries().add(seriesBar);
		
	seriesBar = new SeriesBar();
	seriesBar.setName("Year 1900");
	seriesBar.setDataAsArrayNumber(Arrays.asList(133, 156, 947, 408, 6));
	chartOptions.getSeries().add(seriesBar);
		
	seriesBar = new SeriesBar();
	seriesBar.setName("Year 2000");
	seriesBar.setDataAsArrayNumber(Arrays.asList(814, 841, 3714, 727, 31));
	chartOptions.getSeries().add(seriesBar);
		
	seriesBar = new SeriesBar();
	seriesBar.setName("Year 2016");
	seriesBar.setDataAsArrayNumber(Arrays.asList(1216, 1001, 4436, 738, 40));
	chartOptions.getSeries().add(seriesBar);
		
	return highChart;
}

The Java API’s are up to date with the latest version of Highcharts and Highcharts Stock. They fully supports all chart types and chart options in Highcharts v5.x, v6.x, v7.x, v8.x and Highcharts Stock v8.x.

Current versions supported are:

HyJavaCharts

HyJavaStock