Book Image

Instant Wijmo Widgets How-to

By : Tochi Eke-Okoro
Book Image

Instant Wijmo Widgets How-to

By: Tochi Eke-Okoro

Overview of this book

With Wijmo you will always be one step ahead of regular UI developers. Wijmo doesn't require a re-invention of the wheel; it is written with JQuery, so it supports regular JQuery and even native Javascript. You can initialize any widget you want to use for your project and customize its functionality and styling. With Wijmo, the possibilities are limitless!!"Instant Wijmo Widgets How-to" is perfect for aspiring and experienced UI developers. It describes basic techniques of initializing and deploying various UI widgets that serve a specific purpose. It is an ideal book for aspiring and experienced UI developers. It describes basic techniques for initializing and deploying various UI widgets that serve a specific purpose."Instant Wijmo Widgets How-to" is structured to take you from easy to seemingly difficult topics. This implies that some widgets are easier to initialize than others. However the overall deployment of a widget is basic and straightforward, without the complexities encountered in various JQuery plugins. Every topic discussed in this book is interesting, engaging, and exciting. There is no strict direction from one chapter to the next.. Most chapters are independent of each other. This creates the flexibility to delve into just what you need to resolve a particular task. "Instant Wijmo Widgets How-to" serves as an important inventory for a UI developer, equipping the reader with skills to solve most UI related issues.
Table of Contents (7 chapters)

Bubble chart (Intermediate)


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.

Getting ready

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 axis

  • The value y defines the Cartesian position along the y axis

  • The 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:

How to do it...

  1. To see how the wijbubblechart object works, we can simply examine one of the objects in the seriesList property, like this one:

                    {
                        label: "Beijing",
                        legendEntry: true,
                        data: { y: [85], x: [150], y1: [1340] },
                        markers: {
                            type: "tri"
                        }
                    },
  2. Remember that we already defined x, y, and y1 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 for y is set to 85, and the size of the bubble, y1, is 1340. The legendEntry property is set to true so we can see Beijing in the legend area by the right of the chart.

  3. We can see the various bubbles in different shapes and a legend that tells what city each bubble represents. The type property of the markers object is responsible for setting the shape of the bubble.

        markers: {
                            type: "tri"
                        }

There's more...

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>

Note

The script tags should be embedded within the HTML tags for a successful run.

If we successfully run the preceding code, we should have a bubble chart that looks like this:

See also

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.