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)

Column bar chart (Simple)


A column bar chart widget is slightly different from the regular bar chart widget we previously created. Remember we also had a look at some of the useful and common options used by most Wijmo developers. The last one we listed was the horizontal option of type Boolean. The default value of the horizontal option is true. This implies that the bar chart will be rendered in a horizontal layout by default.

Getting ready

For the creation of our first column bar chart, we shall proceed by setting the horizontal option to false, using the same code used for the previous bar chart we had created. Here's our new complete code:

<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" />
</head>
<body>
<div id="wijbarchart" class="ui-widget ui-widget-content ui-corner-all" style="width: 400px;
height: 300px">
</div>

<script id="scriptInit" type="text/javascript">
        $(document).ready(function () {
    //activating the wijbarchart function on #wijbarchart
            $("#wijbarchart").wijbarchart({
            horizontal: false,//makes it vertical 
            axis: { //set up the x and y axes
                y: {
                    text: "Total Automation Sales",
                     
                },
                x: {
                    text: "",
                    labels: {
                        style: {
                            rotation: -45
                        }
                    }
                }
            },
 
                hint: { //hint text when hovering over chart
                    content: function () {
                        return this.data.label + '\n ' + this.y + '';
                    }
                },
 
                header: {//chart title
                    text: "US Toyota Automobile Statistics (Dummy Data)"
                },
       //data for chart representing each column
                seriesList: [{
                    label: "US",
                    legendEntry: true,
                    data: { x: ['Toyota Camry', 'Toyota Corolla', 'Toyota Sienna'], y: [12.35, 21.50, 30.56] }
                }],
 
               seriesStyles: [{
                fill: "40-#BD0070-#718680", stroke: "#1261C0", opacity: 0.7 
               }],
 
                seriesHoverStyles: [{ "stroke-width": "1.5", opacity: 1
                }]
            });
        });
    </script>
    </body>
</html>

Notice from the preceding code, which we will hereon refer to as the main code, that we set the horizontal option to false. Now, when we run the main code, we should see a column bar chart widget as follows:

That's how simple switching from a regular bar chart to a column bar chart is. The choice between either of the two bar charts is usually dependent on user preference.

How to do it...

We reference the Wijmo dependencies as follows:

  1. After the page loads, we set the horizontal property to false.

  2. The x and y properties are set, and y is rotated at -45 degrees, which rotates the labels for Toyota Camry, Toyota Corolla, and Toyota Sienna.

  3. We set the hint property, which is displayed on hovering over the chart.

  4. We set the header property, which is displayed atop the grid.

  5. For the seriesList property, we have a data subproperty that holds data for x and y. These values are mapped one-to-one in such a way that x['Toyota Camry'] gets y[0] or y[12.35].

  6. For the seriesStyles property, we set the gradient color as "40-#BD0070-#718680" and set the opacity value as 0.7.