JSFiddle - React, Tailwind, and code Playground

by lchau

JavaScript

// data generator
function DateRange(startDate, endDate, stepSizeInDays) {
    var stepSize = stepSizeInDays ? Math.max(30, stepSizeInDays) : 30,
        range = [],
        tempDate = startDate;
    while (tempDate <= endDate){
      range.push(new Date(tempDate));
      tempDate.setDate(tempDate.getDate() + stepSize);
    }
    return range;
}

function Index(indexName, source) {
    var values = [],
        dates = new DateRange(new Date("2012-09-08"), new Date());
    dates.forEach(function(date) {
        values.push({
            "date" : date,
            "USD" : (Math.random() * 1000).toFixed(2)
                        + (Math.floor(Math.random() * 10) % 20 == 0 ? 10 : 100)
        });
    });
    return {
        "name" : indexName,
        "source" : source,
        "values" : values
    }
}