Home Forums Chart Support import csv into canvasJS

import csv into canvasJS

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

    trying to get a canvas graph using csv file.
    The name of the csv is “Data.csv”
    The contents of the csv file:

    When I run it I get a blank screen.
    Am I missing something.

    <!DOCTYPE html>
    <title>Chart using XML Data</title>
    <script type=”text/javascript” src=”https://canvasjs.com/assets/script/jquery-1.11.1.min.js”></script&gt;
    <script type=”text/javascript” src=”https://canvasjs.com/assets/script/canvasjs.min.js”></script&gt;
    <script type=”text/javascript”>
    window.onload = function() {
    var dataPoints = [];

    function getDataPointsFromCSV(Data.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(“,”);
    x: parseFloat(points[0]),
    y: parseFloat(points[1])
    return dataPoints;

    $.get(“https://canvasjs.com/services/data/datapoints.php?xstart=5&ystart=10&length=10&type=csv&#8221;, function(data) {
    var chart = new CanvasJS.Chart(“chartContainer”, {
    title: {
    text: “Chart from CSV”,
    data: [{
    type: “line”,
    dataPoints: getDataPointsFromCSV(data)


    <div id=”chartContainer” style=”width:100%; height:300px;”></div>



    As x-value stored in CSV is data-time, it should be parsed to date object than to float x: parseFloat(points[0]),. Changing it to x: new Date(points[0]), should work fine in your case. Please take a look at this documentation page for step-to-step tutorial on rendering chart with data from CSV.
    Chart using data from CSV

    Vishwas R
    Team CanvasJS

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

You must be logged in to reply to this topic.