如何在HighCharts Android上传递图形点的自定义对象

2izufjch  于 2022-11-10  发布在  Highcharts
关注(0)|答案(1)|浏览(169)

如何在HighCharts Android上传递图形点的自定义对象?我想传递图形点的x和y值以外的额外信息。我想在工具提示中使用这些额外信息。如何在Android上实现这一点?
我试过这样的东西,但它没有工作。

data class GraphPoint(val x:Float, val y:Float, val date:Long)

val readings = ArrayList<List<GraphPoint>>()
readings.add(GraphPoint(1f, 10f, 1657255313)
readings.add(GraphPoint(2f, 5f, 1657255351)
readings.add(GraphPoint(3f, 20f, 1662612113)

val scatter = HIScatter()
scatter.data = readings
bfrts1fy

bfrts1fy1#

已在此处回答https://github.com/highcharts/highcharts-android/issues/237
在这种情况下,我们需要使用Map。在工具提示中,我们需要通过对应的Map关键字(例如point.{key_name})来引用point参数。请查看以下示例:

HIChartView chartView = findViewById(R.id.chartview1);
    HIOptions options = new HIOptions();

    HILegend legend = new HILegend();
    legend.setEnabled(false);
    options.setLegend(legend);

    HITooltip tooltip = new HITooltip();
    tooltip.setHeaderFormat("<span style=\"font-size:11px\">{series.name}</span><br>");
    tooltip.setPointFormat("<b>X: {point.x:.2f}%</b> <b>Y: {point.y:.2f}%</b><br/>Date: point.date");
    options.setTooltip(tooltip);

    HIScatter series1 = new HIScatter();

    HashMap<String, Object> map1 = new HashMap<>();
    map1.put("date", 1657255313);
    map1.put("x", 1);
    map1.put("y", 10);

    HashMap<String, Object> map2 = new HashMap<>();
    map2.put("date", 1657255351);
    map2.put("x", 2);
    map2.put("y", 5);;

    HashMap<String, Object> map3 = new HashMap<>();
    map3.put("date", 1662612113);
    map3.put("x", 3);
    map3.put("y", 20);

    HashMap[] series1_data = new HashMap[] { map1, map2, map3 };
    series1.setData(new ArrayList<>(Arrays.asList(series1_data)));
    options.setSeries(new ArrayList<>(Arrays.asList(series1)));

    chartView.setOptions(options);

相关问题