Jump to content

Chart graphique avec data dynamique


Recommended Posts

Je suis entrain d'afficher un graphe dynamique .En cas ou il ya des mutiples data , il maffiche qu'une courbe .Comment je pourrai faire pour que je puisse afficher plusieurs courbes selon les data .

// fichier.tpl

<style>
   #container {
    height:100%;
    width:100%;
    position:absolute;
}  
</style>
<script src="http://code.highcharts.com/highcharts.js"></script>

<script>

 alert("chrt graphique !!");
    $(document).ready(function(){
    $.ajax({
        url: "fichier.json",
        method: "GET",
        dataType : "text" ,
        success: function(data) {
            //console.log(data);
            var obj = JSON . parse( data );
          
            var prod=obj.hits.hits;
            var allName=[];
            var allPrice=[];
            var allTime=[];
            
          

            for(var i in prod) {
                
        
                allPrice.push(prod._source.price);
                allTime.push(prod._source.timestamp);
                allName.push(prod._source.marketplace);

           
           } 
          
   

$(function () {
    $('#container').highcharts({
        chart: {
            type: 'line'
        },
        title: {
            text: 'chart graphique'
        },
        yAxis: {
        title: {
            text: 'Prix'
        }
       },


        xAxis: {
            categories: allTime
        },
        series: [{
             name:allName[0],
            data: allPrice}


          
            
           ]
           
    });
});

 

        },
        error: function(data) {
            console.log(data);
        }
    });
});


     
   
</script>

<div id="container" ></div>

Link to comment
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
×
×
  • Create New...