flotr2 不会仅呈现条形图的时间戳
flotr2 will not render with timestamp for bar charts only
我正在使用Flotr2使用DateTime渲染一些图形。这已经很好地处理了折线图,但现在我需要在购物车上呈现折线图和条形图。这应该很容易,在flotr2网站上有一个示例。
当我使用int
值时,一切都会按预期工作。当我将其更改为 DateTime
时,它失败了,因为折线图按需要显示,但条形图根本不显示。
我的Javascript在下面(带有注释掉的DateTime值(
function CreateRequiredChart(container)
{
var bars = {
data: [],
bars: {
show: true,
barWidth: 0.03,
lineWidth: 0,
fillColor: {
colors: ['#f00', '#f66'],
start: 'top',
end: 'bottom'
},
fillOpacity: 1
}
},
lines = {
data: [],
lines: {
show: true,
fillColor: ['#900', '#EDC13E', '#4DD43B'],
fill: true,
fillOpacity: 1
}
};
//The next lines displays the result which is desired (in that both line and bar graphs are shown). Comment these out and uncomment the next section to see the fault
bars.data.push([1, 7]);
lines.data.push([0, 4], [1, 9], [2, 5], [3, 3]);
/*The next 2 lines do not display as desired. The line graph works, the bar graph does not
bars.data.push([new Date('01/01/2013 08:30:00'), 7]);
lines.data.push([new Date('01/01/2013 08:29:00'), 5], [new Date('01/01/2013 08:30:00'), 8], [new Date('01/01/2013 08:31:00'), 4]);
*/
graph = Flotr.draw(container, [lines, bars], {
HtmlText: false,
yaxis: {
showLabels: true,
title: "Value"
},
xaxis: {
mode: "time",
timeformat: "%H%M%S",
minorTickFreq: 1,
showLabels: true,
title: "Time from start of logging",
labelsAngle: 90
},
grid: {
verticalLines: true,
backgroundColor: ['#fff', '#ccc']
}
});
}
我做错了什么,还是这是flotr2的限制?
这实际上在一定程度上是按预期工作的。这里有 2 个故障。
1 是无法让 flotr2 使用日期时间,所以我黑了一点。我使用getTime将所有内容转换为int
(long
(。Flotr2似乎喜欢这样,如果他们被安抚,那么一切都很好。
var dt = new Date('01/01/2013 08:29:00');
var dt2 = new Date('01/01/2013 08:30:00');
var dt3 = new Date('01/01/2013 08:31:00');
var x = dt.getTime();
var y = dt2.getTime();
var z = dt3.getTime();
bars.data.push([y, 8]);
lines.data.push([x, 5], [y, 7], [z, 3]);
另一个问题是时间段对于条形图来说太多了......因此,条形图正在"显示",但在如此小的范围内,肉眼看不见。更改为
barWidth: 2000
完整代码
function CreateRequiredChart(container, title, dataForGraph, errorPoints)
{
var bars = {
data: [],
bars: {
show: true,
order:1,
//barWidth: 1000000,
barWidth: 2000,
lineWidth: 0,
fillColor: {
colors: ['#f00', '#f66'],
start: 'top',
end: 'bottom'
},
fillOpacity: 1
}
},
lines = {
data: [],
lines: {
show: true,
fillColor: ['#900', '#EDC13E', '#4DD43B'],
fill: true,
fillOpacity: 1
}
};
var dt = new Date('01/01/2013 08:29:00');
var dt2 = new Date('01/01/2013 08:30:00');
var dt3 = new Date('01/01/2013 08:31:00');
var x = dt.getTime();
var y = dt2.getTime();
var z = dt3.getTime();
bars.data.push([y, 8]);
lines.data.push([x, 5], [y, 7], [z, 3]);
// Please note, you can't have 'HtmlText: true' and rotate the text! It is one or the other, hence why 'HtmlText: false'.
Flotr.draw(
container, [lines, bars], {
HtmlText: false,
yaxis: {
showLabels: true,
title: "Value"
},
xaxis: {
mode: "time",
showLabels: true,
title: "Time from start of logging",
labelsAngle: 90
},
grid: {
verticalLines: true,
backgroundColor: ['#fff', '#ccc']
},
series:{bars:{show:true}}
});
}
相关文章:
- 用chart.js绘制条形图
- 如何每10.6秒从时间戳增加+1
- d3.js用按钮更新条形图工具提示
- 在谷歌图表折线图的x轴上显示日期,而不是时间戳
- 折线图:对齐多个数据集的x轴(时间戳)
- 如何在html5中根据时间在画布上绘制条形图
- 将时间戳放在 Flotr2 折线图中的 x 轴上
- X 轴时间戳图 JS
- flotr2 不会仅呈现条形图的时间戳
- 为什么 D3 折线图和条形图显示在同一时间
- C3.js 中的时间序列图无法访问时间戳
- 使用d3更新具有x轴时间线的图表上的各种长度的条形图数据
- 动态条形图滚动与时间使用javascript
- 以json对象的形式传递时间戳值以填充流线图
- 在带有时间序列的流线图中堆叠条形图
- 为负值的条形图添加时间轴
- 在时间轴上的条形图与plottable.js -条形位置
- 如何使yAxis从一个特定的时间开始,条形图中的序列
- 将时间戳格式添加到折线图x轴
- 谷歌堆叠条形图,日期在x上,时间在y上