Home Forums Chart Support YYYYDDMM XAxis using JSON

YYYYDDMM XAxis using JSON

Viewing 2 posts - 1 through 2 (of 2 total)
  • #28816

    Using the https://canvasjs.com/javascript-charts/json-data-api-ajax-chart/ with data from $.getJSON(“https://covidtracking.com/api/us/daily”, addData);

    Data coming in looks like:
    {“date”:20200330,”states”:56,”positive”:160530,”negative”:784324,”posNeg”:944854,”pending”:65382,”hospitalized”:22303,”death”:2939,”total”:1010236,”hash”:”5d6b80da84d18b345f21f914f55a72520c680310″,”dateChecked”:”2020-03-30T20:00:00Z”,”totalTestResults”:944854,”deathIncrease”:511,”hospitalizedIncrease”:2573,”negativeIncrease”:92034,”positiveIncrease”:21469,”totalTestResultsIncrease”:113503},

    and I’m only pulling date and positive:
    function addData(data) {
    for (var i = 0; i < data.length; i++) {
    dataPoints.push({
    x: new Date(data[i].date),
    y: data[i].positive
    });
    }
    chart.render();

    The xaxis is displaying as ‘326ms’ rather than ’03/26/2020′.
    How can I format this date properly?

    #28829

    @durxxx,

    Passing x-value in one of the valid JavaScript Date-Formats should work fine in this case. Please take a look at this JSFiddle for an example on parsing date to ISO standard [new Date(“2020-03-05”)].


    Vishwas R
    Team CanvasJS

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.