Add linear regression to temporal graphs
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import AggregatedFoodComp from "$lib/components/Energy/Aggregated/AggregatedFoodComp.svelte";
|
||||
import { main } from "$wails/models";
|
||||
import type { ChartData, Point } from "chart.js";
|
||||
import regression from "regression";
|
||||
import {
|
||||
CategoryScale,
|
||||
Chart as ChartJS,
|
||||
@@ -13,6 +14,7 @@
|
||||
Title,
|
||||
Tooltip,
|
||||
} from "chart.js";
|
||||
import { CalculateR2 } from "$lib/utils";
|
||||
|
||||
ChartJS.register(Title, Tooltip, Legend, LineElement, LinearScale, PointElement, CategoryScale);
|
||||
|
||||
@@ -32,7 +34,7 @@
|
||||
pointHoverBorderColor: "rgba(220, 220, 220, 1)",
|
||||
pointHoverBorderWidth: 2,
|
||||
pointRadius: 1,
|
||||
pointHitRadius: 10,
|
||||
pointHitRadius: 20,
|
||||
};
|
||||
const data: ChartData<"line", (number | Point)[]> = {
|
||||
labels: reversedItems.map((f) => f.period),
|
||||
@@ -74,6 +76,14 @@
|
||||
},
|
||||
],
|
||||
};
|
||||
data.datasets.push({
|
||||
...defaultOptions,
|
||||
label: "R2",
|
||||
data: CalculateR2(reversedItems.map((f, i) => [i, f.energy])),
|
||||
borderColor: "#04d1d1",
|
||||
pointBorderColor: "#04d1d1",
|
||||
pointRadius: 0,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@@ -13,6 +13,7 @@
|
||||
Title,
|
||||
Tooltip,
|
||||
} from "chart.js";
|
||||
import { CalculateR2 } from "$lib/utils";
|
||||
|
||||
ChartJS.register(Title, Tooltip, Legend, LineElement, LinearScale, PointElement, CategoryScale);
|
||||
|
||||
@@ -44,6 +45,14 @@
|
||||
},
|
||||
],
|
||||
};
|
||||
data.datasets.push({
|
||||
...defaultOptions,
|
||||
label: "R2",
|
||||
data: CalculateR2(reversedItems.map((f, i) => [i, f.amount])),
|
||||
borderColor: "#04d1d1",
|
||||
pointBorderColor: "#04d1d1",
|
||||
pointRadius: 0,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
Reference in New Issue
Block a user