chartjs / chartjs/chartjs-chart-financial

Initiate chart without data

Open
#80 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
809
Forks
199
PR merge metrics
No merged PRs in 30d

Description

Hey, cheers for your work!

I am currently trying to create a candlestick chart that will be felling up over time. That is, when I initiate the graph, the x axis is already premade but with no y values.

I then later attempt to add values over time: after 5s add a bar to x=1 ...

This works perfectly when using a simple line chart.

However this is not working when using the candlestick type of chart.
I am getting the following error:
![image](https://user-images.githubusercontent.com/38708022/92419957-bde4e480-f1c4-11ea-8a0b-6f6064a95c47.png)

Which seems to be linked to this code:
```
afterBuildTicks: scale => {
const DateTime = window && window.luxon && window.luxon.DateTime;
if (!DateTime) {
return;
}
const majorUnit = scale._majorUnit;
const ticks = scale.ticks;
const firstTick = ticks[0];

let val = DateTime.fromMillis(ticks[0].value); //-- Line 66
if ((majorUnit === 'minute' && val.second === 0)
|| (majorUnit === 'hour' && val.minute === 0)
|| (majorUnit === 'day' && val.hour === 9)
|| (majorUnit === 'month' && val.day <= 3 && val.weekday === 1)
|| (majorUnit === 'year' && val.month === 1)) {
firstTick.major = true;
} else {
firstTick.major = false;
}
let lastMajor = val.get(majorUnit);

for (let i = 1; i < ticks.length; i++) {
const tick = ticks[i];
val = DateTime.fromMillis(tick.value);
const currMajor = val.get(majorUnit);
tick.major = currMajor !== lastMajor;
lastMajor = currMajor;
}
scale.ticks = ticks;
}
```
From what I understand, the code expects ticks right off the bat. So if there is no data by default then it will throw an error?

Am I missing something? if not It would be great to implement upgrade the code to let the chart initiate properly without data.

If I am simply dumb, I'd love an idea on how to achieve what I'm looking for that'd be amazing, cheers.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.