Add graph_utils.convert_pie_data to convert data to the format expected by Chart

This commit is contained in:
Alfredo Cardigliano 2023-08-14 16:54:14 +02:00
parent 7b12986c7b
commit e1c9f92c72

View file

@ -1380,4 +1380,41 @@ end
-- #################################################
-- Convert to the format accepted by the vue Chart/Pie component
-- js_formatter: render function (e.g. 'format_bytes')
function graph_utils.convert_pie_data(res, new_charts, js_formatter)
if not new_charts then
return res
end
local labels = {}
local series = {}
local colors = {}
for _, v in ipairs(res) do
labels[#labels+1] = v.label
series[#series+1] = v.value
colors[#colors + 1] = graph_utils.get_html_color(#colors)
end
res = {
labels = labels,
series = series,
colors = colors,
yaxis = {
show=false
},
tooltip = {
y = {
formatter = js_formatter
}
},
extra_x_tooltip_label = 'None'
}
return res
end
-- #################################################
return graph_utils