Skip to content

Commit a6c15ef

Browse files
committed
better time series support in the chart component
fixes #103
1 parent b663dde commit a6c15ef

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- CLarify some ambiguous error messages:
1010
- make it clearer whether the error comes from SQLPage or from the database
1111
- specific tokenization errors are now displayed as such
12+
- Better support for time series in the [chart](https://sql.ophir.dev/documentation.sql?component=chart#component) component. You can now use the `time` top-attribute to display a time series chart
13+
with smart x-axis labels.
1214

1315
## 0.13.0 (2023-10-16)
1416
- New [timeline](https://sql.ophir.dev/documentation.sql?component=timeline#component) component to display a timeline of events.

sqlpage/apexcharts.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ function sqlpage_chart() {
3535
for (const c of document.getElementsByClassName("chart")) {
3636
try {
3737
const data = JSON.parse(c.querySelector("data").innerText);
38+
const is_timeseries = !!data.time;
3839
/** @type { Series } */
3940
const series_map = {};
4041
data.points.forEach(([name, x, y, z]) => {
4142
series_map[name] = series_map[name] || { name, data: [] }
43+
if (is_timeseries) x = new Date(x);
4244
series_map[name].data.push({ x, y, z });
4345
})
4446
if (data.xmin == null) data.xmin = undefined;
@@ -105,7 +107,7 @@ function sqlpage_chart() {
105107
title: {
106108
text: data.xtitle || undefined,
107109
},
108-
type: data.time ? 'datetime' : categories ? 'category' : undefined,
110+
type: is_timeseries ? 'datetime' : categories ? 'category' : undefined,
109111
},
110112
yaxis: {
111113
logarithmic: !!data.logarithmic,

0 commit comments

Comments
 (0)