Android highcharts 如何启用或禁用数据标签

Android highcharts how to enable or disable data labels

我正在研究 android。通过使用 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);

它给我一个错误

error: incompatible types: HIDataLabels cannot be converted to ArrayList plotOptions.getBar().setDataLabels(new HIDataLabels());

来源: Android Basic Bar

非常感谢任何帮助。

他们已经改变了 datalabel 属性。现在您必须执行以下操作

HIDataLabels dataLabels = new HIDataLabels();
dataLabels.setEnabled(false);
ArrayList<HIDataLabels> dataLabelsList = new ArrayList<>();
dataLabelsList.add(dataLabels);
bar1.setDataLabels(dataLabelsList);

将数据设置为 bar1

后尝试上面的代码

有关详细信息,请参阅此 comment