-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create new chart with x.type=time (#288)
* Create new chart with x.type=time * Remove packageManager item * Nevermind, dont pass through callbacks * Update packages
- Loading branch information
1 parent
06796fc
commit 68e5106
Showing
6 changed files
with
7,558 additions
and
4,825 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import type {ChartTypeRegistry} from "chart.js"; | ||
|
||
const formatter = new Intl.DateTimeFormat(undefined, { | ||
localeMatcher: "lookup", | ||
hour: "numeric", | ||
minute: "2-digit" | ||
}); | ||
const sampleData = { | ||
theme: "light", | ||
chartData: { | ||
total: 31.46, | ||
series: [ | ||
{ | ||
name: "Total", | ||
data: [ | ||
{ x: "1/28/2025, 2:01:13 PM", y: 0.73 }, | ||
{ x: "1/28/2025, 2:04:13 PM", y: 0.73 }, | ||
{ x: "1/28/2025, 2:05:13 PM", y: 0.73 }, | ||
] | ||
}, | ||
{ | ||
name: "Main Proc", | ||
data: [ | ||
{ x: "1/28/2025, 2:01:13 PM", y: 0.19 }, | ||
{ x: "1/28/2025, 2:04:13 PM", y: 0.19 }, | ||
{ x: "1/28/2025, 2:05:13 PM", y: 0.19 } | ||
] | ||
}, | ||
{ | ||
name: "Type A", | ||
data: [ | ||
{ x: "1/28/2025, 2:01:13 PM", y: 0.48 }, | ||
{ x: "1/28/2025, 2:04:13 PM", y: 0.48 }, | ||
{ x: "1/28/2025, 2:05:13 PM", y: 0.48 }, | ||
] | ||
}, | ||
{ | ||
name: "Type B", | ||
data: [ | ||
{ x: "1/28/2025, 2:01:13 PM", y: 0.03 }, | ||
{ x: "1/28/2025, 2:04:13 PM", y: 0.03 }, | ||
{ x: "1/28/2025, 2:05:13 PM", y: 0.03 }, | ||
] | ||
}, | ||
{ | ||
name: "Type C", | ||
data: [ | ||
{ x: "1/28/2025, 2:01:13 PM", y: 0.43 }, | ||
{ x: "1/28/2025, 2:04:13 PM", y: 0.44 }, | ||
{ x: "1/28/2025, 2:05:13 PM", y: 0.45 }, | ||
] | ||
} | ||
] | ||
} | ||
}; | ||
const convertChartDataSeriesToChartjsDatasets = (chartDataSeries) => { | ||
return chartDataSeries.map(({name, data}) => { | ||
return { | ||
label: name, | ||
data: data.map(({x, y}) => { | ||
return { | ||
x: new Date(x).valueOf(), | ||
y | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
const config = { | ||
type: "line" as keyof ChartTypeRegistry, | ||
data: { | ||
datasets: convertChartDataSeriesToChartjsDatasets(sampleData.chartData.series) | ||
}, | ||
options: { | ||
plugins: { | ||
title: { | ||
display: false | ||
}, | ||
tooltip: { | ||
callbacks: { | ||
label: (context) => { | ||
return `${context.dataset.label}: ${context.parsed.y * 100}%` | ||
} | ||
} | ||
}, | ||
chartjs2music: { | ||
axes: { | ||
x: { | ||
format: (n: number) => formatter.format(n) | ||
}, | ||
y: { | ||
format: (y: number) => `${y*100}%` | ||
} | ||
} | ||
} | ||
}, | ||
responsive: true, | ||
scales: { | ||
x: { | ||
title: { | ||
text: "Time", | ||
display: false | ||
}, | ||
type: "time", | ||
time: { | ||
unit: "minute" | ||
}, | ||
ticks: { | ||
callback: (n) => { | ||
return formatter.format(n); | ||
} | ||
} | ||
}, | ||
y: { | ||
title:{ | ||
text: "% of Memory Used", | ||
display: false | ||
}, | ||
min: 0, | ||
max: 1, | ||
ticks: { | ||
callback: (n) => { | ||
return `${n*100}%` | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.