Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Graph pie

google.charts.load('current', {
  packages:['corechart']
}).then(function () {
  $.ajax({
    url: "<?php echo base_url().'Dashboard/chartData'; ?>",
    dataType: "JSON",
    success: function(result){
      drawChart(result);
    },
    error: function () {
      var result = [
        {name: 'defect 1', defects: '1'},
        {name: 'defect 2', defects: '2'},
        {name: 'defect 3', defects: '3'},
        {name: 'defect 4', defects: '4'},
        {name: 'defect 5', defects: '5'}
      ];

      drawChart(result);
    }
  });

  function drawChart(result) {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Name');
    data.addColumn('number', 'defects');

    var dataArray = [];

    $.each(result, function(i, obj) {
      dataArray.push([obj.name, parseInt(obj.defects)]);
    });

    data.addRows(dataArray);

    var piechart_options = {
      title : 'Defects Registered',
      width : 500,
      height: 300,
      is3D: true,
    };
    var piechart = new google.visualization.PieChart(document.getElementById('piechart_div'));
    piechart.draw(data, piechart_options);
  }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: react facebook login 
Javascript :: create react app 
Javascript :: array unshift 
Javascript :: sequelize migration limit 
Javascript :: base64 from file 
Javascript :: Check If Object Contains A Function 
Javascript :: vue js props 
Javascript :: how to use hash in javascript 
Javascript :: react setstate synchronous 
Javascript :: how to download array of files from aws s3 using aws sdk in nodejs 
Javascript :: + operator javascript 
Javascript :: Create array literal 
Javascript :: dispatch store 
Javascript :: assertion error in jest 
Javascript :: Document object not defined Next js 
Javascript :: how to get last element in array java scipt 
Javascript :: javascript classes 
Javascript :: AJAX in reload a div container 
Javascript :: postgresql json array contains 
Javascript :: npm ERR! missing script: build:dev 
Javascript :: functions and variables javascript 
Javascript :: anglar cli 
Javascript :: what is a blob in javascript 
Javascript :: concatenation of loop data in variable using jquery 
Javascript :: Div draggable x axe only 
Javascript :: google script getactivescell 
Javascript :: ngfor with different id 
Javascript :: string .length js 
Javascript :: array of alphabets 
Javascript :: JS urdsathdzygo8sdhurj.hdo78suij 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =