过去两周我在HighChart.js工作。但我坚持以下问题。
我在console.log中的数据与数据相同:
[0.061047,0.061047,0.061047,0.061047,0.061048,0.061033,0.061033,0.061015,0.061015,0.061016,0.061013,0.061013,0.06102,0.061021,0.061035,0.061027,0.061019,0.061018,0.061016,0.061016,0.061014,0.061013]
但是当我将项作为数据时,它什么也没有显示,但是当我静态地输入上述数据时,图表数据已经显示出来。这是我所面临的完全不合逻辑的问题。
请帮帮我。
<script>
$(document).ready(function () {
var items = [];
var index = '';
$.ajax({
type: 'GET',
url: 'http://localhost/HighChart-Js/json_demo.txt',
data: { get_param: 'value' },
dataType: 'json',
success: function (data) {
$.each(data, function(index, element) {
items += ','+element.price;
});
items = items.replace(/^,/, '');
items = "[" + items + "]";
items = $.trim(items);;
}
});
setTimeout(function(){
var d = new Date();
d = d.setDate(d.getDate() - 1);
var baseConfig = {
credits: {
enabled: false
},
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
backgroundColor:'rgba(255, 255, 255, 0.0)'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.y:,.7f}</b>',
percentageDecimals: 1
},
yAxis: {
gridLineWidth: 0
},
plotOptions: {
area: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false,
color: '#000000',
connectorColor: '#000000'
},
marker: {
enabled: false,
symbol: 'circle',
radius: 2,
states: {
hover: {
enabled: true
}
}
}
}
}
};
console.log(items); // ITEMS VARIABLE SHOWS DATA IN CONSOLE BUT WHEN I PUT THE VARIABLE AS A DATA ABOVE, IT SHOWS NOTHING
var data1 = {
title: {
text: 'ETH'
},
subtitle : {
text: "Ethereum"
},
xAxis : {
type: 'datetime'
},
yAxis: {
min: 0,
gridLineWidth: 0
},
series: [{
name: 'Ethereum',
type: 'area',
data: items, // THIS IS THE ITEM VARIABLE THAT IS NOT WORKING HERE
allowDecimals: true,
pointStart: d,
pointInterval: 3600000
}]
};
$('#container1').highcharts(
$.extend(baseConfig, data1)
);
}, 1500);
});
</script>
抱歉编辑。 json_demo.txt有以下数据。
[{"timestamp":1523430220,"tid":224440488,"price":"0.061047","amount":"0.37550269","exchange":"bitfinex","type":"buy"},{"timestamp":1523430220,"tid":224440487,"price":"0.061047","amount":"0.62669802","exchange":"bitfinex","type":"buy"},{"timestamp":1523430214,"tid":224440471,"price":"0.061047","amount":"0.26241442","exchange":"bitfinex","type":"buy"},{"timestamp":1523430214,"tid":224440467,"price":"0.061047","amount":"0.0698787","exchange":"bitfinex","type":"buy"},{"timestamp":1523430212,"tid":224440428,"price":"0.061048","amount":"7.43158","exchange":"bitfinex","type":"buy"},{"timestamp":1523430212,"tid":224440427,"price":"0.061033","amount":"3.0","exchange":"bitfinex","type":"buy"},{"timestamp":1523430212,"tid":224440426,"price":"0.061033","amount":"0.95899114","exchange":"bitfinex","type":"buy"},{"timestamp":1523430202,"tid":224440409,"price":"0.061015","amount":"3.0","exchange":"bitfinex","type":"buy"},{"timestamp":1523430202,"tid":224440408,"price":"0.061015","amount":"0.39885059","exchange":"bitfinex","type":"buy"},{"timestamp":1523430185,"tid":224440327,"price":"0.061016","amount":"0.02","exchange":"bitfinex","type":"buy"},{"timestamp":1523430184,"tid":224440324,"price":"0.061013","amount":"0.22349968","exchange":"bitfinex","type":"buy"},{"timestamp":1523430184,"tid":224440323,"price":"0.061013","amount":"0.43187032","exchange":"bitfinex","type":"buy"}]
答案 0 :(得分:0)
我得到了答案。
使用PARSE,JSON.parse(items)
已显示图表数据。