Home Forums Chart Support fetching data from csv

fetching data from csv

Viewing 10 posts - 1 through 10 (of 10 total)
  • #17568

    Hi,

    I have .csv file with following content:

    11/13/2017 00:10:00,0,69.8,1.53,0,0.0,0.0,
    11/13/2017 00:20:00,0,69.8,1.43,0,0.0,0.0,
    11/13/2017 00:30:00,0,69.8,1.50,0,0.0,0.0,
    11/13/2017 00:40:00,0,69.7,1.53,0,0.0,0.0,
    11/13/2017 00:50:00,0,69.7,1.50,0,0.0,0.0,
    11/13/2017 01:00:00,0,69.6,1.46,0,0.0,0.0,
    11/13/2017 01:10:00,0,69.6,1.54,0,0.0,0.0,

    How has this part of the code to be modified to get between 4 and 8 lines?

    var dataPoints = [];

    function getDataPointsFromCSV(csv) {
    var dataPoints = csvLines = points = [];
    csvLines = csv.split(/[\r?\n|\r|\n]+/);

    for (var i = 0; i < csvLines.length; i++)
    if (csvLines[i].length > 0) {
    points = csvLines[i].split(“,”);
    dataPoints.push({
    x: parseFloat(points[0]),
    y: parseFloat(points[1])
    });
    }
    return dataPoints;
    }

    Thank you for any help!

    • This topic was modified 7 years, 1 month ago by James. Reason: added notify
    • This topic was modified 7 years, 1 month ago by Vishwas R.
    #17611

    James,

    To get data between line number 4 and 8, you need to start the “for loop” from 5 and run it till 7.

    for (var i = 5; i <= 7; i++)

    ___________
    Indranil Deo,
    Team CanvasJS

    #17612

    sorry that was wrong from my side.

    What I mean is:…code to be modified to get the columns between 4-8 ?

    #17625

    James,

    Can you please explain what do you mean by the columns between 4 – 8?

    Since each line in your CSV is in the format:
    ["11/13/2017 00:10:00", "0", "69.8", "1.53", "0", "0.0", "0.0", ""] you can access the columns between 4 & 8 i.e. columns 5, 6, & 7 by accessing the array elements points[4], points[5] & point[6] respectively. But in your CSV data all these columns are zero.

    Also x: parseFloat(points[0]) won’t work as expected as the first element in the array of your CSV data is a date-time value.

    Please create a jsfiddle and brief us more about your requirement so that understand you requirement better and help you out.

    ___________
    Indranil Deo,
    Team CanvasJS

    #17633

    Hi Indranil,

    I have a better .csv now:

    Date,Sensor (S11),Sensor Temperature (S12),Sensor (S21),FlowMeter Total (D2),Output (A1),Output (A2)
    ,CCond,Temp,pH,Flowmeter,Retrans,Prop
    ,µS/cm,°F,,gal,%,%
    11/16/2017 00:10:00,880,69.7,8.32,0,8.8,65.8,
    11/16/2017 00:20:00,881,69.7,8.31,0,8.8,65.8,
    11/16/2017 00:30:00,882,69.6,8.32,0,8.8,65.9,
    11/16/2017 00:40:00,884,69.5,8.32,0,8.8,66.0,

    I would need column 4,5,6,7 in 1 chart as multiple lines.
    All samples and documentation “Creating Charts from CSV” shows only an ONE line-chart.
    I have no idea how the code should look for 4 or more lines in 1 chart.
    Do you have any example for this?

    #17640

    James,

    Please have a look at this jsfiddle.

    __________
    Indranil Deo,
    Team CanvasJS

    #17642

    Many thanks for this :)

    #28080

    Hello,

    I’m trying to create a chart from two different csv files.

    In the image you can see the blue data are not sync with the X axis label.

    How can I sync the chart line with the X axis label?

    Thanks.

    Chart not Sync
    [img]https://i.imgur.com/sDOJrCH.png[/img]

    #28137

    Thanks to Indranil in this forum, I figured out what the problem is. I had used the label instead of x. It works now.

    Again, thanks Indranil.

    #28192

    @santossg,

    Glad that you figured out

    __________
    Indranil Deo
    Team CanvasJS

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

You must be logged in to reply to this topic.