Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I construct a jquery/flot bar chart, without the vertical axis lines?

Tags:

jquery

flot

I am exploring flot, the jquery graphing library.

I'd like to be able to create a bar chart. Seems like it was not really set up for this. If I contort my data a little, I can get it to mostly do what I envision. Using this code:

  var dataSet = [
    [ 15132, "Inez" ],
    [ 21441, "Rocky" ],
    [ 29141, "Jim" ],
    [ 18211, "Sophia" ],
    [ 17556, "Perry" ],
    [ 32251, "Jorge" ],
    [ 43560, "Madison" ],
    [ 20180, "Gil" ],
    [ 12180, "Fran" ],
    [ 31018, "Sheila" ],
    [ 45143, "Nial" ],
  ];


  function plotChart() {
    var d1, xaxisLabels = [], i=0;

    d1 = dataSet.map(function(elt){return {label: elt[1], data: [[i++, elt[0]]]};});
    i = 0;
    // example for xaxis option: {ticks: [[1,'One'], [2,'Two'], [3,'Three'], [4,'Four'], [5,'Five']]},
    xaxisLabels = dataSet.map(function(elt) { return [i++, elt[1]]; });
    $.plot($("#chart1"),
           d1,
           {
             legend: {
               show: true,
               container: $('#legend1'),
             },
             series: {
                   bars: {
                     show       : true,
                     align      : 'center',
                     //dataLabels : true,
                     barWidth : 0.4
                   }
             },
             xaxis: { ticks: xaxisLabels },
             yaxis: {
                   ticks: 10
             },
             grid: {
                   show: true,
                   backgroundColor: { colors: ["#fff", "#eee"] }
             }
           });
}

$(document).ready(plotChart);

This is what I get:

enter image description here

That's pretty good. But I'd like to remove the vertical axis lines. These might make sense in a line chart, but not in a bar chart.

Anyone know how I can do that?

like image 703
Cheeso Avatar asked Aug 27 '11 19:08

Cheeso


1 Answers

All you need is

xaxis: { tickLength: 0 }
like image 113
Daniel J F Avatar answered Sep 29 '22 12:09

Daniel J F