2016-03-28 12 views
0

Ben HIGHCHARTS ile yeni başlayan biriyim. android çalış canlı stok grafik çalışma json data kullanarak URL

http://people.canonical.com/~bradf/media/highstock/examples/basic-line/index.htm

$(function() { 
 

 
    $.getJSON('http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback=?', function(data) { 
 
    // Create the chart 
 
    window.chart = new Highcharts.StockChart({ 
 
     chart: { 
 
     renderTo: 'container' 
 
     }, 
 

 
     rangeSelector: { 
 
     selected: 1 
 
     }, 
 

 
     title: { 
 
     text: 'AAPL Stock Price' 
 
     }, 
 

 
     series: [{ 
 
     name: 'AAPL', 
 
     data: data, 
 
     tooltip: { 
 
      valueDecimals: 2 
 
     } 
 
     }] 
 
    }); 
 
    }); 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="http://code.highcharts.com/stock/highstock.js"></script> 
 
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script> 
 

 
<div id="container" style="height: 500px; min-width: 500px"></div>
Ben gelen JSON dosyasını indirildi:

Ben bu örnekten başlamak istiyorum

http://chartapi.finance.yahoo.com/instrument/1.0/PTC/chartdata;type=quote;range=1d/json/

Ve yerel olarak çalıştırmak istiyorum (ve test ettikten sonra kendi JSON dosyalarım ile). Ama işe yaramıyor!

Örneğin kaynak kodunu kullanıyorum, sadece getJSON satırını değiştirdim.

bu var: -

$.getJSON('./data/json/'+ name+'-c.json&callback=?', function(data) { ....... } 

Sorunun callback.Any fikirler geldiğini düşünüyorum?

+0

"callback =?' - "callback = finance_charts_json_callback" öğesini değiştirmeyi dener misiniz? JSONP'niz var, bu nedenle bir sebep olabilir. Ayrıca, arka sayfa olarak bazı web sunucunuzun olduğundan emin olun - modern tarayıcılar yerel dosyaları yüklemeye izin vermiyor. –

cevap

0

Veriyi, yüksek şemalar için doğru biçimde almak için bağladığınız örnekteki kodu değiştirdim. Bunun yapmanın en iyi yolu olduğundan emin değilsiniz, ancak JSON verilerini görüntülemek için JSON.stringify'u kullanabilir ve ondan istediğiniz alanları elde edebilirsiniz ("Zaman damgası" ve "kapat"). Daha fazla yorumda-- umarım yardımcı olur!

$(function() { 
 

 
    // add ?callback=? 
 

 
    $.getJSON('http://chartapi.finance.yahoo.com/instrument/1.0/PTC/chartdata;type=quote;range=1d/json/?callback=?', function(data) { 
 
     // console.log(data.series); 
 
     // console.log(JSON.stringify(data.series)); 
 
     // extract the data you need 
 
     myData = []; 
 
     data.series.forEach(function(item) { 
 
     myData.push([item.Timestamp, item.close]); 
 

 
     }); 
 
     console.log(JSON.stringify(myData)); 
 
     // Create the chart 
 
     window.chart = new Highcharts.StockChart({ 
 
     chart: { 
 
      renderTo: 'container' 
 
     }, 
 

 
     rangeSelector: { 
 
      selected: 1 
 
     }, 
 

 
     title: { 
 
      text: 'AAPL Stock Price' 
 
     }, 
 

 
     series: [{ 
 
      name: 'AAPL', 
 
      // use extracted data 
 
      data: myData, 
 
      tooltip: { 
 
      valueDecimals: 2 
 
      } 
 
     }] 
 
     }); 
 
    }) 
 
    // check for errors 
 
    .done(function() { 
 
     console.log('getJSON request succeeded!'); 
 
    }) 
 
    .fail(function() { 
 
     console.log('getJSON request failed! '); 
 
    }) 
 
    .always(function() { 
 
     console.log('getJSON request ended!'); 
 
    }); 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="http://code.highcharts.com/stock/highstock.js"></script> 
 
<script src="http://code.highcharts.com/stock/modules/exporting.js"></script> 
 
<div id="container" style="height: 500px; min-width: 500px"></div>

DÜZENLEME: ve ben https://stackoverflow.com/a/19075640/2314737

// check for errors 
    .done(function() { 
     console.log('getJSON request succeeded!'); 
    }) 
    .fail(function() { 
     console.log('getJSON request failed! '); 
    }) 
    .always(function() { 
     console.log('getJSON request ended!'); 
    }); 
+0

@sushant, ihtiyacınız olan şey net değil ... konsolun hata mesajlarını kontrol ettiniz mi? – user2314737

+0

Çevrimiçi yahoo hisse senedi grafiğine ihtiyacım var .. ama bu görüntülenemedi – sushant

0

this ne Highcharts tüketir benzer bir şey için karşılık gelen JSON formatını manipüle Lütfen olduğu gibi hata mesajlarını kontrol etmek öneriyoruz .

İlgili konular