解析数据时间仅显示YYYY Plot.ly javascript

时间:2018-11-25 22:37:37

标签: javascript parsefloat

我有一个要解析为Plot.ly的数据集,可用于javascript。我的问题是,尽管我的数据被定义为“ yyyy-mm-dd hh:MM:ss”,但在解析后我只能看到yyyy。当我错了还是我想念什么?

我的脚本如下:

processData = function(dataset) {

// Data is in the dataset in a column based format, where each column 
   has an array of data
// eg. dataset.column_name[0].raw_data, 
  dataset.column_name[0].formatted_data
data={x: [], y1: [], y2: [], y3: [], y4: []}
for (i=0;i<dataset['datetime'].length;i++){
   data['x'].push(parseFloat(dataset['datetime'][i].raw_data));
   data['y1'].push(parseFloat(dataset['mp_price'][i].raw_data));
   data['y2'].push(parseFloat(dataset['upper'][i].raw_data));
   data['y3'].push(parseFloat(dataset['lower'][i].raw_data));
   data['y4'].push(parseFloat(dataset['market_price'][i].raw_data));
 }
return data
  },

 doDrawing = function(data, $chartDiv, height, width, errorFunction) {

 // Use require to load the javascript libraries you need

 // Libraries we ship with and their location:
 // js/chartingLibraries/c3/c3
 // js/chartingLibraries/chartjs/Chart
 // js/chartingLibraries/d3_3.5.17/d3_3.5.17
 require(['https://cdn.plot.ly/plotly-latest.min.js'], function(Plotly) 
 {

var trace1 = {
x: data['x'],
y: data['y1'],
mode: 'markers',
type: 'scatter',
name: 'Trade Price'
};

var trace2 = {
x: data['x'],
y: data['y2'],
mode: 'lines+markers',
type: 'line',
name: 'Upper Threshold'
};

var trace3 = {
x: data['x'],
y: data['y3'],
mode: 'lines+markers',
type: 'line',
name: 'Lower Threshold'
};

var trace4 = {
x: data['x'],
y: data['y4'],
mode: 'lines+markers',
type: 'line',
name: 'Market Price'
};

var layout = {
title: 'Off Market Trades',
xaxis: {
title: 'Year',
showgrid: true,
zeroline: false
},
yaxis: {
title: 'Trade Values and Thresholds',
showline: false
}
};

var data2 = [trace1, trace2, trace3, trace4];

Plotly.newPlot($chartDiv[0], data2, layout);
});
}

一行数据示例为:
日期时间:2018-11-22 09:28:15.0 mp_price:5.2 市价:5.1 较低:4.8 上:5.6

0 个答案:

没有答案