我正在研究安卓。通过使用highchart
我创建了一个barchart
.
HIOptions options = new HIOptions();
HIChart chart = new HIChart();
chart.setType("bar");
options.setChart(chart);
HITitle title = new HITitle();
title.setText("GOLM");
options.setTitle(title);
HISubtitle subtitle = new HISubtitle();
subtitle.setText("Growth Over Last Month");
options.setSubtitle(subtitle);
HIXAxis xaxis = new HIXAxis();
String[] categories = new String[] { "Mar-2021", "Apr-2021","May-2021"};
xaxis.setCategories(new ArrayList<>(Arrays.asList(categories)));
options.setXAxis(new ArrayList<HIXAxis>(){{add(xaxis);}});
HIYAxis yaxis = new HIYAxis();
yaxis.setMin(0);
yaxis.setTitle(new HITitle());
yaxis.getTitle().setText("Sales");
yaxis.getTitle().setAlign("high");
yaxis.setLabels(new HILabels());
yaxis.getLabels().setOverflow("justify");
options.setYAxis(new ArrayList<HIYAxis>(){{add(yaxis);}});
HITooltip tooltip = new HITooltip();
options.setTooltip(tooltip);
HILegend legend = new HILegend();
legend.setLayout("vertical");
legend.setAlign("right");
legend.setVerticalAlign("top");
legend.setX(-30);
legend.setY(40);
legend.setFloating(true);
legend.setBorderWidth(1);
legend.setBackgroundColor(HIColor.initWithHexValue("FFFFFF"));
legend.setShadow(true);
options.setLegend(legend);
HICredits credits = new HICredits();
credits.setEnabled(false);
options.setCredits(credits);
HIBar bar1 = new HIBar();
bar1.setName("Sale");
Number[] bar1Data = new Number[]{10,15,20};
bar1.setData(new ArrayList<>(Arrays.asList(bar1Data)));
bar1.setColorByPoint(true);
HILegend hiLegend = new HILegend();
hiLegend.setEnabled(false);
options.setLegend(hiLegend);
options.setSeries(new ArrayList<>(Collections.singletonList(bar1)));
golmChart.setOptions(options);
输出
我想启用数据标签。示例代码确实提供了启用数据标签的代码,但它不起作用
HIPlotOptions plotOptions = new HIPlotOptions();
plotOptions.setBar(new HIBar());
plotOptions.getBar().setDataLabels(new HIDataLabels());
plotOptions.getBar().getDataLabels().setEnabled(true);
options.setPlotOptions(plotOptions);
它给了我一个错误
错误:不兼容的类型:HIDataLabels 无法转换为 ArrayList plotOptions.getBar().setDataLabels(new HIDataLabels());
任何帮助将不胜感激。