Javascript 如何使用flot仅绘制点(而不是线)?
最终,我想要的是一个非常小的一维图表,如下所示: 轴Javascript 如何使用flot仅绘制点(而不是线)?,javascript,jquery,charts,plot,flot,Javascript,Jquery,Charts,Plot,Flot,最终,我想要的是一个非常小的一维图表,如下所示: 轴 X轴:0到100,不可见 Y轴:0到0(但绘制三条线可能需要-1到1) 数据 仅限积分。没有台词 两个数据集的颜色需要不同(首选红色和绿色) x轴上的所有数据(y=0) 如果形状是可能的,X和O将是完美的 平面 我需要在x轴上的特定点绘制三条线,而不是标准网格。 例如: 以下是我到目前为止所做的尝试: d1 = [[48,0],[16,0],[10,0],[40,0],[30,0],[37,0]]; d2 = [[43,0],
- X轴:0到100,不可见
- Y轴:0到0(但绘制三条线可能需要-1到1)
- 仅限积分。没有台词
- 两个数据集的颜色需要不同(首选红色和绿色)李>
- x轴上的所有数据(y=0)
- 如果形状是可能的,X和O将是完美的
- 我需要在x轴上的特定点绘制三条线,而不是标准网格。
例如:
d1 = [[48,0],[16,0],[10,0],[40,0],[30,0],[37,0]];
d2 = [[43,0],[60,0],[74,0],[83,0]];
var options = {
points: { show: true, fill: true, radius: 5 },
lines: { show: false, fill: true },
xaxis: { show: false, min:0, max:100, ticks: false, tickColor: 'transparent' },
yaxis: { show: false, min:-1, max:1, ticks: false, tickColor: 'transparent' },
grid: { show:false }
};
var data = [
{ data: d1, points: { color: '#E07571', fillcolor: '#E07571' } },
{ data: d2, points: { color: '#FDEDB2', fillcolor: '#FDEDB2' } }
];
$.plot($('#placeholder'), data, options);
问题:
- 颜色不起作用
- 不知道如何画平面
要绘制更复杂的点符号,请查看。它允许您定义自定义回调来绘制自己的符号。下面是一个快速复制图片的模型:
d1 = [[48,0],[16,0],[10,0],[40,0],[30,0],[37,0]];
d2 = [[43,0],[60,0],[74,0],[83,0]];
var options = {
points: { show: true, radius: 10, lineWidth: 4, fill: false },
lines: { show: false },
xaxis: { show: false },
yaxis: { show: false },
grid: { show:true,
color: "transparent",
markings: [
{ xaxis: { from: 40, to: 40 }, color:"black" },
{ xaxis: { from: 50, to: 50 }, color:"black" },
{ xaxis: { from: 60, to: 60 }, color:"black" }
]
}
};
xCallBack = function (ctx, x, y, radius, shadow) {
ctx.arc(x, y, radius, 0, Math.PI * 2, false);
var text = 'X'
var metrics = ctx.measureText(text);
ctx.font="15px Arial";
ctx.fillStyle = "red";
ctx.fillText(text,x-metrics.width/2,y+4);
}
checkCallBack = function (ctx, x, y, radius, shadow) {
ctx.arc(x, y, radius, 0, Math.PI * 2, false);
var text = '✓'
var metrics = ctx.measureText(text);
ctx.font="15px Arial";
ctx.fillStyle = "green";
ctx.fillText(text,x-metrics.width/2,y+4);
}
var data = [
{ data: d1, color: 'red', points: {symbol: xCallBack } },
{ data: d2, color: 'green', points: {symbol: checkCallBack }}
];
$.plot($('#placeholder'), data, options);
小提琴
哇,这太棒了。谢谢
grid: {
show: true,
color: "transparent",
markings: [
{ xaxis: { from: 20, to: 20 }, color: "#888", lineWidth: 5 }
]
}
d1 = [[48,0],[16,0],[10,0],[40,0],[30,0],[37,0]];
d2 = [[43,0],[60,0],[74,0],[83,0]];
var options = {
points: { show: true, radius: 10, lineWidth: 4, fill: false },
lines: { show: false },
xaxis: { show: false },
yaxis: { show: false },
grid: { show:true,
color: "transparent",
markings: [
{ xaxis: { from: 40, to: 40 }, color:"black" },
{ xaxis: { from: 50, to: 50 }, color:"black" },
{ xaxis: { from: 60, to: 60 }, color:"black" }
]
}
};
xCallBack = function (ctx, x, y, radius, shadow) {
ctx.arc(x, y, radius, 0, Math.PI * 2, false);
var text = 'X'
var metrics = ctx.measureText(text);
ctx.font="15px Arial";
ctx.fillStyle = "red";
ctx.fillText(text,x-metrics.width/2,y+4);
}
checkCallBack = function (ctx, x, y, radius, shadow) {
ctx.arc(x, y, radius, 0, Math.PI * 2, false);
var text = '✓'
var metrics = ctx.measureText(text);
ctx.font="15px Arial";
ctx.fillStyle = "green";
ctx.fillText(text,x-metrics.width/2,y+4);
}
var data = [
{ data: d1, color: 'red', points: {symbol: xCallBack } },
{ data: d2, color: 'green', points: {symbol: checkCallBack }}
];
$.plot($('#placeholder'), data, options);