2012-05-01 1 views
0

si nous avons un code comme celui-ciJSON dans une variable puis passer

yAxis : { 
      title : { 
       text : 'Exchange rate' 
      }, 
      plotLines : [{ 
       value : 0.6738, 
       color : 'green', 
       dashStyle : 'shortdash', 
       width : 2, 
       label : { 
        text : 'Last quarter minimum' 
       } 
      }, { 
       value : 0.7419, 
       color : 'red', 
       dashStyle : 'shortdash', 
       width : 2, 
       label : { 
        text : 'Last quarter maximum' 
       } 
      }] 
     }, 

comment puis-je prendre la plotlines chaîne JSON et ASIGN à une variable et de transmettre cette variable à l'objet plotline ?? ? J'ai essayé quelque chose comme ça

var jsonObj = []; 
jsonObj.push({ "value": 1256211571000, "color": '#D2691E', "width": 1, "label": { "text": 'rinse'} }); 
     var myLines = JSON.stringify(jsonObj); 

et passe ensuite à mylines plotlines mais ça n'a pas vraiment

+0

Que voulez-vous faire? Pourquoi utilisez-vous 'JSON Que voulez-vous dire par "passer la variable à [un] objet"? –

Répondre

1

Si l'on suppose cet objet est dans une variable appelée data, il suffit de faire:

data.yAxis.plotLines.push({ 
    "value": 1256211571000, 
    "color": '#D2691E', 
    "width": 1, 
    "label": { 
     "text": 'rinse' 
    } 
}); 

Ceci est juste un objet JavaScript, pas JSON. JSON est une représentation de chaîne d'un objet (ou tableau).

0

Voici un exemple, si cela fonctionne pour vous '

$ (document) .ready (function() {

 $.getJSON('yourpage.php?getdata=y&compid=<?php echo $comp_details[0]['id']; ?>', function(data) { 

      // split the data set into ohlc and volume 
      var ohlc = [], 
      volume = [], 
      dataLength = data.length; 

      for (i = 0; i < dataLength; i++) { 
       //console.log(data[i][2]); 
       ohlc.push([ 
        data[i][0], // the date 
        data[i][1], // open 
        data[i][2], // high 
        data[i][3], // low 
        data[i][4] // close 
       ]); 

       volume.push([ 
        data[i][0], // the date 
        data[i][5] // the volume 
       ]) 
      } 

      // set the allowed units for data grouping 
      var groupingUnits = [[ 
        'week',       // unit name 
        [1]        // allowed multiples 
       ], [ 
        'month', 
        [1, 2, 3, 4, 6] 
       ]]; 

      // create the chart 
       chart = new Highcharts.StockChart({ 
       chart: { 
        renderTo: 'container', 
        alignTicks: false, 
        zoomType: 'x' 
       }, 

       rangeSelector: { 
        selected: 0 
       }, 

       title: { 
        text: '<?php echo strtoupper($_GET['CompanySymbol']); ?>'+' Historical' 
       }, 

       yAxis: [{ 
         title: { 
          text: 'OHLC' 
         }, 
         height: 200, 
         lineWidth: 2, 
         min:0 
        }, { 
         title: { 
          text: 'Volume' 
         }, 
         top: 300, 
         height: 100, 
         offset: 0, 
         lineWidth: 2 

        }, 
        { 

         height: 200, 
         min: 0, 
         lineWidth: 2, 
         opposite: true 

        }], 
       tooltip: { 
        crosshairs: [true,true], 
        shared: true 
       }, 

       series: [{ 
         type: 'ohlc', 
         name: '<?php echo strtoupper($_GET['CompanySymbol']); ?>', 
         data: ohlc, 
         dataGrouping: { 
          units: groupingUnits 
         } 
        }, 
        { 
         type: 'line', 
         name:'Fuerte', 
         yAxis: 2, 
         data:[<?php echo $newdata; ?>] 
        }, 
        { 
         type: 'line', 
         name:'Debil', 
         yAxis: 2, 
         data:[<?php echo $newdata1; ?>] 
        }, 
        { 
         type: 'column', 
         name: 'Volume', 
         data: volume, 
         yAxis: 1, 
         dataGrouping: { 
          units: groupingUnits 
         } 
        }] 
      }); 
       chart.yAxis[2].setExtremes(10,90); 
     }); 
    });' 
Questions connexes