<select> box period filter in Highcharts library JS

45 Views Asked by At

teams.

I need your help to develop a listed box range filter(created via tag) with "last month", "last 2 month", "last 3 month" which filter data in Highchart column or bar chart.

<html>
<select id = "selectorPeriod" name="selectorPeriod" required="required">
  <option value=" " >select range</option>
  <option value="30">last 30 days</option>
  <option value="60">last 60 days</option>
</select>
<div id= "container"> </div>

<html>
 const today = new Date();
// const sevenDaysAgo = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000) ;
// const fourteenDaysAgo = new Date(Date.now() - 14 * 24 * 60 * 60 * 1000);
 const ago30Days = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
 const ago60Days = new Date(Date.now() - 60 * 24 * 60 * 60 * 1000) ;
 const ago90Days = new Date(Date.now() - 90 * 24 * 60 * 60 * 1000);
 const ago180Days = new Date(Date.now() - 180 * 24 * 60 * 60 * 1000);
 const ago365Days = new Date(Date.now() - 365 * 24 * 60 * 60 * 1000); 


selectorPeriod.addEventListener('change', function(event) {
console.log(event)
    
  if (this.value==="30") {

        w.data.endDate = today; 
        w.data.startDate = ago30Days; 
    } else if (this.value==="60") {
        w.data.startDate = today; 
        w.data.endDate = ago60Days;

} })

0

There are 0 best solutions below