我试图在我的flot图表上使用一个不同的符号作为我的一个数据系列,因为它的规模比其他数据大得多。我使用这个例子作为参考:http://www.flotcharts.org/flot/examples/symbols/index.html使用不同的符号绘制数据不起作用
这是我到目前为止有:
我包括:
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.flot.js"></script>
<script type="text/javascript" src="jquery.flot.symbol.js"></script>
我再配置我海军报的选项,如下所示:
var options = {
grid: {hoverable : true},
xaxis: { mode: "time", timeformat: "%H:%M", tickLength: 1},
series: { points : { show: true } }
};
然后我实际上绘制了数据:
$.plot('#placeholder', [{
data: my_data,
lines: { show : true},
points: { symbol: "square"},
color: '#CB4B4B',
label: 'My Data'
}], options);
}
但是,flot
仍将图形作为默认圆圈。我得到的萤火没有错误消息,我甚至都试图在jquery.flot.symbol.js
库本身添加日志消息,看看是否“方”处理程序甚至被称为像这样:
var handlers = {
square: function (ctx, x, y, radius, shadow) {
console.log("Square handler was called");
// pi * r^2 = (2s)^2 => s = r * sqrt(pi)/2
var size = radius * Math.sqrt(Math.PI)/2;
ctx.rect(x - size, y - size, size + size, size + size);
},
我越来越没有控制台消息等等我假设处理程序没有正确调用。我在这里错过了什么吗?
编辑:
var d1 = [
[1364342400000, 208],
[1364346000000, 107],
[1364353200000, 42],
[1364371200000, 1680],
[1364360400000, 52],
[1364349600000, 67],
[1364385600000, 1118],
[1364367600000, 163],
[1364382000000, 1359],
[1364378400000, 1468],
[1364389200000, 1023],
[1364356800000, 63],
[1364374800000, 1601],
[1364392800000, 556],
[1364364000000, 84],
],
d2 = [
[1364342400000, 86],
[1364346000000, 42],
[1364353200000, 13],
[1364371200000, 458],
[1364360400000, 10],
[1364349600000, 22],
[1364385600000, 453],
[1364367600000, 45],
[1364382000000, 369],
[1364378400000, 379],
[1364389200000, 358],
[1364356800000, 17],
[1364374800000, 471],
[1364392800000, 147],
[1364364000000, 16],
],
d3 = [
[1364342400000, 7],
[1364346000000, 5],
[1364382000000, 11709],
[1364371200000, 58336],
[1364360400000, 1],
[1364349600000, 1],
[1364367600000, 2],
[1364389200000, 1191],
[1364378400000, 9085],
[1364385600000, 4688],
[1364374800000, 9386],
[1364392800000, 1140],
[1364364000000, 1],
];
我还编辑我options
参数和绘图功能是如何叫:我想绘制的数据
例
var options = {
grid: {hoverable : true},
xaxis: { mode: "time", timeformat: "%H:%M", tickLength: 1}
};
$.plot("#placeholder", [{
data: d1,
lines: { show : true },
points: { show: true},
color: '#EDC240',
label: "d1"
}, {
data: d2,
lines: { show : true },
points: { show : true},
color: '#AFD8F8',
label: "d2"
}, {
data: d3,
yaxis: 2,
lines: { show : true},
points: { show: true, symbol: "square"},
color: '#CB4B4B',
label: "d3"
}], options);
我也确信symbol
库被包含在内,因为我已经将一些日志本身添加到库a nd显示正常。
感谢您的帮助迄今。我编辑了我的问题以包含更多信息,包括我试图绘制的数据。我感到困惑,为什么它不工作,因为我的代码与上面的代码很相似。 – 2013-03-27 18:50:15
确实....即使有了这些增加的细节,它仍然不清楚是什么问题 - http://jsfiddle.net/ryleyb/shLtU/2/显示所有的更改,它仍然显得很好... – Ryley 2013-03-27 18:53:42
我应该检查我运行的是什么版本的“flot”。我使用的版本是'0.6',只要我升级到0.7,方形符号就可以很好地工作。你的回答让我走上了正轨。感谢您的帮助! – 2013-03-27 19:15:02