Adam Ellwood
Adam Ellwood

Reputation: 13

Flot axis crosses at

Does anyone know if its possible to set a crosses at value for axis using flot? If you take the example here

http://www.flotcharts.org/flot/examples/threshold/index.html

It would be great to be able to set the x-axis so it crosses the y at 0 and not at the min ( -10 in this example )

I can't find a way to do this. Nor can I find a way using highcharts or jqplot for that matter.

Upvotes: 1

Views: 208

Answers (2)

Mark
Mark

Reputation: 108512

As @DNS mentions, you won't find this in the API, but when all else fails, hack it up!

$(function () {

    var data = [[0, -12], [7, 12], [8, 2.5], [12, 2.5]];  // some data series

    somePlot = $.plot($("#placeholder"), [ data ]); // plot it once

    var xaxis = somePlot.getAxes().xaxis; // get your x and y axis 
    var yaxis = somePlot.getAxes().yaxis;

    var abline = [[xaxis.datamin,0],[xaxis.datamax,0]]; // create a new line to serve as our xaxis, we are using the current xaxis extremes

    somePlot = $.plot($("#placeholder"), [ {data: data}, {color: 'black', data: abline, shadowSize:0} ], {}) // replot it with our new line

    $('.x1Axis .tickLabel').css('top',yaxis.p2c(0)+5+'px'); // move our xaxis tick labels to the zero location of the yaxis   

});

Produces:

enter image description here

Fiddle here.

Upvotes: 1

DNS
DNS

Reputation: 38189

Unfortunately this is not currently possible; Flot only supports axes at the edges of the plot.

You should definitely open an issue to submit this as a suggestion.

Upvotes: 0

Related Questions