A bubble chart is a chart whose data points are replaced with bubbles of various shapes and scattered across the chart. It is like a scatter chart. The Wijmo widget representing a bubble chart is referred to as a wijbubblechart
object.
The data points or bubbles each have three non-dependent values, x
, y
, and y1
as follows:
The value
x
defines the Cartesian position along the x axisThe value
y
defines the Cartesian position along the y axisThe value
y1
defines the bubble size at each point
Having understood a bubble chart and the three values that define the positions of the bubble, we can now happily proceed with an implementation. Let us create a wijbubblechart
object of the percentage of college graduates in six major cities around the world. This is dummy data and doesn't reflect the actual relationship between college graduates and the health of the corresponding economy. However, this dummy data is based on the assumption that a city with more graduates per thousand will have a smarter economy. Also, this depends on the overall population of that city.
Enter the following code into your favorite code editor:
<html> <head> <!--jQuery References--> <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.1.min.js" type="text/javascript"></script> <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.17/jquery-ui.min.js" type="text/javascript"></script> <!--Wijmo Widgets JavaScript--> <script src="http://cdn.wijmo.com/jquery.wijmo-open.all.2.0.0.min.js" type="text/javascript"></script> <script src="http://cdn.wijmo.com/jquery.wijmo-complete.all.2.0.0.min.js" type="text/javascript"></script> <!--Theme--> <link href="http://cdn.wijmo.com/themes/rocket/jquery-wijmo.css" rel="stylesheet" type="text/css" title="rocket-jqueryui" /> <!--Wijmo Widgets CSS--> <link href="http://cdn.wijmo.com/jquery.wijmo-complete.all.2.0.0.min.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> $(document).ready(function () { $("#myWijbubblechart").wijbubblechart({ showChartLabels: false, axis: { y: { text: "Smart Economy Rating" }, x: { text: "College Graduates(Per Thousand)" } }, hint: { content: function () { return this.data.label; } }, header: { text: "College Graduates Vs. Health of the Economy - 2012" }, seriesList: [{ label: "Beijing", legendEntry: true, data: { y: [85], x: [150], y1: [1340] }, markers: { type: "tri" } }, { label: "New Delhi", legendEntry: true, data: { y: [80], x: [167], y1: [1150] }, markers: { type: "diamond" } }, { label: "Los Angeles", legendEntry: true, data: { y: [92], x: [400], y1: [309] }, markers: { type: "circle" } }, { label: "Tokyo", legendEntry: true, data: { y: [94], x: [250], y1: [126] }, markers: { type: "invertedTri" } }, { label: "London", legendEntry: true, data: { y: [82], x: [200], y1: [140] }, markers: { type: "cross" } }, { label: "Lagos", legendEntry: true, data: { y: [48], x: [374], y1: [72] }, markers: { type: "box" } }] }); }); </script> </head> <body> <div id="myWijbubblechart" class="ui-widget ui-widget-content ui-corner-all" style="width: 500px; height: 300px"> </div> </body> </html>
If the preceding code is copied correctly and run in a browser, we should have a Wijmo bubble chart similar to the following screenshot:
To see how the
wijbubblechart
object works, we can simply examine one of the objects in theseriesList
property, like this one:{ label: "Beijing", legendEntry: true, data: { y: [85], x: [150], y1: [1340] }, markers: { type: "tri" } },
Remember that we already defined
x
,y
, andy1
as the values of a point on the x axis, a point on the y axis, and the size of the bubble respectively. So in this case, for Beijing the value fory
is set to85
, and the size of the bubble,y1
, is1340
. ThelegendEntry
property is set totrue
so we can see Beijing in the legend area by the right of the chart.We can see the various bubbles in different shapes and a legend that tells what city each bubble represents. The
type
property of themarkers
object is responsible for setting the shape of the bubble.markers: { type: "tri" }
One more common aspect of the wijbubblechart
object is the possibility of changing its appearance, for example, applying gradient colors, using some options, and so on. To achieve this we simply have to include a seriesStyles
property as follows:
<script type="text/javascript"> $(document).ready(function () { //instantiating wijbubblechart on #myWijbubblechart $("#myWijbubblechart").wijbubblechart({ showChartLabels: false, //setup the x and y axis labels axis: { y: { text: "Smart Economy Rating" }, x: { text: "College Graduates(Per Thousand)" } }, //Display hint text on chart hover hint: { content: function () { return this.data.label; } }, //title of chart header: { text: "College Graduates Vs. Health of the Economy - 2012" }, //chart color fill styles seriesStyles: [{ fill: "180-#8F8F8F-#C462AC", stroke: "#8F8F8F" }, { fill: "45-#C462AC-#2371B0", stroke: "#C462AC" }, { fill: "90-#4A067D-#0B7D19", stroke: "#4A067D" }, { fill: "270-#2371B0-#6AABA7", stroke: "#2371B0" }, { fill: "45-#0C85F0-#852E85", stroke: "#0C85F0" }, { fill: "180-#6AABA7-#AB6A9C", stroke: "#6AABA7" }], //data values for each bubble seriesList: [{ label: "Beijing", legendEntry: true, data: { y: [85], x: [150], y1: [1340] }, markers: { type: "tri" } }, { label: "New Delhi", legendEntry: true, data: { y: [80], x: [167], y1: [1150] }, markers: { type: "diamond" } }, { label: "Los Angeles", legendEntry: true, data: { y: [92], x: [400], y1: [309] }, markers: { type: "circle" } }, { label: "Tokyo", legendEntry: true, data: { y: [94], x: [250], y1: [126] }, markers: { type: "invertedTri" } }, { label: "London", legendEntry: true, data: { y: [82], x: [200], y1: [140] }, markers: { type: "cross" } }, { label: "Lagos", legendEntry: true, data: { y: [48], x: [374], y1: [72] }, markers: { type: "box" } }] }); }); </script>
If we successfully run the preceding code, we should have a bubble chart that looks like this:
You can visit http://wijmo.com/wiki/index.php/Bubblechart for more details about Wijmo bubble charts and more advanced options available for customizing your charts.