mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-29 15:39:33 +00:00
Add graph_utils.convert_pie_data to convert data to the format expected by Chart
This commit is contained in:
parent
7b12986c7b
commit
e1c9f92c72
1 changed files with 37 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue