chartist icon indicating copy to clipboard operation
chartist copied to clipboard

Having issue while initializing Chartist

Open ikismail opened this issue 7 years ago • 4 comments

Hello, I facing a problem while injecting chartist.js

While initializing chartist.js Im getting chart like this Broken Chart.

While resizing the page size or changing the window size, the chart rendered exactly Broken Chart.

Can anyone tell me whats the problem I'm facing ?

ikismail avatar Apr 03 '18 10:04 ikismail

Mine workaround was to set a little timeout on initialize. But would like to hear a better approach.

tkuznyetsoff avatar Apr 05 '18 13:04 tkuznyetsoff

either do what @tkuznyetsoff said, or define hard sizes in pixels for the container

eddr avatar Apr 14 '18 12:04 eddr

Hello @ikismail 👋

Chartist has recently been updated to version 1.0 with some new exciting changes like ESM and TypeScript support. The migration guide can be found right here.

Please let me know if the issue is still relevant to you so we can further look into it!

Arantiryo avatar Oct 29 '22 11:10 Arantiryo

IMHO, this is still relevant.

I suspect that when this occurs, maybe the page (or parent container) isn't fully rendered yet when the chart is being initialized.

I had the same issue as OP, however my chart instance is deep in some nested components. I don't know what the exact culprit is; I haven't investigated further. The chart occurs in an animated modal, so maybe I have to wait for that to finish before initiating the chart.

A test: When this issue occurs, as a test, try to nudge the browser viewport a little bit to invoke a re-paint. and observe what happens. Does the chart magically appear? This tells you something about containment, and I suspect a factor is SVG (in general) being sensitive to containment size.

Workaround(s): 1 - Wrap a timeout of x seconds 2 - Make sure to init the chart only when the page (or parent container) is finished rendering

Sample Vue code:

onMounted( () => {
    setTimeout(() => {
        new BarChart(...)
    }, 1000)
})

kalnode avatar Mar 20 '24 14:03 kalnode