【问题标题】:Android highcharts how to enable or disable data labelsAndroid highcharts 如何启用或禁用数据标签
【发布时间】:2021-05-25 10:55:59
【问题描述】:

我正在开发安卓系统。通过使用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());

来源: Android Basic Bar

任何帮助将不胜感激。

【问题讨论】:

    标签: android highcharts bar-chart android-highcharts


    【解决方案1】:

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

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

    将数据设置为bar1后试试上面的代码

    欲了解更多信息,请参阅comment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-13
      • 2010-11-13
      相关资源
      最近更新 更多