2014-12-19 76 views
0

我已将my PHP code与代码接收到的数据数组(一个JSONP调用)转移到JSfiddle(带有“本地”数据阵列)。奇怪的是,虽然它在PHP中起作用,但它并不是小提琴。具有相同代码/数据集的Highcharts代码在PHP中工作,但在JSfiddle中不起作用

必须与数据数组的东西,我猜,但不知道。

$(function() { 
var options = { 
    chart: { 
     renderTo: 'container', 
     type: 'spline', 
     marginBottom: 50 
    }, 
    xAxis: { 
     labels: 
     { 
      formatter: function() { 
       return Highcharts.numberFormat(this.value, 0, '', ''); // Remove the thousands separator 
      } 
     }, 
     tickWidth: 0, 
     endOnTick: true, 
     showLastLabel: true 
    }, 
    title: 
    { 
     text: "Title", 
     align: "center", 
     y: 20, 
     style: 
     { 
      fontFamily: "Arial", 
      fontSize: "20px", 
      fontWeight: "bold", 
      color: (Highcharts.theme && Highcharts.theme.textColor) || "black" 
     } 
    }, 
    credits: 
    { 
     text: " Source: UNEP (2014): The UNEP Environmental Data Explorer, as compiled from XXXXXX. United Nations Environment<br />Programme. http://geodata.grid.unep.ch. ", 
     url: "", 
     position: 
     { 
      align: "left", 
      x: 80, 
      y: -15 
     }, 
     style: 
     { 
      fontSize: "9px", 
      lineHeight: "9px" 
     } 
    },     
    legend: 
    { 
     layout: "vertical", 
     align: "center", 
     verticalAlign: "bottom", 
     backgroundColor: "#efefef", 
     borderWidth: 0, 
     floating: false, 
     y: -50, 
     title: 
     { 
      text: ":: Legend ::" 
     }, 
     floating: true, 
     draggable: true, 
     zIndex: 20 
    }, 
    tooltip: 
    { 
     shared: true, 
     crosshairs: true 
    }, 
    plotOptions: 
    { 
     series: 
     { 
      marker: 
      { 
       enabled: false 
      } 
     } 
    }, 
    series: [{}] 
}; 


/* This would come from my JSON call */ 
data = '[{"name":"France","data":[[1960,520325],[1961,548976],[1962,585604],[1963,616918],[1964,657130],[1965,688528],[1966,724428],[1967,758391],[1968,790691],[1969,845964],[1970,894468],[1971,942148],[1972,984897],[1973,1050000],[1974,1099250],[1975,1086890],[1976,1134560],[1977,1175100],[1978,1220870],[1979,1262980],[1980,1283650],[1981,1296210],[1982,1327540],[1983,1343900],[1984,1363980],[1985,1385940],[1986,1417210],[1987,1451060],[1988,1518790],[1989,1582390],[1990,1623850],[1991,1640720],[1992,1664970],[1993,1653860],[1994,1691030],[1995,1725650],[1996,1744070],[1997,1782150],[1998,1842360],[1999,1903010],[2000,1973040],[2001,2009260],[2002,2027920],[2003,2046160],[2004,2098230],[2005,2136560],[2006,2189260],[2007,2239300],[2008,2237490],[2009,2167070],[2010,2204450]]}]'; 


/* load the stuff in the JSON like this= */ 
options.series = data; 

var chart = new Highcharts.Chart(options); 

}); 

如果有人能给我一个提示什么是错的,那将是很棒的。

回答

0

您将它作为字符串data ='...'传递。删除单引号''

data = [{"name":"France","data":[[1960,520325],[1961,548976],[1962,585604],[1963,616918],[1964,657130],[1965,688528],[1966,724428],[1967,758391],[1968,790691],[1969,845964],[1970,894468],[1971,942148],[1972,984897],[1973,1050000],[1974,1099250],[1975,1086890],[1976,1134560],[1977,1175100],[1978,1220870],[1979,1262980],[1980,1283650],[1981,1296210],[1982,1327540],[1983,1343900],[1984,1363980],[1985,1385940],[1986,1417210],[1987,1451060],[1988,1518790],[1989,1582390],[1990,1623850],[1991,1640720],[1992,1664970],[1993,1653860],[1994,1691030],[1995,1725650],[1996,1744070],[1997,1782150],[1998,1842360],[1999,1903010],[2000,1973040],[2001,2009260],[2002,2027920],[2003,2046160],[2004,2098230],[2005,2136560],[2006,2189260],[2007,2239300],[2008,2237490],[2009,2167070],[2010,2204450]]}]; 

See fiddle

相关问题