jquery flot, varying size and color for each point

2019-04-07 02:20发布

问题:

Can we change the following properties of the points in a jquery flot plot:

the size of dots : I am basically trying to plot a three dimensional graph. First two dimensions are the x and y values and the third dimension value will be reflected in the size of the points. Larger the value, larger the point.

the color of the dots: Again, am trying to display a property other than the x and y values. larger the value, darker the point.

[EDIT]: I am trying to control these properties for points individually and not for the whole plot.

回答1:

I understand you now. The only way I can see doing this is by passing a callback function to the point symbol option:

function someFunc(ctx, x, y, radius, shadow) 
{
  someFunc.calls++;
   if (someFunc.calls % 2 == 0)
   {
    ctx.arc(x, y, radius * 4, 0, shadow ? Math.PI : Math.PI * 2, false);
   }
   else
   {
     ctx.arc(x, y, radius, 0, shadow ? Math.PI : Math.PI * 2, false);
   }
}
someFunc.calls = 0;

var options = {
  series: {
    lines: { show: true },
    points: { show: true, symbol: someFunc}
  }
};

somePlot = $.plot($("#placeholder"), [ d1 ], options);

In the above I am adjusting the radius size for every other point:

EXAMPLE HERE



标签: jquery flot