jqBarGraph – jQuery graph plugin

jqBarGraph is jQuery plugin that gives you freedom to easily display your data as graphs. There are three types of graphs: simple, multi and stacked. All you have to do is to pass your data to this plugin. This plugin is compatible and fully tested with Safari 2+, Internet Explorer 6+, Firefox 2+, Google Chrome 3+, Opera 9+.

jQuery Bar Graph

Of course, there are a lot of settings to tune appearance of your graph, as are animation, color scheme, dimensions etc. Also, you can additionally change look and feel of graph via CSS.

You will need jQuery in order to make jqBarGraph working. First, you need to download jQuery and jqBarGraph plugin and include them on your page. Similar to this:

<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jqBarGraph.js" type="text/javascript"></script>

Now, we need array of data from which we want to create graph. There is two type of data array for jqBarGraph. First is for simple bar graph type, and second is for multi and stacked bar type.

For simple bar graph type data for one bar should look like this: [value, label, color]. Label and color are optional. This is example for simple bar graph type:

 
arrayOfData = new Array(
    [10.3,'Jan','#f3f3f3'],
    [15.2,'Feb','#f4f4f4'],
    [13.1,'Mar','#cccccc'],
    [16.3,'Apr','#333333'],
    [14.5,'May','#666666']
); 

For multi and stacked type of graph you should send data in next format: [[value1, value2, value3, …, valueN], label]. It should look similar to this:

arrayOfData = new Array(
    [[14,54,26],'2007'],
    [[8,48,38],'2008'],
    [[4,36,57],'2009']
); 

After you set your data array you just need to say in which div you want graph to be created. All you have to do is:

 
$('#divForGraph').jqBarGraph({ data: arrayOfData }); 

The code above is enough to display your data as bar graph. But if you want to made your graph prettier you can achieve that with next set of parameters:

 
data: arrayOfData, // array of data for your graph
title: false, // title of your graph, accept HTML
barSpace: 10, // this is default space between bars in pixels
width: 400, // default width of your graph
height: 200, //default height of your graph
color: '#000000', // if you don't send colors for your data this will be default bars color
colors: false, // array of colors that will be used for your bars and legends
lbl: '', // if there is no label in your array
sort: false, // sort your data before displaying graph, you can sort as 'asc' or 'desc'
position: 'bottom', // position of your bars, can be 'bottom' or 'top'. 'top' doesn't work for multi type
prefix: '', // text that will be shown before every label
postfix: '', // text that will be shown after every label
animate: true, // if you don't need animated appearance change to false
speed: 2, // speed of animation in seconds
legendWidth: 100, // width of your legend box
legend: false, // if you want legend change to true
legends: false, // array for legend. for simple graph type legend will be extracted from labels if you don't set this
type: false, // for multi array data default graph type is stacked, you can change to 'multi' for multi bar type
showValues: true, // you can use this for multi and stacked type and it will show values of every bar part 
showValuesColor: '#fff' // color of font for values

This graph will work without any additional CSS, but it can easily be styled via CSS. I was paying attention that you will have enough selectors to achieve anything you want with CSS. If you create something cool it will be nice if you share that with all of us.

Changelog

1.1

* Compatibility with jQuery 1.4.2+

  • Image gallery with fancy transitions effects (1034)
    I was looking all over the Internet for some jQuery gallery plugin with some interesting transition effects. I found a lot of great plugins but they all have pretty same transition […]
  • Just Random Color (0)
    Some time ago I was working on app where for each category we had to assign random color in case that user didn't choose one. A few day ago I needed to generate random color again. Instead […]
  • Fancy Transitions Featured Gallery for WordPress (62)
    ftFeatured is Wordpress plugin for creating image gallery with fancy transition effects of featured posts. You can choose between three types of transition effects: curtain, wave and […]
  • Coin Slider 4 WordPress (237)
    Coin Slider 4 WP will show your featured posts as image slider and rotate them using unique effects provided by jQuery's Coin Slider. Implementation is very easy, after you download […]
  • Bigshark – larger buttons on Grooveshark (0)
    GrooveShark is one of the web services which I’m using on daily basis. Actually, I have one computer which I use only to play music from my GrooveShark playlists, while I’m sitting on […]

