-1

我在控制台中从 mtgox api 正确接收数据。但是,我无法让数据显示在我的图表上。我正在使用高图表。任何帮助表示赞赏。我的代码发布在下面。谢谢。

Javascript代码:

$(document).ready(function() {

  $.ajax({
    url: "/chart/ajax_get_chart", // the URL of the controller action method
    dataType: "json",
    type: "GET",
    success: function(result) {
      var result = JSON.parse(result);
      var date = new Array();
      var price = new Array();
      for (var i = 0; i < result.length; i++) {
        date.push(result[i]['date']);
        price.push(result[i]['price']);
      }

      $(function () {
        console.log(date);
        $('#container').highcharts({
            chart: {
                type: 'line',
                marginRight: 130,
                marginBottom: 25
            },
            title: {
                text: 'Bitcoin Price',
                x: -20 //center
            },
            subtitle: {
                text: 'Source: MtGox.com',
                x: -20
            },
            xAxis: {
                categories: 'datetime'
            },
            yAxis: {
                title: {
                    text: 'Price'
                },
                plotLines: [{
                    value: 'Price',
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                valueSuffix: '°C'
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'top',
                x: -10,
                y: 100,
                borderWidth: 0
            },
            series: [{
                name: 'Bitcoin',
                data: price
            }]
        });
      });
    }  
  });

}); 

模型:

public function ajax_get_chart() {

    $quotes = $this->rest->get('api/1/BTCUSD/trades/fetch');

    $series_data = array();

    $results = $quotes->return;

    foreach ($results as $quote)
    {
      $series_tmp = array(
        'date'      =>  $quote->date,
        'price'     =>  $quote->price
      );

      $series_data[] = $series_tmp;
    }

    return json_encode($series_data);
  }


}
4

1 回答 1

0

尝试改变这个:

$('#container').highcharts({
    chart: {
        type: 'line',
        marginRight: 130,
        marginBottom: 25
    },

对此:

var chart = new Highcharts.Chart({
    chart: {
        renderTo: 'container'
        type: 'line',            
        marginRight: 130,
        marginBottom: 25
    },
于 2013-06-14T19:05:49.993 回答