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 !

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.