Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用flot仅绘制点(而不是线)?_Javascript_Jquery_Charts_Plot_Flot - Fatal编程技术网

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);
问题:

  • 颜色不起作用
  • 不知道如何画平面

事实上你已经很接近了

颜色不起作用,因为颜色是series的属性,而不是series.points。您只需要将其与数据一起提升一个级别。fillColor选项不起作用,因为“c”需要大写

对于垂直线,使用标记,如下所述:


要绘制更复杂的点符号,请查看。它允许您定义自定义回调来绘制自己的符号。

下面是一个快速复制图片的模型:

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);