Javascript highcharts-php/mysql数据获取
我已经在另一个文件中回显了数据库中的数据。。现在我正在获取数据。我不熟悉jquery和highchart。。plz帮助 我传递的数据格式是:Javascript highcharts-php/mysql数据获取,javascript,jquery,highcharts,Javascript,Jquery,Highcharts,我已经在另一个文件中回显了数据库中的数据。。现在我正在获取数据。我不熟悉jquery和highchart。。plz帮助 我传递的数据格式是: [ {"name":"a","data":0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]}, {"name":"b","da
[
{"name":"a","data":0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]},
{"name":"b","data":[34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49]}
]
我的highchart代码是:
var chartOptions = {
chart: {
renderTo: 'container',
zoomType: 'x',
defaultSeriesType: 'line',
backgroundColor: null,
plotBackgroundColor: null,
borderRadius:20,
plotShadow: false,
events: {
load: function() {
// event.exporting.buttons.infoButton.symbolX=5;
// event.exporting.buttons.infoButton.symbolY=2;
// info_img=0;
// this.renderer.rect(5, 5, 60, 25, 15).attr({ fill: issue_col[1], zIndex: 0 }).add();
}
},
style: {
zIndex: 1
},
marginRight:30
},
title: {
text: 'hello',
style: {
fontFamily: 'Arial',
fontWeight: 'bold',
fontSize: '12px',
textShadow: 'none'
}
},
xAxis: {
type:'datetime',
title: {
text: null
}
},
yAxis: {
title: {
text: 'nothing is coming',
style: {
fontFamily: 'Arial',
fontWeight: 'bold',
fontSize: '12px',
textShadow: 'none'
}
},
min: 0.0,
},
credits: {
enabled: true,
position: {
align: 'center',
x: 10,
verticalAlign: 'bottom',
y: -3
},
href: "http://www.interscapetech.com",
style: {
cursor: 'pointer',
color: '#909090',
fontSize: '9px'
},
text: "(c)1997- Interscape Technologies Inc. All rights reserved."
},
/*labels:{
items: [{
html: "TM",
style: {
fontSize:'8px',
left: '330px',
top: '140px'
}
}],
style: {
color: 'grey'
}
},*/
lang:{
downloadButtonTitle:'Download Chart',
printButtonTitle :'Print Chart',
infoButtonTitle:'Chart Information',
switchButtonTitle:'Click to Enlarge'
// switchButtonTitle:'Switch to Bar Chart'
},
navigation:{
buttonOptions:{
align:'right',
verticalAlign:'middle',
height:15,
symbolFill: '#4572A7',
hoverSymbolFill: '#768F3E',
hoverBorderColor:'#92A8CD',
borderColor:'#3D96AE',
backgroundColor:'white',
borderRadius:5,
borderWidth:2,
width:20,
symbolX:10,
symbolY:8,
symbolSize:10
}
},
subtitle: {
text: '',
align:'left',
style: {
fontFamily: 'Arial',
fontWeight: 'bold',
fontSize: '12px',
textShadow: 'none',
color: 'white'
},
x:3, //-165 if center
y:12
},
plotOptions: {
line: {
lineWidth: 1,
marker: {
enabled: false,
states: {
hover: {
enabled: true,
radius: 5
}
}
},
shadow: false,
states: {
hover: {
lineWidth: 1
}
},
zindex:1
},
series:[{
zindex:1
}]
}
,
tooltip: {
formatter: function() {
var ctime= Highcharts.dateFormat('%m/%d/%Y %H:%M:%S',this.x);
var s = '<b>'+ ctime +'</b>';
$.each(this.points, function(i, point) {
var result=Math.round(point.y*10)/10;
s += '<br/>'+ point.series.name +': '+result;
});
return s;
},
shared: true,
backgroundColor: '#FCFFC5'
},
legend: {
itemStyle: {
fontFamily: 'Arial',
fontSize: '12px',
textShadow: 'none'
},
enabled: true
// symbolPadding: 10
},
series: []
};
$(document).ready(function()
{
var url='highchars_test2.php';
alert('helo');
$.getJSON(url, function(seriesData){
$(seriesData).each(function(i, pdata){
console.log();
if(i==(seriesData.length-1) || i==(seriesData.length-2))
{}
else
{
alert(pdata['data']);
chartOptions.series.push(pdata);
}
});
chart = new Highcharts.Chart(chartOptions);
});
});
var图表选项={
图表:{
renderTo:'容器',
zoomType:'x',
defaultSeriesType:“行”,
背景颜色:空,
plotBackgroundColor:null,
边界半径:20,
影子:错,
活动:{
加载:函数(){
//event.exporting.buttons.infoButton.symbolX=5;
//event.exporting.buttons.infoButton.symbolY=2;
//信息=0;
//rect(5,5,60,25,15).attr({fill:issue_col[1],zIndex:0}).add();
}
},
风格:{
zIndex:1
},
marginRight:30
},
标题:{
文字:“你好”,
样式:{
fontFamily:“Arial”,
fontWeight:'粗体',
fontSize:'12px',
textShadow:“无”
}
},
xAxis:{
类型:'datetime',
标题:{
文本:空
}
},
亚克斯:{
标题:{
文本:“什么都没有来”,
样式:{
fontFamily:“Arial”,
fontWeight:'粗体',
fontSize:'12px',
textShadow:“无”
}
},
最小值:0.0,
},
学分:{
启用:对,
职位:{
对齐:'居中',
x:10,
垂直排列:“底部”,
y:-3
},
href:“http://www.interscapetech.com",
风格:{
光标:“指针”,
颜色:“#9090”,
字体大小:“9px”
},
正文:“(c)1997-Interscape Technologies Inc.保留所有权利。”
},
/*标签:{
项目:[{
html:“TM”,
风格:{
字体大小:'8px',
左:“330px”,
顶部:“140px”
}
}],
风格:{
颜色:“灰色”
}
},*/
朗:{
下载按钮:'下载图表',
打印按钮:'打印图表',
信息按钮:'图表信息',
开关按钮:'单击以放大'
//SwitchButtonTile:“切换到条形图”
},
导航:{
按钮选项:{
对齐:'右',
垂直线:'中间',
身高:15,
symbolFill:“#4572A7”,
hoverSymbolFill:“#768F3E”,
悬停边框颜色:“#92A8CD”,
边框颜色:“#3D96AE”,
背景颜色:'白色',
边界半径:5,
边界宽度:2,
宽度:20,
symbolX:10,
符号:8,
符号化:10
}
},
副标题:{
文本:“”,
对齐:'左',
风格:{
fontFamily:“Arial”,
fontWeight:'粗体',
fontSize:'12px',
textShadow:'无',
颜色:“白色”
},
x:3,//-165(若中心)
y:12
},
打印选项:{
行:{
线宽:1,
标记:{
启用:false,
国家:{
悬停:{
启用:对,
半径:5
}
}
},
影子:错,
国家:{
悬停:{
线宽:1
}
},
zindex:1
},
系列:[{
zindex:1
}]
}
,
工具提示:{
格式化程序:函数(){
var ctime=Highcharts.dateFormat(“%m/%d/%Y%H:%m:%S”,this.x);
var s=''+ctime+'';
$.each(this.points,function(i,point){
var结果=数学四舍五入(点y*10)/10;
s+='
'+point.series.name+':'+结果;
});
返回s;
},
分享:是的,
背景颜色:“#FCFFC5”
},
图例:{
itemStyle:{
fontFamily:“Arial”,
fontSize:'12px',
textShadow:“无”
},
已启用:true
//符号:10
},
系列:[]
};
$(文档).ready(函数()
{
var url='highchars_test2.php';
警报(“直升机”);
$.getJSON(url,函数(seriesData){
$(seriesData)。每个(函数(i,pdata){
console.log();
if(i==(seriesData.length-1)|i==(seriesData.length-2))
{}
其他的
{
警报(pdata[‘数据’);
chartOptions.series.push(pdata);
}
});
图表=新的Highcharts.chart(图表选项);
});
});
无法创建图表。。plz help..就像在a系列中一样,在数据数组之前缺少方括号。在a系列中,数据格式不正确(缺少方括号) 我加上了这一点,它也起作用了
看看这个应该是
var url='highchars_test2.php'吗
而不是var url='highchars_test2.php代码>?单引号缺失?@shibly:是的。。同样的事情:-)。。我也试过了。。但是没有得到图表使用a[在你的线路上{“name”:“a”,“data”:
这是一个错误吗?谢谢Charles.编辑了Parsing我试着编辑数据..但仍然不起作用。我更改了if循环..现在它起作用了..非常感谢Torsteing