Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
Onclick Event Google Visualization Pie Chart create with Dynamic input value

I have 3 inputs and from where by click in a button get those input value and create a Google Visualization dynamic Pie Chart depend on those value . I have made like this code below , but did not getting expecting result

HTML

<input type="text" name="BigHalo"  id="BigHalo">
<input type="text" name="MediumHalo" id="MediumHalo">
<input type="text" name="SmallHalo" id="SmallHalo">
<button type="button" onclick="onclickChartValur()" >CLICK HERE</button>
<div id="donutchart" style="width:380px; height:380px;"></div>

SCRIPT CODE

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>

<script type="text/javascript">

  google.charts.load("current", {packages:["corechart"]});
  google.charts.setOnLoadCallback(drawChart);
  function drawChart(BigHalo,MediumHalo,SmallHalo) {

 

    var data = google.visualization.arrayToDataTable([
      ['Language', 'Speakers (in millions)'],
      ['Big Halo',  BigHalo],
      ['Medium Halo',  MediumHalo],
      ['Small Halo',SmallHalo]
    ]);

  var options = {
    legend: 'none',
    pieSliceText: 'label',
    title: '',
    pieStartAngle: 100,
  };

    var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
    chart.draw(data, options);
  }

  function onclickChartValur() {

    var BigHalo    = $("#BigHalo").val();
    var MediumHalo = $("#MediumHalo").val(); 
    var SmallHalo  = $("#SmallHalo").val(); 

    drawChart(BigHalo,MediumHalo,SmallHalo);

  }


</script>

ERROR RESULT ::

Error Result

EXPECTING RESULT Expecting result

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It is Solved! I made it . Here I am sharing this technique.

HTML

<input type="text" name="BigHalo"  id="BigHalo">
<input type="text" name="MediumHalo" id="MediumHalo">
<input type="text" name="SmallHalo" id="SmallHalo">
<button type="button" onclick="onclickChartValur()" >CLICK HERE</button>
<div id="donutchart" style="width:380px; height:380px;"></div>

Script

   <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
function drawChart(BigHalo,MediumHalo,SmallHalo) {

var data = google.visualization.arrayToDataTable([
  ['Language', 'Speakers (in millions)'],
  ['Big Halo',   parseInt(BigHalo)],
  ['Medium Halo',   parseInt(MediumHalo)],
  ['Small Halo', parseInt(SmallHalo)]
]);
var options = {
    legend: 'none',
    title: '',
    pieStartAngle: 100,
  };

var chart = new google.visualization.PieChart(document.getElementById('donutchart'));
chart.draw(data, options);
}

function ontypeChartValur() {

    var BigHalo    = $("#BigHalo").val();
    var MediumHalo = $("#MediumHalo").val(); 
    var SmallHalo  = $("#SmallHalo").val(); 
    drawChart(BigHalo,MediumHalo,SmallHalo);
}

</script>

And OnClick event this cart will be generate easily ! Also we can make it with onKeyup / onKeydown event also.

NOTE : parseInt is used here because of convert string to number.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!