Home forums Using CanvasJS fetching data from csv

Tagged: ,

This topic contains 6 replies, has 2 voices, and was last updated by  James 3 weeks, 6 days ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #17568

    James
    Member

    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 1 month ago by  James. Reason: added notify
    • This topic was modified 1 month ago by  Vishwas R.
    #17611

    Indranil Deo
    Member

    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

    James
    Member

    sorry that was wrong from my side.

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

    #17625

    Indranil Deo
    Member

    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

    James
    Member

    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

    Indranil Deo
    Member

    James,

    Please have a look at this jsfiddle.

    __________
    Indranil Deo,
    Team CanvasJS

    #17642

    James
    Member

    Many thanks for this :)

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

You must be logged in to reply to this topic.