I am trying to get the data in the correct format for the float pie chart. I have obtained the right data in output but I need help in getting it in the correct format so that the pie chart works.
Array ([0] => Array ([[2] => Array ([incident_type] => notification_only), [3] => Array [Incident_type] = & gt; alcoholic mass) = & amp; gt; alcoholic mass, Array ([incident_type] => information_only,) [4] => array ([incident_type] => notification_soon), [5 ] = & Gt; Hey ([incident_type] => notification_soon), [6] = & gt array ([incident_type] => argument,) [7] = & gt; array ([incident_type] => gt; ; [8] = & gt; Hey ([incident_type] => notification_sus), [9] = array ([incident_type] => notification_only), [10] => Array ([ Incident_type] = & gt; controversy,) [ 11] = & gt; Array ([incident_type] => information_how) [12] = Array ([incident_type] => notification_soon), [13] => hey ([incident_type] =) [14] => Array ([incident_type] => controversy, [15] => Array ([incident_type] => dispute,) [16] = & amp; nbsp; & amp; Array ([incident_type] = & gt; theft,) [17] = & gt; Array ([incident_type] => notification_how) [18] => Array ([incident_type] => information_how ,) [19] = & gt; Array ([incident_type] = & gt; alcoholic mass, throat of the road,) [20] = & gt; The same data above, and my function below: public function show_pie_data () {/ Array ([incident_type] = & gt; information_only,) / Use the same data // $ all_incident_type = $ this- & gt; Events _M- & gt; Get_all_incident_types (); $ Result = array (); $ Last_sulu = array (); Forex currency ($ all_incident_type as $ value) {$ date_bits = explosion (',', $ value ['incident_type']); Forex currency ($ date_bits $ key = & gt; $ value) {if ($ value! = '') {$ Result [$ = $ value; }} // print_r (array_count_values ($ result)); $ K = & gt; $ v as Forex currency (array_count_values ($ result) {$ final_result [] = "{label:". $ K. ", Data:". $ V. "}"; } // {label: "test", data: 10} return json_encode ($ end_post);
Here's my solution:
'Array' ('incident_type' = & gt; 'dispute'), array ('' event '' = '' '' dispute ''), array ('' '' app '' ('event_type' Array ('incident_type' = & gt; 'addictive'), arrays array ('event_type' = & gt; 'event_type' = & gt; 'dispute'), array ('event_type' = 'gtc:' 'dispute' '), array ; 'Nationist_person'), Array ('incident_type' = & gt; 'drug mass'), array ('event_type' =>,); $ flat = array ($); $ unique = array; = Array (); $ last = Array (); $ Json = Array (); // Filter Unique Unique Values ($ case = $ value as dollar) {foreach ($ c => value as $ v) {if ( ! In_array ($ v, $ unique) {$ unique [] = $ V;}}} // ARRE foreign currency ($ case as $ $ => $ value) {foreach ($ c = & gt; ; $ V as value = $ v) {$ flat [$ key] = $ v;}} // COUNT foreach ($ flat as flat => val =) {if (in_array ($ val, $ unique )) {If (array_key_exists ($ val, $ final)) {$ final [$ val] = $ last [$ val] + 1; } And {$ last [$ val] = 0; }}} Count = 0; Foreign currency ($ k = $ => $ v as final) {$ json [$ count] ['label'] = $ k; $ Json [$ count] ['data'] = $ v; $ Count ++; Echo json_encode ($ json); ? & Gt; Results: [{"label": "brawl", "data": 4}, {"label": "inxicated_persons", " Data ": 4 }]
No comments:
Post a Comment