Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

im newbie programmer idk how to update chart When choosing a time #1307

Open
skieslineb opened this issue Mar 9, 2022 · 0 comments
Open
Labels

Comments

@skieslineb
Copy link

skieslineb commented Mar 9, 2022

I'm using chartist.js to run a chart, but I can't update it when choosing between two time intervals.

in
<div id="traffic"></div> <input onchange="filterData()" type="date" id="startdate" value="<?php echo $date[0] ?>"> <input onchange="filterData()" type="date" id="enddate" value="<?php echo $date[count($date) - 1] ?>">

in script
`const dates = [];
const datapoints = [];
//set chartist
var chart1 = new Chartist.Line('#traffic', {
labels: dates,
series: [{
name: 'proTotal',
data: datapoints
}, ]
}, {
low: 0,
showArea: true
});
function filterData() {
const dates2 = [...dates];
console.log(dates2)
const startdate = document.getElementById('startdate');
const enddate = document.getElementById('enddate');

    const indexstartdate = dates2.indexOf(startdate.value);
    const indexendtdate = dates2.indexOf(enddate.value);
    //console.log(startdate)

    const filterDate = dates2.slice(indexstartdate, indexendtdate + 1);

    // replace the labels in the chart
    chart1.labels = filterDate;


    //datapoints
    const datapoints2 = [...datapoints];
    const filterDatapoints = datapoints2.slice(indexstartdate, indexendtdate + 1);

    chart1.series = filterDatapoints;


    chart1.update();
}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants