Book Image

FusionCharts Beginner's Guide: The Official Guide for FusionCharts Suite

Book Image

FusionCharts Beginner's Guide: The Official Guide for FusionCharts Suite

Overview of this book

User experience can make or break any app these days, no matter whether it's a commercial product or an internal solution. While most web applications out there are boring and outdated when it comes to their charting, you can make yours both stunning and powerful using FusionCharts Suite. Once you have mastered it, you can give your users a delightful reporting experience in no time at all. FusionCharts Beginner's Guide is a practical, step-by-step guide to using FusionCharts Suite for creating delightful web reports and dashboards. Getting you started quickly, you will learn advanced reporting capabilities like drill-down and JavaScript integration, and charting best practices to make the most out of it. Filled with examples, real-life tips and challenges, this book is the firstofitstype in the visualization industry. The book teaches you to create delightful reports and dashboards for your web applications assuming no previous knowledge of FusionCharts Suite. It gets your first chart up in 15 minutes after which you can play around with different chart types and customize them. You will also learn how to create a powerful reporting experience using drill-down and advanced JavaScript capabilities. You will also connect your charts to server-side scripts pulling data from databases. Finally you round up the experience learning reporting best practices including right chart type selection and practical usability tips. By the end of the book, you will have a solid foundation in FusionCharts Suite and data visualization itself. You will be able to give your users a delightful reporting experience, from developers to management alike.
Table of Contents (16 chapters)
FusionCharts
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface

Time for action — converting FusionCharts XML format to JSON


  1. 1. Launch the FCDataConverter tool from the FusionCharts Installation Folder | Tools | FCDataConverter | Index.html.

  2. 2. Once the page has finished loading, in the text area on the left, titled FusionCharts XML Data, paste the XML data that we had previously created for Revenue by Year chart.

  3. 3. Click on the Convert to JSON button present below it.

  4. 4. In the text area on the right, you will now see the JSON equivalent of the XML data, as shown in the following screenshot:

What just happened?

Using the FusionCharts Data Format Conversion Tool, you just converted the previous XML data into JSON format. It reads as in the following code snippet:

{
"chart": {
"caption": "Harry's SuperMart",
"subcaption": "Revenue by Year",
"xaxisname": "Year",
"yaxisname": "Amount",
"numberprefix": "$"
},
"data": [
{
"label": "2009",
"value": "1487500"
},
{
"label": "2010",
"value": "2100600"
},
{
"label": "2011",
"value": "2445400"
}
]
}

Similar to XML, the chart object contains attributes that let you configure functional and cosmetic aspects of the chart.

In the most general form, chart attributes represent the following JSON format:

"attributeName" : "Value"

For example,"xAxisName" : "Year"

The attributes can occur in any order and values can be specified either using double quotes or single, for example, xAxisName:'Year'. However, you need to ensure that the same attribute is not defined twice for any element, as it results in an invalid XML.

Note

Escaping of special characters is not compulsory in the JSON URL format

When using the JSON data format, special characters are not encoded to XML entities. Instead, they are escaped in JavaScript using \. However, this is not mandatory when using JSON URL as data, as JavaScript loads the JSON data and directly parses attributes as string literals. Hence, in our example, Harry's SuperMart does not need to be encoded as we had done in the XML format.

However, if you have a mismatch of JavaScript enclosing quotes and JSON attribute quotes, as we will see in our next example, escaping is required.

Next, the array data contains all the data points to be plotted on the chart. For example, in XML, label attribute for each data point defines its text label, and the value attribute represents its numerical value. Each element in the data array is an unnamed object defined in the following format:

{ "label: "Jan", "value" : "17400", "otherAttribute" : "value"}

With the JSON format understood, let us also look at how to use the setJSONUrl() and setJSONData() methods.