剛開始時第一次使用flot.js並且有一些問題/問題。圖表顯示罰款減去一些困擾我的事情。flot.js - 點與x軸,空數據集,圖例重疊不匹配
1 - 蜱和日期似乎沒有正確排列。例如,在目前的圖表中,我正在研究兩天內只有兩個條目。由於某種原因,實際數據值(點)不會超過其對應的日期。在這裏看到圖像
2 - 是否有任何方法使y軸大於數據集以防止線條與圖例重疊?在這個例子中,它很好,但我看到其他數據與圖例重疊的地方。
3 - 如何處理沒有數據?我打算在此擴展以允許用戶選擇開始/結束日期...因此,如果沒有結果,是否有一個很好的方式來返回此信息和/或可能在圖表中顯示一條消息?這裏最主要的是當沒有數據時腳本不會中斷。
JS:
//get the data
$.ajax({
url: "/process/chart_main.php",
type: "POST",
dataType: "json",
success: onDataReceived
});
function onDataReceived(series) {
console.log(series);
// Load all the data in one pass; if we only got partial
// data we could merge it with what we already have.
data = series;
var options = {
series: {
lines: {
show: true,
lineWidth: 2,
fill: true,
fillColor: {
colors: [{
opacity: 0.05
}, {
opacity: 0.01
}
]
}
},
points: {
show: true
},
shadowSize: 2
},
grid: {
hoverable: true,
clickable: true,
tickColor: "#eee",
borderWidth: 0
},
//colors: ["#d12610", "#37b7f3", "#52e136"],
xaxis: {
tickSize: [1, "day"],
mode: "time",
timeformat: "%m-%d-%Y"
},
yaxes: [{
position: "left"
}],
legend: {
position: "ne"
}
};
$.plot("#flot_chart", data, options);
}
PHP:
//actual select removed for this display
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if($results)
{
foreach($results as $row)
{
$data1[] = array(strtotime($row['date']) * 1000, $row['day_count']);
}
//send our data values to $mergedData, add in your custom label and color
$mergedData[] = array('label' => "Events" , 'data' => $data1, 'color' => '#37b7f3');
}
// return result array to ajax
echo json_encode($mergedData);