我正在尝试使用日期而不是默认的 1、2、3、4 等向我的 X 轴添加轴标签。
从服务器返回的 date_time 也需要转换为可读的日期/时间。
任何帮助表示赞赏。
代码
<script type="text/javascript">
var chart;
var store;
require(["dojo/request/xhr",
"dojo/json",
"dojo/store/Memory",
"dojo/store/Observable",
"dojox/charting/StoreSeries",
"dojox/charting/Chart2D",
"dojox/charting/plot2d/Lines",
"dojox/charting/axis2d/Default",
"dojo/domReady!"],
function(xhr, JSON, Memory, Observable, StoreSeries, Chart) {
xhr("json_result.php",{
handleAs: "json"
}).then(function(data){
store = Observable(new Memory({data: data}));
chart = new Chart("graph");
chart.addPlot("default", {type: "Lines", markers:true});
chart.addAxis("x", {title:"Time", titleOrientation:"away"});
chart.addAxis("y", {vertical: true, majorTick: false, title:"Load"});
chart.addSeries("Load Cell 1", new StoreSeries(store, { query: { load_cell_id:0 }}, "kn"));
chart.addSeries("Load Cell 2", new StoreSeries(store, { query: { load_cell_id:1 } }, "kn"));
chart.render();
});
});
</script>
JSON 结果
[{"date_time":1351280845,"load_cell_id":0,"kn":56.8},{"date_time":1351280845,"load_cell_id":1,"kn":45},{"date_time":1351367241,"load_cell_id":0,"kn":23.7},{"date_time":1351367241,"load_cell_id":1,"kn":34.9},{"date_time":1351417945,"load_cell_id":0,"kn":56.9},{"date_time":1351417945,"load_cell_id":1,"kn":67.8},{"date_time":1353914066,"load_cell_id":0,"kn":12.4},{"date_time":1353914066,"load_cell_id":1,"kn":19.43},{"date_time":1353992714,"load_cell_id":0,"kn":45.8},{"date_time":1353992714,"load_cell_id":1,"kn":40.8}]