gpt4 book ai didi

android - HighChart 库 Android : HIOptions not found in HIChartView

转载 作者:太空狗 更新时间:2023-10-29 13:46:23 26 4
gpt4 key购买 nike

我正在尝试将 highcharts 集成到我的 android 应用程序中(在 fragment 内),但我每次都会收到此错误:

java.util.NoSuchElementException: HIOptions not found in HIChartView

这是我的 onCreateView 方法:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
parentView = inflater.inflate(R.layout.bar_layout, null);
return parentView;
}

我如何获得图 TableView :

chartView = parentView.findViewById(R.id.hc);

我正在调用图表 API 以在收到响应后获取数据,我正在设置选项但它给了我同样的错误,下面是我如何设置图表的代码 fragment :

                HIOptions options = new HIOptions();

HIChart chart = new HIChart();
chart.setType("column");
options.setChart(chart);

HIExporting hiExporting = new HIExporting();
hiExporting.setEnabled(false);
options.setExporting(hiExporting);

List<BarChartSeries> seriesList = barChartModel.getSeries();
if (!seriesList.isEmpty()) {

final HIXAxis xAxis = new HIXAxis();

HITitle xAxisTitle = new HITitle();
xAxisTitle.setText(getString(R.string.year));

xAxis.setTitle(xAxisTitle);

XAxisDto xAxisDto = barChartModel.getxAxis();
List<String> stringList1 = xAxisDto.getCategories();

ArrayList<String> xAxisList = new ArrayList<>();
xAxisList.addAll(stringList1);
xAxis.setCategories(xAxisList);
xAxis.setCrosshair(new HICrosshair());

ArrayList<HIXAxis> axes = new ArrayList<>();
axes.add(xAxis);

options.setXAxis(axes);


HIYAxis yAxis = new HIYAxis();
yAxis.setMin(0);

HITitle yAxisTitle = new HITitle();
yAxisTitle.setText(getString(R.string.no_of_cases));

yAxis.setTitle(yAxisTitle);

ArrayList<HIYAxis> yaxes = new ArrayList<>();
yaxes.add(yAxis);


options.setYAxis(yaxes);

HITooltip tooltip = new HITooltip();
tooltip.setHeaderFormat("<span style=\"font-size:10px\">{point.key}</span><table>");
tooltip.setPointFormat("<span style=\"font-size:10px\">{point.key}</span><table>");
tooltip.setFooterFormat("</table>");
tooltip.setShared(true);
tooltip.setUseHTML(true);
options.setTooltip(tooltip);

HIPlotOptions plotOptions = new HIPlotOptions();
HIColumn hiColumn = new HIColumn();
hiColumn.setPointPadding(0.2);
hiColumn.setBorderWidth(0);
plotOptions.setColumn(hiColumn);
options.setPlotOptions(plotOptions);

ArrayList<HISeries> dataSetList = new ArrayList<>();
if (seriesList.size() > 0) {
for (int i = 0; i < seriesList.size(); i++) {

BarChartSeries barChartSeries = seriesList.get(i);
String name = barChartSeries.getName();
List<Data> dataList = barChartSeries.getData();

HIColumn series1 = new HIColumn();
series1.setName(name);

List<String> stringList = xAxisDto.getCategories();
ArrayList<BarEntry> yVals = new ArrayList<BarEntry>();
ArrayList<Long> doubleArrayList = new ArrayList<>();

if (stringList != null) {

for (int j = 0; j < stringList.size(); j++) {
String cat = stringList.get(j);
int count = 0;

for (int ij = 0; ij < dataList.size(); ij++) {
Data data = dataList.get(ij);

if (data.getYear().equalsIgnoreCase(cat)) {
count++;
yVals.add(new BarEntry(ij, data.getCount()));
doubleArrayList.add(data.getCount());
break;
}
}

if (count == 0) {
yVals.add(new BarEntry(yVals.size() + 1, 0));
doubleArrayList.add(0l);
}
}
}
series1.setData(doubleArrayList);
dataSetList.add(series1);
}

}

options.setSeries(dataSetList);
ArrayList<HIColor> hiColors = new ArrayList<>();
hiColors.add(HIColor.initWithHexValue("FF0000"));
hiColors.add(HIColor.initWithHexValue("FFA500"));
hiColors.add(HIColor.initWithHexValue("808080"));
options.setColors(hiColors);

HITitle title = new HITitle();
title.setText("");
options.setTitle(title);

HISubtitle subtitle = new HISubtitle();
subtitle.setText("");

options.setSubtitle(subtitle);

HICredits hiCredits = new HICredits();
hiCredits.setEnabled(false);

options.setCredits(hiCredits);
chartView.setOptions(options);

我在这里错过了什么?或者如何解决这个问题?

最佳答案

我能够解决这个问题。

按照以下步骤解决问题:

  1. 当 fragment View 可见时
  2. 获取图表 ID

    chartView = parentView.findViewById(R.id.hc);

  3. 为 chartView 设置空选项:

    HIOptions options = new HIOptions();

    chartView.setOptions(options);
  4. 从 API 中获取数据后,再次将选项设置为 chartView 并调用重新加载方法:

    chartView.setOptions(options);
    chartView.reload();

关于android - HighChart 库 Android : HIOptions not found in HIChartView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53514005/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com