Issue
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
Solution
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);
Answered By - K Pradeep Kumar Reddy
Answer Checked By - Clifford M. (JavaFixing Volunteer)