Reputation: 3343
I have a simple line chart that contains 2 series, with the x-axis being a date and the y-axis an integer. The code that illustrates this is as follows:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" language="javascript" src="flot/jquery.js"></script>
<script type="text/javascript" language="javascript" src="flot/jquery.flot.js"></script>
<style type="text/css">
#overview-plot24 {
width: 94%;
margin-left: 20px;
height: 220px;
}
</style>
<script type="text/javascript">
$(function() {
var plotOptions = {
//Options go here
xaxis: {
mode: "time",
tickLength: 5,
reserveSpace: true,
autoscaleMargin: 0.01
},
yaxis: {
min: 0
},
legend: {
show: false
},
series: {
lineWidth: 1,
shadowSize: 0
},
grid: {
hoverable: true,
clickable: true
}
};
var plot2 = $.plot(
'#overview-plot24', [
{
label: "Alerts",
color: "#FC8200",
data: [
[Date.parse("2013-03-19 15:00"), 9650],
[Date.parse("2013-03-19 16:00"), 33124],
[Date.parse("2013-03-19 17:00"), 27806],
[Date.parse("2013-03-19 18:00"), 24143],
[Date.parse("2013-03-19 19:00"), 7573],
]},
{
label: "Scores",
color: "#8000FF",
data: [
[Date.parse("2013-03-19 15:00"), 26407],
[Date.parse("2013-03-19 16:00"), 93973],
[Date.parse("2013-03-19 17:00"), 77760],
[Date.parse("2013-03-19 18:00"), 68715],
[Date.parse("2013-03-19 19:00"), 20383],
]
}
],
plotOptions
);
});
</script>
</head>
<body>
<div id="overview-plot24"></div>
</body>
</html>
This is correctly rendered in Chrome and Opera, but the series fails to be rendered on Safari and Firefox. Chrome renders is correctly. Safari and Firefox renders it incorrectly.
This is perplexing as the examples on the flot web page render correctly on all browsers and I'm struggling to see where my code differs!
For those interested in running the code directly, zip archive containing all you need is available.
Upvotes: 3
Views: 2553
Reputation: 38183
I had this same issue and, although I fixed the date format it didn't solve the problem. The issue turned out to be a bug in Flot where it will not graph the data if you specify min
and max
options for time values on the x-axis.
Once I removed the min
and max
it worked like a charm in all browsers.
Upvotes: 1
Reputation: 20254
Could this be a problem with the Date.parse function not working as you expect on Safari and Firefox? I think the date formats that are recognised are implementation dependent, and may not be consistent across different browsers.
See this question for more details
Upvotes: 3
Reputation: 67080
The problem is not in Flot or its rendering but in the JavaScript, specifically in the format you use for date.
Format you're using for date is not valid (see horizontal axis in the rendered chart) because that format 2013-03-19 19:00
is recognized by IE and Chrome but not FF and Safari.
The only format you're sure every browser will read is YYYY-MM-DDTHH:mm:ss.sssZ
so in your case you should change string in your code to 2013-03-19T19:00
. Take a look to this and this posts on SO for other details (or this little tutorial about dates).
Upvotes: 5