我正在构建一个应用程序来监视应用程序服务器上运行的服务数量。有关正在运行的服务的信息将存储在数据库中,我想在网页上显示其中的一些信息。在这一点上,我只想构建一个活跃运行的服务数量的图形表示,它随着数据库的更新而动态更新。目标是创建一个简单的图表,显示最近运行的服务数量的 10 个(左右)值,类似于 ekg 读数的样子。我正在使用 dojox.charting.Chart 小部件,但无法正确更新图表,因此它仅显示 numFailedAttempts:"0" 的十个最新值。就像现在一样,图表显示所有值,并且 x 轴值不断地越来越接近以容纳所有内容。根据 dojotoolkit.org 上的 dojo api 参考和文档,我认为 dojox.charting.Chart 的“displayRange”属性应该可以解决这个问题。所以我的问题是,我做错了什么?这是代码:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.6/dojo/resources/dojo.css">
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js" data-dojo-config="isDebug: true, parseOnLoad: true"></script>
<script type="text/javascript">
dojo.require("dojox.charting.StoreSeries");
dojo.require("dojox.charting.Chart2D");
dojo.require("dojo.store.Memory");
dojo.require("dojo.store.Observable");
dojo.require("dojox.charting.Chart");
dojo.require("dojox.charting.plot2d.Areas");
dojo.ready(function(){renderDataChart()});
function renderDataChart(){
//data from a database
var dataChartData = {
itentifier: 'id',
items:
[
{id: 1, serviceName:"service1", startDate:"today", endDate:"today", numFailedAttempts:"1", errorTime:"null", errorMessage:"null", suppressError:"null"},
{id: 2, serviceName:"service2", startDate:"today", endDate:"today", numFailedAttempts:"1", errorTime:"now", errorMessage:"broken", suppressError:"click"},
{id: 3, serviceName:"service3", startDate:"today", endDate:"today", numFailedAttempts:"0", errorTime:"now", errorMessage:"broken", suppressError:"click"},
{id: 4, serviceName:"service4", startDate:"today", endDate:"today", numFailedAttempts:"1", errorTime:"now", errorMessage:"broken", suppressError:"click"},
{id: 5, serviceName:"service5", startDate:"today", endDate:"today", numFailedAttempts:"0", errorTime:"null", errorMessage:"null", suppressError:"null"}
]
};
//data store
var dataChartStore = dojo.store.Observable(new dojo.store.Memory({
data: {
identifier: "id",
label: "runningServices",
items: dataChartData
}
}));
var dataChart = new dojox.charting.Chart("myDataChart", {
displayRange: 10,
stretchToFit: false,
scrolling: true,
fieldName: "runningServices",
type: dojox.charting.plot2d.Areas
});
dataChart.addAxis("x", {microTickStep: 1, minorTickStep: 1});
dataChart.addAxis("y", {vertical: true, minorTickStep: 1, natural: true});
dataChart.addSeries("y", new dojox.charting.StoreSeries(dataChartStore, {query: {numFailedAttempts: 0}}, "value"));
dataChart.render();
//update datastore to simulate new data
var startNumber = dataChartData.length;
var interval = setInterval(function(){
dataChartStore.notify({value: Math.ceil(Math.random()*29), id: ++startNumber, numFailedAttempts: 0});
}, 1000);
}
</script>
</head>
<body>
<div id="myDataChart" style="width: 500px; height: 200px;"></div>
</body>