Home Forums Chart Support Not able to display pie chart with external csv file

Not able to display pie chart with external csv file

Viewing 2 posts - 1 through 2 (of 2 total)
  • #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://cdn.canvasjs.com/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.