Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I plot only points (not lines) with flot?

Ultimately I'm after a very minimal 1 dimensional chart like this:

Simple Line Plot

Axes

  • X-axis: 0 to 100, and invisible
  • Y-axis: 0 to 0 (but -1 to 1 may be necessary to draw a three lines)

Data

  • Points only. No lines.
  • Two data sets need to be colored differently (red and green preferred).
  • All data on x-axis (y=0)
  • If shapes are possible, X's and O's would be perfect

Planes

  • Instead of a standard grid, I need three lines drawn at specific points on the x-axis.
    Example:

    [[40,-1],[40,1]],
    [[50,-1],[50,1]],
    [[60,-1],[60,1]]
    

Here's what I've tried so far:

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

Problems:

  • colors don't work
  • can't figure out how to draw planes
like image 400
Ryan Avatar asked Oct 24 '13 04:10

Ryan


People also ask

How do I Turn Off lines in Flot?

The most important options are “lines”, “points” and “bars” that specify whether and how lines, points and bars should be shown for each data series. In case you don’t specify anything at all, Flot will default to showing lines (you can turn this off with lines: { show: false }).

How does Flot choose the closest item to an item?

If there are two or more points within this radius, Flot chooses the closest item. For bars, the top-most bar (from the latest specified data series) is chosen. If you want to disable interactivity for a specific data series, you can set “hoverable” and “clickable” to false in the options for that series, like this:

How do I use time series data in Flot?

Use “time” for time series data; see the time series data section. The time plugin (jquery.flot.time.js) is required for time series support. The “color” option determines the color of the line and ticks for the axis, and defaults to the grid color with transparency.

What is the use of marking in plotter?

“markings” is used to draw simple lines and rectangular areas in the background of the plot.


1 Answers

Here's a quick mock-up replicating your picture:

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

Fiddle here.

enter image description here

like image 187
Mark Avatar answered Nov 15 '22 03:11

Mark