Book Image

DART Cookbook

By : Ivo Balbaert
Book Image

DART Cookbook

By: Ivo Balbaert

Overview of this book

Table of Contents (18 chapters)
Dart Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using JavaScript libraries


In this recipe, we use the js package as an interface from our Dart script to the Google Chart JavaScript API. This gives us many rich and highly customizable ways to graphically represent data in our Dart web apps and, because it is built with HTML5/SVG, it works cross-browser (even for older IE versions) and cross-platform (also for iOS and Android).

How to do it...

Take a look at the project googlechart:

  1. In the <body> tag of the HTML file, place the following:

    <div id="chart" style="width: 900px; height: 500px;"></div>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="application/dart" src="googlechart.dart"></script>

    The <div> tag with the ID chart is where the chart will be drawn; the code to do this is contained in googlechart.dart.

  2. The following is the data we want to represent in a chart:

    var listData = [
                    ['Year', 'Sales', 'Expenses'],
                    ['2004...