>

JChart

A JQuery Chart Making Plugin

Description


This plugin will allow you to create a bar chart with raw data, either specified in a Javascript array, or in plain old HTML with some specific classes and attributes.

Requires JQuery 1.9.x and Twitter Bootstrap 3.0.x with tooltip enabled.

Live Demo

Mouse over bars to see their exact value.


500000
217500
119000
78000
466000
326000

Javascript Usage


You can create a basic bar chart on an html element by calling .jChart() on a JQuery object or collection.

	
	$("#population_chart").jChart({
		name: "North American Regional Population Loss 2014",
		headers: ["Arizona","Michigan","Ontario","British Columbia","Texas"],
		values: [250000,478000,88000,429000,423000],
		footers: [100000,200000,300000,400000,500000],
		colors: ["#1000ff","#006eff","#00b6ff","#00fff6","#00ff90"]
	});
	

All parameters except for the values are optional. The HTML would look like this:

	
	<div id="population_chart"></div>
	

HTML Usage


Many of the options can be overridden in raw HTML, without the need to write any Javascript. First, place a block element, like a <div> on the page (#bar_of_pies in the example below). You can give it a name to override the title, a semantic bootstrap-like class ("chart-sm" or "chart-lg") to change bar and text sizing, a data-width attribute(Integer specifying chart width in pixels), and a data-sort="true" to override the sort function (default is false). The content of the element should be the value that you want the bar to have.


Additionally, you may include any number of elements within your container with the class "define-chart-row" to create a new bar. Give that element a data-color (rgb, hex, or semantic) to override the color. You can specify a title attribute in that element to give the bar a heading.


You may also specify any number of elements with the class "define-chart-footer" to indicate where a footer should be placed. The value that the footer and label should be placed at should be the content of the element.

Here is an example

	
	<div id="bar_of_pies" data-sort="true" data-width="300" class="jChart chart-sm" name="My Favorite Pies">
		<div class="define-chart-row" data-color="red" title="Pumpkin">13</div>
		<div class="define-chart-row" data-color="gray" title="Pecan">24</div>
		<div class="define-chart-row" data-color="green" title="Cherry">17</div>
		<div class="define-chart-row" data-color="orange" title="Apple">26</div>
		<div class="define-chart-row" data-color="black" title="Rhubarb">12</div>
		<div class="define-chart-row" data-color="blue" title="Chocolate Cream">8</div>
		
		<div class="define-chart-footer">10</div>
		<div class="define-chart-footer">20</div>
		<div class="define-chart-footer">30</div>
	</div>
	

Then simply call $("#bar_of_pies").jChart(); without any options specified to generate the chart like below:

13
24
17
26
12
8

Options


OptionDescriptionDefault
widthA number specifying the pixel width of the chart750
nameThe name of the chart, displayed at the top of the chartnull
typeThe type of chart - currently only supports bar charts"bar"
headersA Javascript array of bar labelsnull (no labels)
valuesA Javascript array of numeric values for each corresponding barnull
footersA Javascript array of numeric values to display at the bottom of the chartnull
colorsA Javascript array of colors that will loop back if needed#6b9bd6 (dark blue)
sortIndicates if the bars should be sorted (not implemented)false