gvChart plugin – jQuery with Google Charts
gvChart is a plugin for jQuery, that uses Google Charts to create interactive visualization by using data from the HTML table tag. It is easy in use and additionally it allows you to create five types of the charts.
Check out demo Download plugin from github
Important: Download link and Demo are up to date (version 1.0.1).
Some time ago I tried to find some JavaScript libraries, which would easily create nice charts. I have found two: jQuery Visualise and Google Charts. First one was interesting because of using table HTML tag as a data source for the chart, but it isn’t interactive and there are no labels with values of every chart node. Google Charts provide useful tools for creating interactive charts, but it uses JavaScript Array() as a source of data. So I decided to create my own hybrid of these features.
Creating chart in three steps
Create HTML table
Create table with your data. The table must be well formed:
- Table should have caption element – it will be used as a title of the chart.
- Table should be divided into two parts: thead and tbody.
- In the thead element create one row with th elements. They will be used as arguments presented on the x-axis.
- In the tbody element place data rows. Each row represents one data set. The first element of the row should be th with the name of the data set.
Download gvChart
Download gvChart and place it in your HTML code.
To use this plugin you have to put script tags reffering to jQuery, gvChart and Google jsapi.
<script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript" src="jquery.gvChart-0.1.min.js"></script>
Important! Google jsapi script tag must be placed before gvChart script.
Before using script you have to initialize Google Api, by using gvChartInit() function. This function may not work when placed in the external JavaScript file. It is better idea to place it inline in the head.
<script type="text/javascript"> gvChartInit(); </script>
Connect gvChart to the table
Now you can use gvChart in your scripts. Below is a basic example of usage.
jQuery('#myTable').gvChart({
chartType: 'ColumnChart',
gvSettings: {
vAxis: {title: 'No of players'},
hAxis: {title: 'Month'},
width: 720,
height: 300,
}
});
gvChart settings
chartType – You can use five different google charts, by setting chartType to one of:
hideTable [Default: true] – If set to false, it won’t hide table while creating the chart.
gvSettings – In the gvSettings variable you can place Google Charts settings, which you can find in the Google Visualization API Gallery.
swap [Default: false] – swaps table columns and rows.
Special thanks to Urszula Ciaputa, for helping me with this plugin.
UPDATE: 18/06/2012! Plugin is now placed on the github.
This entry was posted by Janusz Kamieński on 22 June 2010 at 21:00, and is filed under English, JavaScript, Webdesign, xHTML. Follow any responses to this post through RSS 2.0.You can leave a response or trackback from your own site.
-
#3 written by Bernardo 2 years ago
Hi,
I tryied to use the plugin.. I suggest you replace the references to ‘$’ in the source code by ‘jQuery’.. I had to do it here, in order for the plugin to work.. (I use ‘$j’ in mu environment).
Now, a doubt: is it possible to set a transparent background? I tryed to set using the references mentioned here: http://code.google.com/intl/pl-PL/apis/chart/docs/chart_params.html#rgb
without success. I received the message
‘#FFFFFFFF is not a valid color string’
whereas the last FF was meant to be interpreted as 100% transparent.Congratulations for the plugin!
Regards,
Bernardo -
#7 written by Janusz Kamieński 2 years ago
-
#14 written by Pedo 2 years ago
Hi James
I think your problem is in the demo code rather than the plugin and is similar to the fix mentioned above i.e. remove trailing commas such as below
jQuery(‘#myTable1′).gvChart({
chartType: ‘AreaChart’,
gvSettings: {
vAxis: {title: ‘No of players’},
hAxis: {title: ‘Month’},
width: 720,
height: 300, REMOVE TRAILING COMMA HERE
}
});There are a few similar to the above the demo code just elimiate all the commas immediately preceding a }.
Works for me in IE7 once I do the above (no need to touch plugin code itself).
Looks like a nice plugin a very much in keeping with the unobtrusive javasript paradigm!
-
#15 written by Janusz Kamieński 2 years ago
Hi Pedo,
I have uploaded v. 1.0.1 with the fix you have mentioned (removed trailing comma from end of the options). Now it works fine in IE7.
_________________________________________
@Tyok,
I think I am going to add this functionality in the next minor release. Sadly, for now have not much time to make it. -
#16 written by Geetha 2 years ago
-
I had a problem where I had two graphs loading on a page, followed by two loading from an Ajax page. The two from the Ajax page would overwrite the first two as they would have the same name (e.g ‘gvChartDiv1′. To fix this, I modified the chartDivID to add a random number from 1 to 100 to the end of the div ID for each of them, making them unique!
chartDivID: ‘gvChartDiv’ + (Math.random()*101),
A quick and dirty hack, but it works nicely.
-
#22 written by Behnam Divsalar 2 years ago
Hi,
Thanks for the plugin.would that be possible to displatythe vAxis title vertically. I have a ColumnChart type with a lot of column bars. Because the title of each bar could be long, I like to display it vertically rather than default which is horizontally.
I also like to know if it’s possible to have a horizontal line across all column bars. Imagine a maximum number of people as a horizontal line across all column bars representing the number of people.
Regards
Behnam Divsalar
-
#24 written by Janusz Kamieński 1 year ago
By “init” you mean the init function you need to place in the header of the page? Have you tried placing this init in the header and just running the gvchart() function on the lighbox loading? You can also try loading the chart once the page is loaded, not on showing the lightbox. I haven’t tried using it that way.
btw. isn’t lightbox from prototype.js or is it jQuery lightbox?
-
#25 written by Leandro 1 year ago
Thanks for the answer.
I’ve tried all the possibilities you mention and in all of them happens the same.
The lightbox is a jQuery lightbox, colorbox.
I searched in Google Charts forum for this issue and found that one user had the same problem with another lightbox, Shadowbox. But in that case he found a solution that works fine. So i changed to that lightbox and it works too.
Problem “solved”…
-
#28 written by Andrzej 1 year ago
witaj, jak wygląda kwestia kodowania znaków narodowych dla vAxis i yAxis? z klawiatury (generalnie UTF-8) nie przyjmuje (kwadraty), kodów html też nie (nie interpretuje, wyświetla as is). Nie zawsze elegancko jest zostawić anglojezyczne napisy. I dzięki za wspaniały plugin, zamiast walczyć z wyświetleniem bezpośrednio z bazy zastosowałem plugin jako przejścówkę i wspaniale działa. pzdr
-
#29 written by Janusz Kamieński 1 year ago
Szczerze mówiąc trudno mi powiedzieć. Plugin, jak sam napisałeś, jest tylko przejściówką i to co wrzuca się do ustawień jest przekazywane do nich bezpośrednio. Próbnie w moim demo zrobiłem na jednej osi “ąłżćżłńśą” i wyglądają dobrze, tj. są polskie litery. Co do formatowania, to już nie wiem, jak sobie z tym radzi Google Charts API (po prostu są tam przekazywane). Próbowałeś może sprawdzić najpierw te polskie litery na demo dołączonym do paczki? Moje pliki są pisane w UTF-8.
-
#30 written by Andrzej 1 year ago
Januszu, mam już rozwiązanie problemu ale w swoim kodzie to już raczej ty musisz pogrzebać. Zamiast cytować kod podam link do mojego zapytania na Starckoverflow -> http://stackoverflow.com/questions/8173407/google-chart-tool-change-language-for-xaxis/8174471#8174471. Bardzo bym cię prosił na info na emaila jak wprowadzisz już poprawki żebym mógł sciągnąć. I jeszcze raz dzięki za twoją pracę i ukłony dla p.Urszuli – plugin jest bardzo poręczny i wspaniale ułatwia obejście problemów z translacją danych z MySQL do GCT.
-
#32 written by Andrzej 1 year ago
PS2 – hmmm, jeśli tak zrobiłeś to może miałeś zdefiniowany język dla części htmlo’wej i dlatego miałeś ok? Ja mam to w pliku php podpinanym via iframe do pliku php gdzie jest deklaracja językowa (z CMS-a). No ale i tak, gdybyś wprowadził poprawki do kodu to nie byłby to ‘przypadek szczególny’ że działa ok. pzdr
-
#34 written by Andrzej 1 year ago
w powyższym poście wycieło mi ‘style’ i ‘script’. Ok, jest jeszcze jeden problem. W zwykłym GCT – przy wykresie kołowym – dla wartości ujemnych pozostawiane jest wolne miejsce ale wykres jest oczywiście generowany. U ciebie wykres nie jest generowany, wyświetla się komunikat: Negative values are invalid for a pie chart. Teoretycznie wygląda jakby to sam GCT odmówił generacji a nie plugin ale na stronie code.google.com wyraźnie jest napisane że wykres powinien zostać wygenerowany. Jak mógłbyś przyjrzeć się i temu problemowi, pzdr.
-
#35 written by Andrzej 1 year ago
kopię, szukam – jak na razie sprzeczne informacje. Na czystym źródłowym kodzie też wychodzi błąd, w manualu stoi jak byk u wrót – wartości ujemne powodują wyświetlenie pustych części wykresu i nawet wykres mają wygenerowany (niestety, sam obrazek bo bym zaraz do kodu zajrzał …) Zadałem pytanie na grupie, zobaczymy co odpowiedzą. Sorry jeśli mieszam ale staram się uporządkować temat tak żebym był pewny pracy kodu i nie musiał już do tego wracać. A przy okazji, jak dodac 3 wymiar do twojego pie? też oczywiście trafiłem na sprzeczne komendy i na dodatek nie wiem jak poprawnie je zaimplementowac. pzdr
-
#39 written by Marvin 1 year ago
I experimented with selecting based on class:
gvChartInit();
jQuery(document).ready(function(){
jQuery('.pie').gvChart({
chartType: 'AreaChart',
gvSettings: {
vAxis: {title: 'No of players'},
hAxis: {title: 'Month'},
width: 720,
height: 300
}
});});
When I have 2 tables in this class ‘pie’, it only shows one.
Performing a jQuery(‘.pie’).hide() hides both tables.Why can’t I use the class as a selector to plot all charts in the html?
-
#40 written by Sidney 11 months ago
-
#41 written by Sidney 11 months ago
-
#44 written by Glenn Wilton 11 months ago
-
#45 written by Janusz Kamieński 11 months ago
Hi again,
Sorry for long absence, but I have had no time for looking into the plugin. Now there’s an update:
- I moved plugin to github – linked in the post
- I have added “swap” option proposed by Glenn Wilton
- current version is 1.1Once I get more time, I will look into the UTF-8 and special chars issue. You can also propose your own modification via github now.
Thanks!
-
Hi, I can’t align my charts
How do you do that? for example if I want to visualize two charts
on the same line of my page.Only I can see one on the same line of my web page and the next one it vizualize on the bottom I try to give a style float left to the table which contains the chart but not works
-
- Tweets that mention gvChart plugin – jQuery with Google Charts | Janusz Kamieński — Topsy.com
- Interactive Charts With HTML Table and Google Charts API | Greepit
- Anis Berejeb » Générer Facilement des graphes depuis vos tables HTML avec gvGraph
- gvChart: Gráficos con Google Charts y jQuery | Craftyman Blog
- 30+ Brand New jQuery Plugins To Change the Look and Feel of Your Website
- 30+ New jQuery Plugins To Change the Look and Feel of Your Website « qeqnes | Designing. jQuery, Ajax, PHP, MySQL and Templates
- 50 Awesome New jQuery Plugins :Speckyboy Design Magazine
- 50 Awesome New jQuery Plugins · rogdykker
- 50 Awesome New jQuery Plugins | DesignerLinks | Home to Web design news, jQuery Tutorials, CSS tutorials, Web Designing tutorials, JavaScript tutorials and more!
- [indiFish] learn to be a pro designer!
- 50 Awesome New jQuery Plugins | Typography Blog
- 10 Fresh and Useful jQuery Plugins | Tools
- 10 Fresh and Useful jQuery Plugins | Xiaoqi He ( Harry He ) – Official Blog – 贺孝琦官方博客
- 10 Fresh and Useful jQuery Plugins | Web Design Chicago
- 10 Fresh and Useful jQuery Plugins | Focus of Photography
- 10 Fresh and Useful jQuery Plugins « fanclub_demo4
- 10 Fresh and Useful jQuery Plugins | gabriel catalano | in-perfección
- 10 Fresh and Useful jQuery Plugins « fanclub_demo11
- Indexw3: Blog de Tecnología » 10 Nuevos plugins para jQuery
- 10 Fresh and Useful jQuery Plugins | Tools | Ispey Seo Expert
- links for 2010-09-04 | A Web editor's tale
- 10 Fresh and Useful jQuery Plugins | Afif Fattouh – Web Specialist
- 10 Best jQuery Plugins | Cosmos Blog – Tips For Designer And Bloggers
- Developpeur Web » JQuery et les outils Google
- 10 Fresh and Useful jQuery Plugins | Gazetem Sanat
- Best jQuery Plugins of 2010 | Resources
- Best jQuery Plugins of 2010 | Focus of Photography
- Best jQuery Plugins of 2010 | Focus of Photography
- 11 Fresh and Useful jQuery Plugins | StarWebSoft Blog – Website Design & Development, SEO Service, Online Marketing
- Best jQuery Plugin-ovi za 2010 – Web dizajn blog PopArt
- 50 Awesome New jQuery Plugins « Blog d'Artefakt
- Create a Web Spy with a PHP Crawler « RPL Class
- Tổng hợp jQuery plugin của năm 2010 « Kỹ Thuật Lập Trình ASP.NET
Hello.
The plugin works great. There’s just a little bug with float numbers. I have solved it myself already. Check this post on StackOverflow:
http://stackoverflow.com/questions/3397185/google-chart-odd-rounding-for-values/3397433
Basically, I switched parseInt() for parseFloat() and it works great.