dimanche 30 décembre 2018

Cannot create array for keys and another for its values for Google GeoChart addRow() function

Lavacharts GeoChart displays the following structure:

    $popularity = Lava::DataTable();

    //creates lavachart GEOMAP chart providing values
    $popularity
            ->addStringColumn('Country')
            ->addNumberColumn('VALUE')
            ->addRow($value));
    Lava::GeoChart('Popularity', $popularity);

And ->addRow() request values in the following form:

->addRow(array('US', 200))
->addRow(array('BR', 300))

My current code generates $value using an array of countries:

    $countryIso[] = array('US', 'BR','CL');

and foreach country performs a calculation:

    foreach ($countryIso as $countrycode) {
        $value[] = $this->product->make_calculation();
    }

My problem:

Currently my code displays data in the following format:

Array ( [0] => 899.99 1 => 1214.9865 [2] => 1445.833935 )

And I cannot find the way to replace keys like [0] with values from $countryIso array

eg: [0] replaced by US , 1 replaced by BR ....

in order to create values in the way requested by Google GeoChart like:

->addRow(array('US', 200))

I tried with array_combine — "a function that creates an array by using one array for keys and another for its values" but with no success.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire