private void setDefaultChartOptions(String yTitle, String yOppositeTitle, String[] seriesName) { setDefaultChartOptions(yTitle, seriesName, true); chart .getYAxis(1) .setAxisTitle( new AxisTitle() // .setText(yOppositeTitle) // .setAlign(AxisTitle.Align.MIDDLE)) // .setOpposite(true) // .setAllowDecimals(false) // .setMin(0); }
private void setDefaultChartOptions( String yTitle, String[] seriesName, boolean hasOppositeTitle) { chart .setToolTip(new ToolTip().setEnabled(false)) // .setLegend(new Legend().setEnabled(true)) // .setCredits( new Credits().setEnabled(false) // ); chart .getYAxis(0) .setAxisTitle(new AxisTitle().setText(yTitle).setAlign(AxisTitle.Align.MIDDLE)) .setAllowDecimals(false); chart .getXAxis() // .setType(Axis.Type.DATE_TIME) // .setLabels( new XAxisLabels() // .setRotation(-45) // .setAlign(Labels.Align.RIGHT) .setFormatter( new AxisLabelsFormatter() { @Override public String format(AxisLabelsData axisLabelsData) { if (axisLabelsData.getValueAsDouble() < 0) { return ""; } return DateTimeFormat.getFormat("mm:ss") .format(new Date(axisLabelsData.getValueAsLong())); } }) // ); for (int i = 0; i < seriesName.length; i++) { if (hasOppositeTitle) { chart.addSeries(chart.createSeries().setName(seriesName[i]).setYAxis(i)); } else { chart.addSeries(chart.createSeries().setName(seriesName[i])); } } }
private Chart createChart(String title, String yaxisTitle) { Chart chart = new Chart() .setType(Series.Type.BAR) .setChartTitleText(title) .setBarPlotOptions( new BarPlotOptions() .setAnimation(false) .setDataLabels(new DataLabels().setEnabled(true))) .setLegend(new Legend().setEnabled(false)) .setCredits(new Credits().setEnabled(false)) .setHeight(categories.size() * 30 + 100); chart.getXAxis().setCategories(categories.toArray(new String[categories.size()])); chart .getYAxis() .setAxisTitle(new AxisTitle().setText(yaxisTitle).setAlign(AxisTitle.Align.HIGH)); chart.setAnimation(false); return chart; }