Fix server crash with empty data when plotting a chart using gnuplot.

This commit is contained in:
Dorian Niemiec 2024-08-06 15:57:32 +02:00
parent 04a8bac338
commit 03125d8b47

View file

@ -26,6 +26,7 @@ function plot(data) {
Object.keys(data).sort().forEach(function (key) {
dataToFeed.push(dataToFeed.length + " \"" + key.replace(/"/g, "'") + "\" " + parseFloat(data[key]));
});
if (dataToFeed.length == 0) dataToFeed.push("0 \"\" 0");
var gnuplotObject = gnuplot().set("terminal png size 800,480").set("tics font \"Poppins,12\"").set("xtics rotate by 45 right").set("boxwidth 0.6").set("style fill solid").set("yrange [0:*]").set("grid ytics mytics").set("grid").plot("'-' using 1:3:xtic(2) notitle lc rgb \"#007000\" with boxes");
gnuplotObject.end(dataToFeed.join("\n"));
return gnuplotObject;