I was trying to make a solid gauge chart, but I couldn’t get the maximum to be 50. I tried passing in 50 and it kept putting the max as 60. I thought it might be incrementing my 10, so I tried 40, but that kept giving me a max of 40. This is what I have:
public static Chart solidGauge(int min, double current, int max, String label) {
Chart chart = new Chart(ChartType.SOLIDGAUGE);
Configuration configuration = chart.getConfiguration();
Pane pane = configuration.getPane();
pane.setCenter(new String[]{"50%", "50%"});
//Change depending on how the gauge should be (more open or closed)
pane.setStartAngle(-95);
pane.setEndAngle(95);
//Creates an arced background for the Gauge
Background paneBackground = new Background();
paneBackground.setInnerRadius("60%");
paneBackground.setOuterRadius("100%");
paneBackground.setShape(BackgroundShape.ARC);
pane.setBackground(paneBackground);
YAxis yAxis = configuration.getyAxis();
yAxis.setTickAmount(2);
yAxis.setTitle(label);
//No small ticks
yAxis.setMinorTickInterval("null");
yAxis.getTitle().setY(-50);
yAxis.getLabels().setY(16);
yAxis.setMin(min);
yAxis.setMax(max);
PlotOptionsSolidgauge plotOptionsSolidgauge = new PlotOptionsSolidgauge();
DataLabels dataLabels = plotOptionsSolidgauge.getDataLabels();
dataLabels.setY(5);
dataLabels.setUseHTML(true);
configuration.setPlotOptions(plotOptionsSolidgauge);
DataSeries series = new DataSeries(label);
DataSeriesItem item = new DataSeriesItem();
item.setY(current);
item.setColorIndex(2);
item.setClassName(label);
DataLabels dataLabelsSeries = new DataLabels();
dataLabelsSeries.setFormat("<div style=\"text-align:center\"><span style=\"font-size:25px;"
+ "color:black' + '\">{y}</span><br/>"
+ "<span style=\"font-size:12px;color:silver\">" + label + "</span></div>");
item.setDataLabels(dataLabelsSeries);
series.add(item);
configuration.addSeries(series);
return chart;
}
Edit: So I was trying some more values and it seems that 500 rounds t 600, 550 rounds to 600, etc and this is extremely difficult to get around.
Edit 2: After some digging, the issue might be with something called chart.alignTicks but I have no idea how to change or disable that.
Thanks!