157 comments on "jqBarGraph – jQuery graph plugin"

@Dario Villanueva
Height will define maximum value, maybe you can use that.

@Roly
I didn’t have a chance to test it on iPhone, I’m glad that works fine.

Thanks for comments, I really appreciate it.

Lazarevic Ivan on June 13, 2010 at 8:52 am

Now this is a JS charting tool that can take on the Flash equivalents. Well done!! This is the only solution we have found that contains animation similar to FusionCharts. Do you have plans to develop other charts eg line chart?

We have looked at so many JS solutions of charts that work on the iPhone/Safari browser but none of them work as good as this. Graphael come very close (and that very impressive) but it’s not animated and let’s face it, that’s what users want to see.

Cheers,
Roly.

Roly on June 9, 2010 at 8:37 pm

Fantastic plugin, It’s really clean and beautifully animated. It’d be great however if you could add an option to define the scale, i.e. the maximum value. I’m making a page with a lot of independent graphs that scale automatically according to their own dataset, but i’d want them to all scale the same so they could be comparable. Other than that, fantastic plugin A++++

Cheers!

Dario Villanueva on June 4, 2010 at 3:30 am

Great plug-in, thanks!

Question is there a way to make it a horizontal graph?

Thanks again!

erica on May 11, 2010 at 1:12 pm

You can add grids as background image. I know that it’s not a perfect solution : )

Lazarevic Ivan on April 13, 2010 at 2:08 pm

Hi, Nice work there.
But one thing , what about X and Y grid view?

M A Hossain Tonu on April 12, 2010 at 4:27 am

Philip, there is no option for that, but you can change source code if you know how to achieve that. If you need help feel free to contact me.

Lazarevic Ivan on April 11, 2010 at 4:13 am

Is it possible to reverse the order of the legend so that the legend match the sequence of the stacked graph?

Philip on April 8, 2010 at 12:55 pm

Stvarno dobar plugin. Svaka cast..
Naisao sam na jedan problem: Kada jednom iskoristim hide() na elementu kome grafik pripada,grafik se vise ne prikazuje, naravno isto je i iz css-a display:none

Primer:

Dakle, kada sakrijem prvi_blok a kasnije zelim da ga prikazem, grafik se jednostavno izgubi.
Kod prikaza sam koristio jednostavno show() ili toggle()

U cemu je problem? Mozda negde gresim

Predic on March 15, 2010 at 5:11 am

Pravin, after Ajax response on success just create graph again with data from response.

Lazarevic Ivan on March 4, 2010 at 1:13 pm

Thanks for developing such a good plugins.
I need help regarding the arrayOfData. In our example we have to generate arrayOfData using jsp file. So how can I get the arrayOfData as a Ajax response.

Please help me out.

Pravin on March 3, 2010 at 9:22 am

Odličan plugin. Jednostavan za koristenje, super izgleda…

Ozren on February 17, 2010 at 6:12 am

That’s a good question tplaner. For now, you should clear graph container div before drawing new graph. Something similar is done on jqBarGraph’s page examples part. This is code snippet from there.

$(‘#multiSortDesc’).click(function(){
$(‘#exampleMulti’).html(”);
$(‘#exampleMulti’).jqbargraph({ data: arrayOfDataMultiForSort });

});

Thanks for feedback. I’ll fix this in next release.

Lazarevic Ivan on December 18, 2009 at 2:01 pm

Excellent plug-in well designed and coded for displaying basic bar charts. I really like how browser compatible these bar charts are since they do not rely on the canvas element.

One question though, I was wondering how you would go about updating the charts in semi-real-time? For example if you had animation set to false, how would you then simply add to the data set on the screen?

I attempted to simply modify the data and pass it back to the jqBarGraph function, however it doesn’t seem to be working correctly (I end up with overlapping text).

tplaner on December 18, 2009 at 9:31 am

Leave a Reply

Your email address will not be published. Required fields are marked *