Home forums Using CanvasJS Not able to display pie chart with external csv file

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by  Manoj Mohan 2 weeks, 1 day ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #25690

    version.csv
    KM,-
    7.8.2,6
    7.12.0,5
    7.12.1,3
    7.12.2,42
    8.1.0,10
    8.1.1,27
    8.4.0,12
    6.9.2,7
    6.12.0,3
    7.2.0,3
    7.2.2,6
    7.3.3,10
    7.8.2,8
    7.8.3,2

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

    function getDataPointsFromCSV(csv) {
    var dataPoints = [];
    var csvLines = [];
    var points = [];

    csvLines = csv.split(/[\r?\n|\r|\n]+/);

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

    }
    return dataPoints;
    }

    $.get(“version.csv”, function(data) {
    var chart = new CanvasJS.Chart(“chartContainer”, {
    title: {
    text: “Chart from CSV”,
    },
    data: [{
    type: “pie”,
    dataPoints: getDataPointsFromCSV(data)
    }]
    });

    chart.render();

    });
    }
    </script>
    </head>
    <body>
    <div id=”chartContainer” style=”width:100%; height:800px;”></div>
    </body>
    </html>

    #25699

    @sanikahumbe,

    It seems to be working fine without any issue. Please take a look at this working sample.

    If you are still facing any issue, kindly share sample project reproducing the issue along with sample csv over Google-Drive or Onedrive so that we can understand the issue better and help you resolve the same.

    —-
    Manoj Mohan
    Team CanvasJS

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

You must be logged in to reply to this topic.