从Array值获取值以形成聊天

I'm pulling feedback from a table and analyzing it by converting it to the format below:

String: The food is very bad

Dominant: neg, scores: Array ( [neg] => 0.5 [neu] => 0.25 [pos] => 0.25 )

String: The car is very bad

Dominant: neg, scores: Array ( [neg] => 0.5 [neu] => 0.25 [pos] => 0.25 )

String: The bridge is very bad

Dominant: neg, scores: Array ( [neg] => 0.5 [neu] => 0.25 [pos] => 0.25 )

All I want to do is to compute all the values for negative, positive and neutral and present them in a pie chart

This is an example of the chart I want to develop using the array element

enter image description here

You can do it like below:-

<?php
$a = Array ( 'neg' => 0.5, 'neu' => 0.25, 'pos' => 0.25 );
$key = array_keys($a); //get te keys of the array
$b = Array ( 'neg' => 0.5, 'neu' => 0.25, 'pos' => 0.25 );
$c=  Array ( 'neg' => 0.5, 'neu' => 0.25, 'pos' => 0.25 );
$d = array_map(function () {
    return (array_sum(func_get_args())/3)*100; // add all three array corresponding keys values and convert them to percentage
}, $a, $b,$c);

$d = array_combine($key,$d); // now combine key array and sum array
$d = array('Sentiment'=>'rating') + $d; // add which type of chart it is as a key value pair
$rating_data = array(); //create a new array variable

foreach($d as $key=>$val){
    $rating_data[] = array($key,$val); //convert summ array to key,value sub-array and assig it to new array
}
 $encoded_data = json_encode($rating_data); //json encode the new array
?>

<html>
    <head>
        <script type="text/javascript" src="https://www.google.com/jsapi"></script>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript">
            google.load("visualization", "1", {packages:["corechart"]});
            google.setOnLoadCallback(drawChart);
            function drawChart() 
            {
             var data = google.visualization.arrayToDataTable(
             <?php  echo $encoded_data; ?>
             );
             var options = {
              title: "Sentiment vs Rating"
             };
             var chart = new google.visualization.PieChart(document.getElementById("employee_piechart"));
             chart.draw(data, options);
            }
        </script>
        <style>
            body
            {
             margin:0 auto;
             padding:0px;
             text-align:center;
             width:100%;
             font-family: "Myriad Pro","Helvetica Neue",Helvetica,Arial,Sans-Serif;
             background-color:#FAFAFA;
            }
            #wrapper
            {
             margin:0 auto;
             padding:0px;
             text-align:center;
             width:995px;
            }
            #wrapper h1
            {
             margin-top:50px;
             font-size:45px;
             color:#585858;
            }
            #wrapper h1 p
            {
             font-size:18px;
            }
            #employee_piechart
            {
             padding:0px;
             width:600px;
             height:400px;
             margin-left:190px;
            }
        </style>
    </head>
    <body>
        <div id="employee_piechart" style="width: 900px; height: 500px;"></div>
    </body>
</html>

Output at my local end:-http://prntscr.com/fk71m2