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+.
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+
@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.
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.
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!
Great plug-in, thanks!
Question is there a way to make it a horizontal graph?
Thanks again!
You can add grids as background image. I know that it’s not a perfect solution : )
Hi, Nice work there.
But one thing , what about X and Y grid view?
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.
Is it possible to reverse the order of the legend so that the legend match the sequence of the stacked graph?
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
Pravin, after Ajax response on success just create graph again with data from response.
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.
Odličan plugin. Jednostavan za koristenje, super izgleda…
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.
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).