2017-12-18 114 views
0

我試圖使用Amcharts庫繪製散點圖,我的數據是時間序列。我米有一個困難時期繪製它,帶時間序列數據的Amchart散點圖

下面

是我的什麼我都試過javascript代碼,到目前爲止:

var chart = AmCharts.makeChart("chartdiv", { 
    "type": "xy", 
"dataProvider": [{'nj6kJemGCxKx5dTxZ4dDNW': '95.025', 'lineColor': '#00ff00', 'x_axis_value': '0:10:06'}, {'nj6kJemGCxKx5dTxZ4dDNW': '94.067', 'lineColor': '#00ff00', 'x_axis_value': '0:10:07'}, {'nj6kJemGCxKx5dTxZ4dDNW': '98.055', 'lineColor': '#00ff00', 'x_axis_value': '0:10:08'}, {'nj6kJemGCxKx5dTxZ4dDNW': '97.136', 'lineColor': '#00ff00', 'x_axis_value': '0:10:09'}, {'nj6kJemGCxKx5dTxZ4dDNW': '97.136', 'lineColor': '#00ff00', 'x_axis_value': '0:10:10'}], 
    "valueAxes": [ { 
     "axisAlpha": 0, 
     "dashLength": 1, 
     "position": "left", 
     "title": "Y Axis" 
    }], 
    "dataDateFormat": "JJ:NN:SS", 
    "graphs": [{ 
     "balloonText": "x:[[x]] y:[[y]]", 
     "bullet": "triangleUp", 
     "lineAlpha": 0, 
     "xField": "x_axis_value", 
     "yField": "nj6kJemGCxKx5dTxZ4dDNW", 
     "lineColor": "#FF6600", 
     "fillAlphas": 0 
    }], 
} 
); 

這裏的jsfiddle:http://jsfiddle.net/Shivin15/o3kp2dqb/

什麼我M任何建議做錯了?

謝謝你的幫助。

回答

1

您需要通過創建第二個數值軸並將它的type設置爲"date"來指定您的x軸是基於日期時間的。您還需要修復您的數據包含兩位數小時爲單數的小時數是will not workdataDateFormat

更新演示:

var chart = AmCharts.makeChart("chartdiv", { 
 
    "type": "xy", 
 
    "dataProvider": [{ 
 
    'nj6kJemGCxKx5dTxZ4dDNW': '95.025', 
 
    'lineColor': '#00ff00', 
 
    'x_axis_value': '00:10:06' 
 
    }, { 
 
    'nj6kJemGCxKx5dTxZ4dDNW': '94.067', 
 
    'lineColor': '#00ff00', 
 
    'x_axis_value': '00:10:07' 
 
    }, { 
 
    'nj6kJemGCxKx5dTxZ4dDNW': '98.055', 
 
    'lineColor': '#00ff00', 
 
    'x_axis_value': '00:10:08' 
 
    }, { 
 
    'nj6kJemGCxKx5dTxZ4dDNW': '97.136', 
 
    'lineColor': '#00ff00', 
 
    'x_axis_value': '00:10:09' 
 
    }, { 
 
    'nj6kJemGCxKx5dTxZ4dDNW': '97.136', 
 
    'lineColor': '#00ff00', 
 
    'x_axis_value': '00:10:10' 
 
    }], 
 
    "valueAxes": [{ 
 
    "axisAlpha": 0, 
 
    "dashLength": 1, 
 
    "position": "left", 
 
    "title": "Y Axis" 
 
    }, { 
 
    "position": "bottom", 
 
    "title": "X Axis", 
 
    "type": "date" 
 
    }], 
 
    "dataDateFormat": "JJ:NN:SS", 
 
    "graphs": [{ 
 
    "balloonText": "x:[[x]] y:[[y]]", 
 
    "bullet": "triangleUp", 
 
    "lineAlpha": 0, 
 
    "xField": "x_axis_value", 
 
    "yField": "nj6kJemGCxKx5dTxZ4dDNW", 
 
    "lineColor": "#FF6600", 
 
    "fillAlphas": 0 
 
    }], 
 
});
html, body { 
 
    width: 100%; 
 
    height: 100%; 
 
} 
 

 
#chartdiv { 
 
    width: 100%; 
 
    height: 100%; 
 
}
<script src="https://www.amcharts.com/lib/3/amcharts.js"></script> 
 
<script src="https://www.amcharts.com/lib/3/xy.js"></script> 
 
<script src="https://www.amcharts.com/lib/3/themes/light.js"></script> 
 
<script src="https://www.amcharts.com/lib/3/plugins/export/export.min.js"></script> 
 
<link rel="stylesheet" href="https://www.amcharts.com/lib/3/plugins/export/export.css" type="text/css" media="all" /> 
 
<div id="chartdiv"></div>

+0

太謝謝你了 –