PhoneGap and Highcharts
PhoneGap and Highcharts
我正在使用Highcharts的混合移动应用程序(Cordova-Phonegap),我正在从数据库中查询数据,并试图在图表上动态显示数据。
这是获取数据的代码,这是有效的。
var exerciseData = [];//global
var chart;//global
编辑2:$(document).ready(function() {
//chart is here
}
//Cordova is ready
function onDeviceReady() {
db.transaction(queryDB);
}
//查询数据库
function queryDB(tx) {
//get all results from db
tx.executeSql('SELECT * FROM MYTABLE', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
var len = results.rows.length;
console.log("MYTABLE table: " + len + " rows found.");
for (var i=0; i<len; i++){
console.log("Row = " + i + " Reading_name = " + results.rows.item(i).Reading_name + " Date="+results.rows.item(i).Rec_date + " Reading = " + results.rows.item(i).Reading);
//get exercise data only
if(results.rows.item(i).Reading_name=='exercise'){
var reading=parseInt(results.rows.item(i).Reading);
var thisDate=results.rows.item(i).Rec_date;
var exObj=([manageDate(thisDate), reading]);
exerciseData.push(exObj);
}
}
}
现在,当我取exerciseData
并设置如下:
chart.series[0].setData(exerciseData,true);
则图表上不显示任何内容。
但是如果我将它设置为:
chart.series[0].setData([[1383824000000,10] ],true);
然后我可以看到图表上的数据点。
我如何修复exerciseData
数组显示数据Highchart图表系列?
console.log(exObj);
显示:
[1363996800000, 10]
和console.log(exerciseData);
给出了这个:
[
Array[2]
0: 1363996800000
1: 10
length: 2
__proto__: Array[0]
]
编辑:图表的代码
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
defaultSeriesType: 'line'
},
title: {
text: 'chart'
},
xAxis: {
type: 'datetime',
labels: {
formatter: function() {
return Highcharts.dateFormat('%a %d %b', this.value);
},
dateTimeLabelFormats: {
minute: '%H:%M',
hour: '%H:%M',
day: '%e. %b',
week: '%e. %b',
month: '%b ''%y',
year: '%Y'
}
}
},
yAxis: {
title: {
text: ''
},
min: 0
},
series: [
{
name: 'Exercise',
data: [],
type:'spline'
},
{
name: 'MyData2',
data: [],
type:'line'
});
chart.series[0].setData(exerciseData,true);//does not work
chart.series[1].setData([[1383824000000,10]],true);
});
试试这个:
var exObj=[];
exObj.push(manageDate(thisDate));
exObj.push(reading);
exerciseData.push(exObj);
另一种方法是用x,y来指定点,例如
var exObj = {
x:manageDate(thisDate),
y:reading
}
还需要调用
chart.series[0].setData(exerciseData,true
相关文章:
- 在Web应用程序中使用Highcharts javascript
- 在Highcharts中,我们可以通过任何方式在渲染图表之前获得plotWidth和plotHeight
- Selenium WebDriver and JavaScript change
- HighCharts长标题文本在某些元素上重叠
- Highcharts colorsByPoint与系列中的线性渐变一起使用时不起作用
- Highcharts-如何在自定义格式化程序中获得默认的y轴标签格式化程序
- Highcharts仪表未显示
- 可以使用highcharts导出图表AND表数据
- JSON and Highcharts
- Svg and Highcharts?
- JSon with HighCharts and ASP.NET
- JSF, HighCharts and JS
- Highcharts and Extjs 4
- Highcharts and JSON problems
- Highcharts error #13 and AngularJs
- highcharts.js and highstock.js conflict
- Node.js, express, jade, highcharts and 2D array
- Highcharts and durandal
- PhoneGap and Highcharts
- HIghcharts and dynamic json