如何通过HighCharts Android上的图形来传递自定义对象

发布于 2025-02-13 23:56:04 字数 456 浏览 2 评论 0原文

如何通过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

How to pass custom object for graph point on HighCharts Android ?
I want to pass extra information other than x and y values for point on graph. That extra information i want to use in tooltip.
How to achieve this on Android ?

I tried something like this, but it did not work.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月亮坠入山谷 2025-02-20 23:56:05

在这里回答

对于这种情况,我们需要使用地图。在Tooltip中,我们需要通过其映射键等效(例如{key_name})来参考点参数。查看此示例:

    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);

Answered here
https://github.com/highcharts/highcharts-android/issues/237

For that case, we will need to use maps. In tooltip, we will need to refer to point parameter by its map key equivalent (e.g. point.{key_name}). Check out this example:

    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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文