Skip to content

Commit

Permalink
fix: issues in time series chart if no data provided
Browse files Browse the repository at this point in the history
  • Loading branch information
claustres committed Aug 28, 2024
1 parent 999216a commit 3c4af9e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/client/components/chart/KTimeSeriesChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ async function onCanvasRef (ref) {
if (ref) {
if (!chart) {
const config = await makeChartConfig()
if (!config) return
chart = new Chart(ref.getContext('2d'), config)
}
} else {
Expand Down Expand Up @@ -114,6 +115,8 @@ function computeScaleBound (scale, property, min, max) {
async function makeChartConfig () {
// Order matters as we compute internals like data time range
const datasets = await makeDatasets()
// No data ?
if (_.isEmpty(datasets)) return null
const scales = makeScales()
const annotation = makeAnnotation()
const config = {
Expand Down Expand Up @@ -286,6 +289,8 @@ async function makeDatasets () {
const targetUnit = getTargetUnit(timeSerie)
if (targetUnit) setUnit(timeSerie, targetUnit)
const data = await timeSerie.data
// No data ?
if (_.isEmpty(data)) continue
const dataset = Object.assign({
label,
data,
Expand Down Expand Up @@ -407,6 +412,11 @@ async function update () {
max = null
const config = await makeChartConfig()
if (!config) {
if (chart) chart.destroy()
chart = null
return
}
if (!chart) {
chart = new Chart(canvas.getContext('2d'), config)
} else {
Expand Down

0 comments on commit 3c4af9e

Please sign in to comment.