简体   繁体   English

谷歌图表API-饼图未显示

[英]google charts api - pie chart is not displaying

I am trying to create a piechart dynamically by using Google Chart api. 我正在尝试通过使用Google Chart API动态创建一个饼图。 i am taking values from the database. 我正在从数据库中获取值。 I am not getting how exactly this can be done. 我不知道该怎么做。

$resultViewed = $this->model_report_product->getMostViewed();
        $stringResult ="var data= google.visualization.arrayToDataTable([ ['Product', 'Views'],";

     foreach($resultViewed as $results)
     {               
                 $stringResult = $stringResult . "['".$results['name']."',".$results['quantity']."],";
                 break;     
     }
     $stringResult .= "]);";

    $this->data['Viewed'] = $stringResult;  

When i run this, it gives Chart heading but pie chart is not displayed but it says No Data. 当我运行此命令时,它会给出Chart标题,但不会显示饼图,但会显示No Data。

You can't pass a variable in memory between php to html. 您不能在php和html之间传递内存中的变量。 You have to print it out to pass it to html. 您必须将其打印出来才能传递给html。 So where you have: 所以你有:

return $stringResult;

you should print it out like: 您应该像这样打印出来:

print $stringResult;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM