0

Hi,
i'm trying to implement a flot.js graph using a custom php array as data.
Here is what i've done :

<?php 
foreach ( $dynamic_prices as $limit => $price ): 
    $coordonnees[] = array($limit,$price);
endforeach; 
?>

<?php
    echo json_encode(($coordonnees), JSON_NUMERIC_CHECK);
?>

This code outputs : [[5,9],[6,8]]
is it the right format ? I think it is if i believe the flot.js documentation.

Then my JQuery :

<script type="text/javascript">
$(document).ready(function () {

    var test = <?php echo $coordonnees ?>;
    var graphData = [{
        "label": "Paliers",
        "data": <?php echo $coordonnees ?>,
        color: '#71c73e'
    }];

    $.plot($('#graph-lines'), graphData, {
        series: {
            points: {
                show: true,
                radius: 5
            },
            lines: {
                show: true
            },
            shadowSize: 0
        },
        grid: {
            color: '#646464',
            borderColor: 'transparent',
            borderWidth: 20,
            hoverable: true
        },
        xaxis: {
            tickColor: 'transparent',
            tickDecimals: 0
        },
        yaxis: {
            tickSize: 5,
            tickDecimals: 0
        }
    });

Any idea to fix this ?
Thanks !

1
Contributor
1
Reply
8
Views
2 Years
Discussion Span
Last Post by Olivier_1
0

Hi,
i figured out how to fix it :
- remove "" from "data":
- add : var coords = <?php echo $coordonnees ?>;
- replace "data": <?php echo $coordonnees ?> with : data: coords,

Actually, i understand now that it was missing a coma after <?php echo $coordonnees?>; .... It may be the problem

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.