Home Forums Chart Support Date format problem

Date format problem

Viewing 6 posts - 1 through 6 (of 6 total)
  • #30624

    Hello I have problem with date format on the chart:

    I am fetching csv file where data look like that

    2020-07-11T23:11:52,23.45
    2020-07-14T21:06:39,25.02
    2020-07-14T21:08:05,25.07
    2020-07-14T21:10:00,25.13
    2020-07-14T21:12:10,25.04
    2020-07-14T21:14:32,25.07
    2020-07-14T21:30:49,24.87

    Code:

    async function getData(){

    var response =await fetch(‘data.csv’);
    var data = await response.text();
    var table = data.split(‘\n’).slice(1);
    table.forEach(row =>{
    var columns = row.split(‘,’);
    var date = new Date(columns[0]);
    var xValue = date;
    var yValue = columns[1];

    xlabels.push(date);
    dataPoints.push({
    x: xValue,
    y: yValue
    });

    });

    And creating chart:

    var chart;
    chart = new CanvasJS.Chart(“chartContainer”,
    {
    title: {
    text: “Chart with Date Selector”
    },
    data: [
    {
    type: “line”,
    dataPoints: xlabels
    }
    ]
    });
    chart.render();

    What is a problem?

    #30631

    @amania,

    After looking into your code, it seems you have parsed dataPoints into a variable called dataPoints. But you are assigning a different variable within chart option/data.

    Passing the variable dataPoints within chart options/data should work fine in your case.

    If you are still facing the issue kindly create a sample project reproducing the issue and share it with us along with the sample CSV over Google-Drive or Onedrive so that we can run your code locally, understand your scenario better and help you out.

    ___________
    Indranil Deo
    Team CanvasJS

    #30632

    Still same problem :(

    https://we.tl/t-bk3lKJedhG – project is here

    Please help me :(

    #30636

    @amania,

    Parsing the y-value to float using parseFloat() and rendering the chart inside getData() should work fine in your case. Please take a look at this updated sample project.

    ___________
    Indranil Deo
    Team CanvasJS

    #30637

    Thank you It really worked, also problem was that I have been using safari. Thank you very much!!!!

    #30679

    @amania,

    Glad that you figured it out :)

    ___________
    Indranil Deo
    Team CanvasJS

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

You must be logged in to reply to this topic.