Maybe it will be simpler for you to just pass your data2 as a parameter to
the innerDrawChart, and move innerDrawChart out to the top level as a
normal named function.

             var data2 = [['Covid19', 'Stats'],
                  ['Active cases',value.active],
                  ['Deaths', value.deaths],
                  ['recovered', value.recovered],];
  innerDrawChart(data2);
  ...
function innerDrawChart(data2) {
  ...
}


On Thu, Apr 16, 2020 at 1:40 PM Shivan Singh <[email protected]> wrote:

> i used if condition so that it doesn't repeat.
>
> creating jquery as function removes the error but doesn't show any chart.
>
> google.charts.load("current", {packages:["corechart"]});
> google.charts.setOnLoadCallback(drawChart);
> function drawChart() {
> function covid() {
> $.getJSON("https://api.covid19india.org/data.json";, function(data){
> $.each(data.statewise, function(key, value){
> if (value.state == "Total") {
> var data2 = [['Covid19', 'Stats'],
>                   ['Active cases',value.active],
>                   ['Deaths', value.deaths],
>                   ['recovered', value.recovered],];
>                   innerDrawChart();
> }
> });
> });
> }
> var innerDrawChart = function() {
>       var data = google.visualization.arrayToDataTable(data2);
>
>       var options = {
> width:"350",
> height:"350",
> pieHole: 0.5,
> backgroundColor: { fill:"transparent"},
> chartArea:{
> left:10,
> right:10, // !!! works !!!
> bottom:20,  // !!! works !!!
> top:20,
> width:"100%",
> height:"100%"
> },
> pieSliceTextStyle: {
> color: "white",
> },
> legend: {position: "bottom", textStyle: {color: "gray"}},
>
> pieSliceText: "none",
> };
>
>       var chart = new
> google.visualization.PieChart(document.getElementById('covid19'));
>       chart.draw(data, options);
>     }
> }
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Visualization API" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-visualization-api/b5e85afa-f53a-4707-9fcf-6748a720e188%40googlegroups.com
> <https://groups.google.com/d/msgid/google-visualization-api/b5e85afa-f53a-4707-9fcf-6748a720e188%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 
Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2>
[email protected] <[email protected]>   Cambridge MA

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-visualization-api/CAOtcSJMtT96obCPKg6XO%2Bz%2BTSKD6%3D_O4X%3DTyzfS36EOypysJWQ%40mail.gmail.com.

Reply via email to