1. roberto.aloi
  2. highcharts-php
Issue #4 new

Array of arrays as series data

pembeci
created an issue

Some chart types (i.e. scatter) require the series data to be an array of arrays. For such cases current HighchartsArray conversion is not working. Here is a possible solution to fix this:

{{{

!php

class HighchartsArray { private $_array; public function HighchartsArray($array) { $this->_array = $this->convert_to_HA($array); }

// added a recursive function private function convert_to_HA($array) { $new_array = array(); foreach ($array as $elem) if (is_string($elem)) $new_array []= '\'' . $elem . '\''; else if (is_array($elem)) { // additional check $sub_array = '[' . implode(',', $this->convert_to_HA($elem)) . ']'; $new_array []= $sub_array; } else $new_array []= $elem; return $new_array; }

public function get() { $js_array = '['; $js_array .= implode(',', $this->_array); $js_array .= ']'; return $js_array; } } }}}

I am not very used to write code for PHP classes so I don't know if this is the best method to achieve this but the ultimate solution may follow the general idea here.

Comments (5)

  1. Anonymous

    pembeci, can you try it? I´m unable to do things like:

    series: [{ type: 'pie', name: 'Browser share', data: [ ['Firefox', 44.2], ['IE7', 26.6], { name: 'IE6', y: 20, sliced: true, selected: true }, ['Chrome', 3.1], ['Safari', 2.7], ['Opera', 2.3], ['Mozilla', 0.4] ]

  2. Log in to comment