The solution isn't particularly elegant, but maybe someone might be interested. It's based on https://community.rei3.de/d/766-using-the-options-object-for-echarts/7
The referenced rei3 backend_function returns an object like
{
"x": [2020, 2021, 2022, 2023, 2024, 2025],
"y": [
{"id": 15, "data": [null, null, -4, 22, 8, 51], "name": "One"},
{"id": 28, "data": [19, 23, 67, 41, 12, 37], "name": "Two"}
]
}
with id being the dataset id.
The frontend function has to be executed after the form has been loaded.
let optionsLine = {
legend:{
orient:'vertical',
left:'left',
type:'scroll'
},
series:[],
toolbox:{
feature: {
saveAsImage:{ show:true }
}
},
tooltip: {
trigger:'item'
},
xAxis:{
data:[],
type:'category'
},
yAxis: {
position:'left',
type:'value'
}
};
const parse = function(rows) {
optionsLine.xAxis.data = rows.x;
for(const row in rows.y) {
let r = rows.y[row];
optionsLine.series.push({
type:'line',
id:r.id,
data:r.data,
name:r.name,
label:r.name,
connectNulls:true,
symbolSize: 7,
tooltip: {
valueFormatter:(value) => value + ' °C'
}
});
};
app.timer_set('chart_set', false, () => {
// line chart
app.set_field_chart({F1::Chart}, optionsLine);
// get echart object from rei3 echart attribute id
let r3Id = app.get_field_id({F1::Chart});
let r3El = self.document.querySelector('[data-field-id="' + r3Id + '"]');
let ecEl = r3El.querySelector('[_echarts_instance_]');
let ecId = ecEl.getAttribute('_echarts_instance_');
let ec = self.echarts.getInstanceById(ecId);
// open form when echart datapoint is clicked
ec.on('click', function(event) {
app.form_open(
"<uuid>", // form id
event.seriesId, // record id
false, // new tab
false, // pop_up
0, // max_height
0, // max_width,
false // replace_history
);
});
}, 100);
};
const data = app.call_backend({schema.backend_function}).then(
res => parse(res !== null ? JSON.parse(res) : []),
console.warn
);