add some data to charts

This commit is contained in:
Torsten Dittmann committed 2022-03-25 15:30:55 +03:00
1 parent ade7e21c8a
commit 506e735d72
4 files changed
+73 -22

No files matched your search

+35 -18
View File
@@ -1,29 +1,46 @@
<script lang="ts">
import 'chart.js/auto';
import { Chart, type ChartConfiguration } from 'chart.js';
import { Chart, type ChartConfiguration, type ChartDataset } from 'chart.js';
import { onMount } from 'svelte';
let element: HTMLCanvasElement;
const labels = ['January', 'February', 'March', 'April', 'May', 'June'];
const data = {
labels: labels,
datasets: [
{
label: 'My First dataset',
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 132)',
data: [0, 10, 5, 2, 20, 30, 45]
}
]
};
const config: ChartConfiguration = {
type: 'line',
data: data
};
export let labels: string[];
export let datasets: ChartDataset<'line'>[];
onMount(() => {
new Chart(element, config);
console.log(labels);
console.log(datasets);
new Chart(element, {
type: 'line',
data: {
datasets,
labels
},
options: {
scales: {
x: {
display: false
},
y: {
min: 0
}
},
plugins: {
tooltip: {
mode: 'index',
intersect: false,
caretPadding: 0
}
}
}
});
});
</script>
<canvas bind:this={element} />
<style>
canvas {
max-height: 12rem;
}
</style>
+5 -1
View File
@@ -1,4 +1,8 @@
<div class="top-cover">
<script lang="ts">
export let adjustContentToCover = false;
</script>
<div class="top-cover" class:is-adjust-content-to-cover={adjustContentToCover}>
<div class="container">
<slot name="breadcrumbs" />
<h1 class="main-title">
+2
View File
@@ -46,6 +46,8 @@
<button class="transparent-button" on:click={() => (showDropdown = !showDropdown)}>
<span class="is-only-desktop">{$user.name}</span>
<img
width="40"
height="40"
class="user-image"
src={sdkForConsole.avatars.getInitials($user.name, 40, 40).toString()}
alt=""
+31 -3
View File
@@ -6,8 +6,13 @@
import { Cover, Container } from '$lib/layout';
import CreatePlatform from './_createPlatform.svelte';
import { Line } from '$lib/charts';
import { page } from '$app/stores';
import { toLocaleDate } from '$lib/helpers/date';
let addPlatform = false;
let range: '24h' | '30d' | '90d' = '30d';
$: requestUsage = sdkForConsole.projects.getUsage($page.params.project, range);
</script>
<svelte:head>
@@ -15,7 +20,7 @@
</svelte:head>
{#if $project}
<Cover>
<Cover adjustContentToCover>
<svelte:fragment slot="title">{$project.name}</svelte:fragment>
<ul class="links-nav">
<li class="links-nav-item">
@@ -40,8 +45,31 @@
</Cover>
<Container>
<Card>
<Line />
<p>imagine here are some cool stats</p>
{#await requestUsage then usage}
<Line
labels={usage.requests.map((t) => toLocaleDate(t.date))}
datasets={[
{
label: 'Requests',
data: usage.requests.map((v) => v.value),
fill: true,
borderWidth: 2
},
{
label: 'Users',
data: usage.users.map((v) => v.value),
fill: true,
borderWidth: 2
},
{
label: 'Documents',
data: usage.documents.map((v) => v.value),
fill: true,
borderWidth: 2
}
]}
/>
{/await}
</Card>
<h1>Platforms</h1>
<List>