question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redraw chart on click

See original GitHub issue

How can I redraw my chart on click? My template has options to display the width of a column on toggling a button, however the chart is not updating, only if I resize the browser will it redraw.

Here’s my code:

<script>
            var chart = new Chartist.Line('#chart', {
                labels: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'],
                series: [
                  [12, 12, 12, 13, 14, 16, 18, 20, 21, 20, 22, 22],
                  [14, 14, 15, 16, 15, 17, 17, 18, 18, 19, 20, 21],
                  [16, 16, 17, 18, 19, 20, 22, 23, 22, 21, 21, 23]
                  
                ]
            }, {
                low: 12,
                showArea: true,
                fullWidth: true,
                axisX: {
                    //showGrid: false
                },
                axisY: {
                    offset: 30,
                    onlyInteger: true,
                    labelInterpolationFnc: function (value) {
                        return '$' + value + 'k';
                    }
                },
                plugins: [
                    Chartist.plugins.tooltip(),
                    Chartist.plugins.legend({
                        legendNames: ['Investments', 'Returns', 'Interest'],
                    })
                ]
            });

            chart.on('draw', function (data) {
                if (data.type === 'line' || data.type === 'area') {
                    data.element.animate({
                        d: {
                            begin: 500 * data.index,
                            dur: 500,
                            from: data.path.clone().scale(1, 0).translate(0, data.chartRect.height()).stringify(),
                            to: data.path.clone().stringify(),
                            easing: Chartist.Svg.Easing.easeOutQuint
                        }
                    });
                }
            });
        </script>

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
wim-mertenscommented, Feb 20, 2017

[solved] added setTimeout and is working now.

0reactions
gulshan-escaloncommented, May 11, 2017

Hi gionkunz,

Actually I have 3 charts on the page so How can i use the chart.update() function to update all charts. currently its update the last chart only. I am using id base charts , any more solution ?

Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google chart redraw onclick - Stack Overflow
I can't seem to find a way to pass new data in the chart on a click event. I got it working so...
Read more >
chart.events.redraw | highcharts API Reference
Information on the clicked spot can be found through event. ... Fires when the chart is redrawn, either after a call to chart.redraw()...
Read more >
How to use the redraw method of chart? | jQuery - ejChart
The redraw method is used to dynamically refresh the chart content and redraw the chart based on the updated values. Refer to the...
Read more >
Updating Charts - Chart.js
It's pretty common to want to update charts after they've been created. When the chart data or options are changed, Chart.js will animate...
Read more >
Onclick Button Change Chart Type in Chart JS - YouTube
In this video we will explore how to use buttons with onclick function to change the chart type. We will explore why the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found