Sign in to follow this  
Gnacer

Using Associative Arrays

Recommended Posts

Does anyone know if it is possible to use multi-dimensional associative arrays to generate chart data.

 

I am trying to write my own extention to FC, but am running into a snag when it comes to making entries line up where they should.

 

In the following examply of what I'm trying to do, I have 3 categories (employees) along the X-axis, and I have 3 dataset (Bid, Awards, Completed).

 

2 of the employees have both Bids and Awarded Data, while the third only has Completed Data. I would like to pass the associated array, and have the chart reflect the data correctly.

 

      $data['Emp 1']['Bids'] = 14;
      $data['Emp 1']['Awarded'] = 4;
      $data['Emp 2']['Bids'] = 12;
      $data['Emp 2']['Awarded'] = 3;
      $data['Emp 3']['Complete'] = 20;

      foreach ($data as $k => $v) {
       $FC->AddCategory($k);
       foreach ($v as $k1 => $v1) {
        if ($v1 != 0) {
         $sets[$k1][$k] = $v1;
        } else {
         $sets[$k1][$k] = '';
        }
       }
      }

      foreach ($sets as $k => $v) {
       $FC->AddDataset($k);
       foreach ($v as $val) {
        $FC->AddChartData($val);
       }
      } 

 

However, when I do this, the 20 jobs listed for Emp 3 and Completed wind up under Emp 1 Completed. Without several 'foreach' loops created empty data to ensure placeholders are there so the data shows up correct, is there a better way to handle this problem?

 

Any help would be appreciated

Share this post


Link to post
Share on other sites
Guest Angshu

Hi,

 

Welcome to FusionCharts Forum! smile.gif

 

FusionCharts PHP class functions are used to to plot charts from data contained in PHP arrays.

 

To know more, please visit the links below:

 

http://docs.fusioncharts.com/charts/?guide-for-web-developers/php-class/PHPClass_Array.html

 

http://docs.fusioncharts.com/charts/?guide-for-web-developers/fusioncharts-php-class/Functions.html

 

Hope this helps.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this