<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>FusionBrew - The official FusionCharts blog</title> <atom:link href="http://blog.fusioncharts.com/feed/" rel="self" type="application/rss+xml" /><link>http://blog.fusioncharts.com</link> <description></description> <lastBuildDate>Tue, 10 Apr 2012 11:22:46 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>How boring charts in Microsoft Excel and a craving for pocket money gave birth to FusionCharts</title><link>http://blog.fusioncharts.com/2012/04/how-boring-charts-in-microsoft-excel-and-a-craving-for-pocket-money-gave-birth-to-fusioncharts/</link> <comments>http://blog.fusioncharts.com/2012/04/how-boring-charts-in-microsoft-excel-and-a-craving-for-pocket-money-gave-birth-to-fusioncharts/#comments</comments> <pubDate>Tue, 10 Apr 2012 11:22:46 +0000</pubDate> <dc:creator>Hrishikesh Choudhari</dc:creator> <category><![CDATA[News & Announcements]]></category> <category><![CDATA[Thoughts]]></category> <category><![CDATA[customers]]></category> <category><![CDATA[history]]></category> <category><![CDATA[milestone]]></category> <category><![CDATA[our story]]></category><guid isPermaLink="false">http://blog.fusioncharts.com/?p=2724</guid> <description><![CDATA[It all began in 2002 when our CEO, all of 17-years then, was fed up of *boring* charts in Excel. This, alongside an opportunity to tap into the lack of interactive charting solutions on the web and rake in decent pocket money set the ball in motion. He figured out an innovative way using Macromedia Flash (back then) to make charts interactive and fun, published that as an article and]]></description> <content:encoded><![CDATA[<p></p><a href="http://blog.fusioncharts.com/2012/04/how-boring-charts-in-microsoft-excel-and-a-craving-for-pocket-money-gave-birth-to-fusioncharts/" title="Link to How boring charts in Microsoft Excel and a craving for pocket money gave birth to FusionCharts"><img class="wppt_float_left" src="http://blog.fusioncharts.com/wp-post-thumbnail/LD3BYL.jpg" alt="" title="" width="88" height="88" /></a><p>It all began in 2002 when our CEO, all of 17-years then, was fed up of *boring* charts in Excel. This, alongside an opportunity to tap into the lack of interactive charting solutions on the web and rake in decent pocket money set the ball in motion. He figured out an innovative way using Macromedia Flash (back then) to make charts interactive and fun, published that as an article and the rest as they say is &#8220;HISTORY&#8221;.<br /> <span id="more-2724"></span></p><p><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/04/20k_pictogram.jpg" alt="" title="FusionCharts has 20,000 customers" width="418" height="222" class="aligncenter size-full wp-image-2725" /></p><p>Our evolution has been exciting all along. Starting without any external funding (in fact none till date) and all of six chart types (since that&#8217;s all of what we knew back then), the first version of FusionCharts was launched. It steadily picked up steam and today we boast of 90 chart types and 550 maps. More importantly, FusionCharts today powers over a *billion* charts a month in some of the most popular web destinations like LinkedIn, Weather.com, Google Docs etc. We also have a picture of President Obama using FusionCharts products….and no it is NOT Photoshopped!!!!!!</p><p><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/04/f3_base.jpg" alt="" title="The First 3 Years" width="360" height="414" class="aligncenter size-full wp-image-2746" /></p><p>For the first three years of our existence, a desk and a chair were all we had. No &#8220;official&#8221; office, no employees, not even an office number to call up on. In fact, the founder&#8217;s home number doubled up as the office number and he changed accents when you thought the call had been transferred from the support to the sales team. We didn&#8217;t even have a single dedicated sales person till we got to 10,000 customers, forget a sales team. In fact, we hadn&#8217;t even stepped out on foreign soil for as much as an expo till a year back. Guess we can safely say that hard work and persistence does pay off.</p><p><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/04/mkt_base.jpg" alt="" title="Moving up the value chain" width="357" height="305" class="aligncenter size-full wp-image-2747" /></p><p>As we moved up the value-chain, so did our learnings and offerings. From our first ever tag line &#8220;The extensive real-time animated graphing solution&#8221; to the current &#8220;Data to delight&#8230; in minutes,&#8221; we have come a long way. We learnt a lot about technology, markets, dynamics and even marketing. We have our own mascot too, the FusionCharts Dude. We introduced products for Microsoft SharePoint, PowerPoint, VB6, Adobe Flex and Joomla. We even gave back to the community a free version of our core product. Success breeds more success and we gained tremendous coverage in leading publications like Forbes, Entrepreneur, Mixergy, Penn-Olson and far too many magazines, all of these without spending a single dime on PR. We have also been acknowledged as one of the 50 fastest growing tech firms in India and one of the top 500 firms in Asia-Pacific.</p><p>This is just the beginning and we are working hard to constantly push the boundaries of data visualization. We thank you for being with us along this exciting journey, for the brickbats and the bouquets alike. It matters a lot to us.</p> ]]></content:encoded> <wfw:commentRss>http://blog.fusioncharts.com/2012/04/how-boring-charts-in-microsoft-excel-and-a-craving-for-pocket-money-gave-birth-to-fusioncharts/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>JavaScript charts using SQL Server data with FusionCharts XT &#8211; Part 2</title><link>http://blog.fusioncharts.com/2012/03/javascript-charts-using-sql-server-data-with-fusioncharts-xt-part-2/</link> <comments>http://blog.fusioncharts.com/2012/03/javascript-charts-using-sql-server-data-with-fusioncharts-xt-part-2/#comments</comments> <pubDate>Fri, 30 Mar 2012 13:40:12 +0000</pubDate> <dc:creator>Hrishikesh Choudhari</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[asp.net]]></category> <category><![CDATA[dotnet]]></category> <category><![CDATA[javascript]]></category><guid isPermaLink="false">http://blog.fusioncharts.com/?p=2691</guid> <description><![CDATA[In the second part of FusionCharts XT with ASP.NET series, learn how to use SQL Server data to create JavaScript charts. We will use the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/csnet/CS_BasicExample.html" target="_blank">.NET library bundled with FusionCharts XT</a> to create charts in ASP.NET (C#). In the first article of this series, we saw how this .NET library reduces developer effort and generates the HTML and JavaScript required to produce interactive charts in the browser<div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1'>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2'>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/' rel='bookmark' title='Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3'>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p></p><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-using-sql-server-data-with-fusioncharts-xt-part-2/" title="Link to JavaScript charts using SQL Server data with FusionCharts XT - Part 2"><img class="wppt_float_left" src="http://blog.fusioncharts.com/wp-post-thumbnail/i0CJac.png" alt="" title="" width="88" height="88" /></a><p>In the second part of FusionCharts XT with ASP.NET series, learn how to use SQL Server data to create JavaScript charts. We will use the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/csnet/CS_BasicExample.html" target="_blank">.NET library bundled with FusionCharts XT</a> to create charts in ASP.NET (C#). In the first article of this series, we saw how this .NET library reduces developer effort and generates the HTML and JavaScript required to produce interactive charts in the browser.<br /> <span id="more-2691"></span></p><blockquote><h3>FusionCharts XT with ASP.NET</h3><ul><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/" target="_blank">Part 1 &#8211; Create JavaScript charts in ASP.NET (C#)</a></li><li><a href="#">Part 2 &#8211; Plot JavaScript charts using SQL Server data</a></li><li>Part 3 &#8211; Create Drill-Down &#038; LinkedCharts in ASP.NET(C#)</li></ul></blockquote><h2>What we are going to visualize</h2><p>We will use the same SQL Server database that powers our showcase <a href="http://www.fusioncharts.com/demos/business/#management-dashboard" target="_blank">Management Dashboard</a>. To keep things simple, we will plot the Total Sales Revenue of each Year.<br /><script type="text/javascript" src="/Assets/fusioncharts/js/FusionCharts.js"></script></p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='annual_revenue';var myChartSWF='/Assets/fusioncharts/Column2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData('<chart caption="Total Revenue" palette="3" showValues="0" numberPrefix="$" useRoundEdges="1"><set label="1994" value="175345.1000"/><set label="1995" value="631865.8900"/><set label="1996" value="547247.6000"/></chart>');chartObj.render(myChartId+'container');/*]]>*/</script></p><h2>.NET library bundled with FusionCharts XT</h2><p>FusionCharts XT is essentially a JavaScript library. In order to render a chart, certain amount of HTML and JavaScript is required, along with the chart data in <a href="http://docs.fusioncharts.com/charts/contents/?DataFormats/XML/Overview.html" target="_blank">XML</a> or <a href="http://docs.fusioncharts.com/charts/contents/?DataFormats/JSON/Overview.html" target="_blank">JSON</a>.</p><p>In order to automate this, we provide a .NET library with FusionCharts XT, which generates the HTML and JavaScript required. You can find this library in <code class="codecolorer xml default"><span class="xml">FusionCharts XT Download Package &gt; Code &gt; CS &gt; Bin &gt; FusionCharts.dll</span></code>. By referencing this library, rendering charts is just one line of code! Let us see how..</p><h2>What we will need</h2><ul><li>Visual Studio or Visual Web Developer</li><li>SQL Server</li><li><a href="http://www.fusioncharts.com/download/trials/" target="_blank">The latest version of FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionChartsDB.zip">Sample SQL Server Database</a></li></ul><h2>Preparing the project</h2><p>We will be using Visual Studio 2010 for this series. Visual Studio 2008 or Visual Web Developer will suit fine too.</p><p>You can re-use the project we created in the previous article, or create a new one:</p><ul><li>Create a blank ASP.NET (C#) web site and save it as <code class="codecolorer csharp default"><span class="csharp">FusionChartsXT_with_ASPNET</span></code>.</li><li>Right-click the project&#8217;s name in <code class="codecolorer xml default"><span class="xml">Solution Explorer &gt; Add New Item &gt; Web Form</span></code>. Keep the name as <code class="codecolorer csharp default"><span class="csharp">Using_MS_SQL_Server<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span></span></code>.</li><li>Copy the <code class="codecolorer csharp default"><span class="csharp">Charts</span></code> folder from the FusionCharts Download Package and paste it in the Solution Explorer.</li><li>Include the FusionCharts XT&#8217;s JavaScript file in <code class="codecolorer csharp default"><span class="csharp">Using_MS_SQL_Server<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span></span></code>:<div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container html4strict default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Charts/FusionCharts.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></div></div><div class="code-holder-bottom"></div></div></li><li>Right-click the project&#8217;s name in <code class="codecolorer xml default"><span class="xml">Solution Explorer &gt; Add ASP.NET Folder &gt; App_Data</span></code>.</li><li>Right-click <code class="codecolorer xml default"><span class="xml">App_Data &gt; Add Existing Item &gt; Browse</span></code> to the folder containing <a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionChartsDB.zip">Sample SQL Server Database</a>.</li><li>Right-click the project&#8217;s name in <code class="codecolorer xml default"><span class="xml">Solution Explorer &gt; Add Reference &gt; Browse</span></code>. Now browse to <code class="codecolorer xml default"><span class="xml">FusionCharts XT Download Package &gt; Code &gt; CS &gt; Bin &gt; FusionCharts.dll</span></code>.</li><li>In <code class="codecolorer csharp default"><span class="csharp">Using_MS_SQL_Server<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span><span style="color: #008000;">.</span><span style="color: #0000FF;">cs</span></span></code>, include the namespace of this library by writing<div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container csharp default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">InfoSoftGlobal</span><span style="color: #008000;">;</span></div></div><div class="code-holder-bottom"></div></div></li></ul><p>The above steps are necessary whenever you want to use FusionCharts XT in a .NET project.</p><p>Before we begin coding, let us have a look at the database. It has 7 tables:<br /> <img src="http://blog.fusioncharts.com/wp-content/uploads/2012/03/Database.png" alt="" title="Database" width="256" height="359" class="aligncenter size-full wp-image-2702" /><br /> But we will work with just 2 of them for this demo &#8211; <code class="codecolorer html4strict default"><span class="html4strict">FC_Orders</span></code> and <code class="codecolorer html4strict default"><span class="html4strict">FC_OrderDetails</span></code>:<br /> <img src="http://blog.fusioncharts.com/wp-content/uploads/2012/03/Concerned-Database-Tables.png" alt="" title="Concerned Database Tables" width="255" height="380" class="aligncenter size-full wp-image-2701" /></p><h2>Creating charts using Data String method</h2><p>As explained in the previous post, you can supply data to FusionCharts using the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataXMLExp.html" target="_blank">Data String method</a> or the Data URL method. First, let us try the Data String method.</p><p>In this method, the XML or JSON data is embedded within the web page, along with the chart’s HTML and JavaScript code. This method doesn’t require a static data file or a virtual data provider. Moreover, once the chart has finished loading, the data is present locally within the page.</p><p>In <code class="codecolorer csharp default"><span class="csharp">Using_MS_SQL_Server<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span></span></code>, create a <code class="codecolorer html4strict default"><span class="html4strict">Literal</span></code> tag with a unique ID.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container csharp default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Literal ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;chart_from_db&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br /> <span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Literal<span style="color: #008000;">&gt;</span></div></div><div class="code-holder-bottom"></div></div><p>In the code-behind page, write the following code. In-line comments will help you understand what we&#8217;re doing:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container csharp default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data.Sql</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data.SqlClient</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">InfoSoftGlobal</span><span style="color: #008000;">;</span><br /> <br /> <br /> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> Using_MS_SQL_Server <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><br /> <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_Load<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Construct the connection string to interface with the SQL Server Database</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> connStr <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Fusion Charts\Documents\Visual Studio 2010\WebSites\FusionChartsXT_with_ASPNET\App_Data\FusionChartsDB.mdf;Integrated Security=True;User Instance=True&quot;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Initialize the string which would contain the chart data in XML format</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; StringBuilder xmlStr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Provide the relevant customization attributes to the chart</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; xmlStr<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;chart caption='Total Revenue' palette='3' showValues='0' numberPrefix='$' useRoundEdges='1'&gt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Create a SQLConnection object </span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>SqlConnection conn <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlConnection<span style="color: #008000;">&#40;</span>connStr<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Establish the connection with the database</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conn<span style="color: #008000;">.</span><span style="color: #0000FF;">Open</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Construct and execute SQL query which would return the total amount of sales for each year</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlCommand query <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlCommand<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;SELECT SUM(FC_OrderDetails.UnitPrice * FC_OrderDetails.Quantity) AS AMOUNT, YEAR(FC_Orders.OrderDate) AS yr FROM FC_Orders INNER JOIN FC_OrderDetails ON FC_OrderDetails.OrderID = FC_Orders.OrderID GROUP BY YEAR(FC_Orders.OrderDate) ORDER BY YEAR(FC_Orders.OrderDate)&quot;</span>, conn<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Begin iterating through the result set</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlDataReader rst <span style="color: #008000;">=</span> query<span style="color: #008000;">.</span><span style="color: #0000FF;">ExecuteReader</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>rst<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Construct the chart data in XML format</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlStr<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendFormat</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;set label='{0}' value='{1}'/&gt;&quot;</span>, rst<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;yr&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, rst<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;AMOUNT&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// End the XML string</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlStr<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;/chart&gt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Close the result set Reader object and the Connection object</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rst<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conn<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Call the RenderChart method, pass the correct parameters, and write the return value to the Literal tag</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; chart_from_db<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> FusionCharts<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderChart</span><span style="color: #008000;">&#40;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">&quot;FusionChartsXT/Column2D.swf&quot;</span>, <span style="color: #008080; font-style: italic;">// Path to chart's SWF</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">&quot;&quot;</span>, &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Leave blank when using Data String method</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlStr<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, &nbsp;<span style="color: #008080; font-style: italic;">// xmlStr contains the chart data</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">&quot;annual_revenue&quot;</span>, &nbsp; <span style="color: #008080; font-style: italic;">// Unique chart ID</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">&quot;640&quot;</span>, <span style="color: #666666;">&quot;340&quot;</span>, &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Width &amp; Height of chart</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">false</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Disable Debug Mode</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Register with JavaScript object</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> <span style="color: #008000;">&#125;</span></div></div><div class="code-holder-bottom"></div></div><p>Save and run this project. This is the chart that you should see in your browser:</p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='annual_revenue_2';var myChartSWF='/Assets/fusioncharts/Column2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData('<chart caption="Total Revenue" palette="3" showValues="0" numberPrefix="$" useRoundEdges="1"><set label="1994" value="175345.1000"/><set label="1995" value="631865.8900"/><set label="1996" value="547247.6000"/></chart>');chartObj.render(myChartId+'container');/*]]>*/</script></p><h2>Creating charts using Data URL method</h2><p>As previously explained, in Data URL method, you need two pages:</p><li><strong>Chart Container Page</strong> &#8211; The page which embeds the HTML code to render the chart. This page also tells the chart where to load the data from. We&#8217;ll use the <code class="codecolorer csharp default"><span class="csharp">Using_MS_SQL_Server<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span></span></code> page for this.</li><li><strong>Data Provider Page</strong> &#8211; This page provides the XML data to the chart. We&#8217;ll name this page as <code class="codecolorer csharp default"><span class="csharp">DataProvider<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span></span></code>.<p>Keep the code in <code class="codecolorer csharp default"><span class="csharp">Using_MS_SQL_Server<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span></span></code> as it is. Delete all but the first line from <code class="codecolorer csharp default"><span class="csharp">DataProvider<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span></span></code>.</p><p>From <code class="codecolorer csharp default"><span class="csharp">Using_MS_SQL_Server<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span><span style="color: #008000;">.</span><span style="color: #0000FF;">cs</span></span></code>, <em>cut</em> the contents of the <code class="codecolorer csharp default"><span class="csharp">Page_Load<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></span></code> method, till before the <code class="codecolorer csharp default"><span class="csharp">RenderChart<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></span></code> method&#8217;s line. Paste it in <code class="codecolorer csharp default"><span class="csharp">DataProvider<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span><span style="color: #008000;">.</span><span style="color: #0000FF;">cs</span></span></code>. This is what you should have in <code class="codecolorer csharp default"><span class="csharp">DataProvider<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span><span style="color: #008000;">.</span><span style="color: #0000FF;">cs</span></span></code>:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container csharp default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data.Sql</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Data.SqlClient</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">InfoSoftGlobal</span><span style="color: #008000;">;</span><br /> <br /> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> DataProvider <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><br /> <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_Load<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Construct the connection string to interface with the SQL Server Database</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> connStr <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Fusion Charts\Documents\Visual Studio 2010\WebSites\FusionChartsXT_with_ASPNET\App_Data\FusionChartsDB.mdf;Integrated Security=True;User Instance=True&quot;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Initialize the string which would contain the chart data in XML format</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; StringBuilder xmlStr <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Provide the relevant customization attributes to the chart</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; xmlStr<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;chart caption='Total Revenue' palette='3' showValues='0' numberPrefix='$' useRoundEdges='1'&gt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Create a SQLConnection object </span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>SqlConnection conn <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlConnection<span style="color: #008000;">&#40;</span>connStr<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Establish the connection with the database</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conn<span style="color: #008000;">.</span><span style="color: #0000FF;">Open</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Construct and execute SQL query which would return the total amount of sales for each year</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlCommand query <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SqlCommand<span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;SELECT SUM(FC_OrderDetails.UnitPrice * FC_OrderDetails.Quantity) AS AMOUNT, YEAR(FC_Orders.OrderDate) AS yr FROM FC_Orders INNER JOIN FC_OrderDetails ON FC_OrderDetails.OrderID = FC_Orders.OrderID GROUP BY YEAR(FC_Orders.OrderDate) ORDER BY YEAR(FC_Orders.OrderDate)&quot;</span>, conn<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Begin iterating through the result set</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlDataReader rst <span style="color: #008000;">=</span> query<span style="color: #008000;">.</span><span style="color: #0000FF;">ExecuteReader</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">while</span> <span style="color: #008000;">&#40;</span>rst<span style="color: #008000;">.</span><span style="color: #0000FF;">Read</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Construct the chart data in XML format</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlStr<span style="color: #008000;">.</span><span style="color: #0000FF;">AppendFormat</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;set label='{0}' value='{1}'/&gt;&quot;</span>, rst<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;yr&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, rst<span style="color: #008000;">&#91;</span><span style="color: #666666;">&quot;AMOUNT&quot;</span><span style="color: #008000;">&#93;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// End the XML string</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xmlStr<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;&lt;/chart&gt;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Close the result set Reader object and the Connection object</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rst<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; conn<span style="color: #008000;">.</span><span style="color: #0000FF;">Close</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// This page should return only XML content</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response<span style="color: #008000;">.</span><span style="color: #0000FF;">ContentType</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;text/xml&quot;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response<span style="color: #008000;">.</span><span style="color: #0000FF;">Write</span><span style="color: #008000;">&#40;</span>xmlStr<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> <span style="color: #008000;">&#125;</span></div></div><div class="code-holder-bottom"></div></div><p>This completes the code for <code class="codecolorer csharp default"><span class="csharp">DataProvider<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span></span></code>. Run this page, and all you will see is the chart data in XML format:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container xml default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart</span> <span style="color: #000066;">caption</span>=<span style="color: #ff0000;">&quot;Total Revenue&quot;</span> <span style="color: #000066;">palette</span>=<span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">showValues</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">numberPrefix</span>=<span style="color: #ff0000;">&quot;$&quot;</span> <span style="color: #000066;">useRoundEdges</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br /> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;1994&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;175345.1000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;1995&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;631865.8900&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;1996&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;547247.6000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div><div class="code-holder-bottom"></div></div><p>Coming back to <code class="codecolorer csharp default"><span class="csharp">Using_MS_SQL_Server<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span><span style="color: #008000;">.</span><span style="color: #0000FF;">cs</span></span></code>, modify the <code class="codecolorer csharp default"><span class="csharp">RenderChart<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></span></code> method to use Data URL:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container csharp default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span><br /> <span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">InfoSoftGlobal</span><span style="color: #008000;">;</span><br /> <br /> <br /> <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> Using_MS_SQL_Server <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span><span style="color: #008000;">.</span><span style="color: #0000FF;">UI</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Page</span><br /> <span style="color: #008000;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">protected</span> <span style="color: #6666cc; font-weight: bold;">void</span> Page_Load<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span><br /> &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Call the RenderChart method, pass the correct parameters, and write the return value to the Literal tag</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; chart_from_db<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> FusionCharts<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderChart</span><span style="color: #008000;">&#40;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">&quot;FusionChartsXT/Column2D.swf&quot;</span>, <span style="color: #008080; font-style: italic;">// Path to chart's SWF</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Server<span style="color: #008000;">.</span><span style="color: #0000FF;">UrlEncode</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;DataProvider.aspx&quot;</span><span style="color: #008000;">&#41;</span>, <span style="color: #008080; font-style: italic;">// Page which returns chart data</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">&quot;&quot;</span>, &nbsp;<span style="color: #008080; font-style: italic;">// String containing the chart data. Leave blank when using Data URL.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">&quot;annual_revenue&quot;</span>, &nbsp; <span style="color: #008080; font-style: italic;">// Unique chart ID</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666;">&quot;640&quot;</span>, <span style="color: #666666;">&quot;340&quot;</span>, &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Width &amp; Height of chart</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">false</span>, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Disable Debug Mode</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-style: italic;">// Register with JavaScript object</span><br /> &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br /> <span style="color: #008000;">&#125;</span></div></div><div class="code-holder-bottom"></div></div><p>We use the <code class="codecolorer csharp default"><span class="csharp">Server<span style="color: #008000;">.</span><span style="color: #0000FF;">UrlEncode</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></span></code> method to take care of any special characters in the URL / querystring.<br /> Save and run this page. You should see the same chart as before:</p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='annual_revenue_3';var myChartSWF='/Assets/fusioncharts/Column2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData('<chart caption="Total Revenue" palette="3" showValues="0" numberPrefix="$" useRoundEdges="1"><set label="1994" value="175345.1000"/><set label="1995" value="631865.8900"/><set label="1996" value="547247.6000"/></chart>');chartObj.render(myChartId+'container');/*]]>*/</script></p><p>The data for this chart is provided by <code class="codecolorer csharp default"><span class="csharp">DataProvider<span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span><span style="color: #008000;">.</span><span style="color: #0000FF;">cs</span></span></code>. You can see this by opening the <em>Network</em> tab in either Firebug or Chrome&#8217;s Developer Tools.</p><h2>Download Source Project</h2><p><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionChartsXT_with_ASPNET2.zip"><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/03/Download_Sample_Code5.png" alt="" title="Download Source Project" width="257" height="100" class="aligncenter size-full wp-image-2718" /></a></p><h2>Next in the series: Creating Drill-down JavaScript charts with ASP.NET(C#)</h2><p>In the third part of this series, we will add drill-down functionality to the above chart, so that we can drill-down into the year 1995 and see monthly revenue for that year. You can <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/csnet/CS_Drill.html" target="_blank">read more about drill-down charts in the FusionCharts Documentation</a>. Stay tuned..</p><div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1'>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2'>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/' rel='bookmark' title='Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3'>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://blog.fusioncharts.com/2012/03/javascript-charts-using-sql-server-data-with-fusioncharts-xt-part-2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</title><link>http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/</link> <comments>http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/#comments</comments> <pubDate>Thu, 29 Mar 2012 13:55:34 +0000</pubDate> <dc:creator>Hrishikesh Choudhari</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[asp.net]]></category> <category><![CDATA[javascript]]></category><guid isPermaLink="false">http://blog.fusioncharts.com/?p=2654</guid> <description><![CDATA[<em>FusionCharts XT with ASP.NET</em> is a new series where we walk you through the basics of creating interactive JavaScript charts, using your .NET skills. <a href="http://www.fusioncharts.com/products/suite/" target="_blank">FusionCharts Suite</a> is the leading enterprise-grade JavaScript charting solution. Our <a href="http://www.fusioncharts.com/success-stories/customers/" target="_blank">enterprise customers</a> have vouched for our products and support, and we keep adding <a href="http://www.fusioncharts.com/products/suite/fusionwidgets-xt/" target="_blank">newer products</a> and <a href="http://www.fusioncharts.com/demos/features/" target="_blank">features</a> to our solution. Be it a simple column or pie chart<div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-sql-server-data-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts using SQL Server data with FusionCharts XT &#8211; Part 2'>JavaScript charts using SQL Server data with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2'>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/' rel='bookmark' title='Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3'>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p></p><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/" title="Link to JavaScript charts with ASP.NET (C#) using FusionCharts XT - Part 1"><img class="wppt_float_left" src="http://blog.fusioncharts.com/wp-post-thumbnail/F0WGZ7.png" alt="" title="" width="88" height="88" /></a><p><em>FusionCharts XT with ASP.NET</em> is a new series where we walk you through the basics of creating interactive JavaScript charts, using your .NET skills. <a href="http://www.fusioncharts.com/products/suite/" target="_blank">FusionCharts Suite</a> is the leading enterprise-grade JavaScript charting solution. Our <a href="http://www.fusioncharts.com/success-stories/customers/" target="_blank">enterprise customers</a> have vouched for our products and support, and we keep adding <a href="http://www.fusioncharts.com/products/suite/fusionwidgets-xt/" target="_blank">newer products</a> and <a href="http://www.fusioncharts.com/demos/features/" target="_blank">features</a> to our solution. Be it a simple column or pie chart, gauges, advanced zoom and scroll charts, or specialized financial charts, FusionCharts Suite covers all your charting requirements. All the charts support interactive options like tooltips, drill-down, exporting as image, PDF, or CSV. We&#8217;re <a href="http://blog.fusioncharts.com/2012/02/create-charts-for-iphone-and-ipad-apps-using-fusioncharts-xt/" target="_blank">iPhone and iPad ready</a>, too!</p><p>With FusionCharts XT, you can leverage your .NET skills to create JavaScript charts. We provide a <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/csnet/CS_BasicExample.html" target="_blank">.NET library</a> which generates all the HTML and JavaScript required to create charts.<br /> <span id="more-2654"></span></p><blockquote><h3>FusionCharts XT with ASP.NET</h3><ul><li><a href="#">Part 1 &#8211; Create JavaScript charts in ASP.NET (C#)</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-using-sql-server-data-with-fusioncharts-xt-part-2/" target="_blank">Part 2 &#8211; Plot JavaScript charts using SQL Server data</a></li><li>Part 3 &#8211; Create Drill-Down &#038; LinkedCharts in ASP.NET(C#)</li></ul></blockquote><h2>What we are going to visualize</h2><p>The chart below shows data of Top 5 Employees of a fictitious company.<br /><script type="text/javascript" src="/Assets/fusioncharts/js/FusionCharts.js"></script></p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='browser_share';var myChartSWF='/Assets/fusioncharts/Column2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData('<chart caption="Top 5 Employees for 2011" palette="3" showValues="0" numberPrefix="$" useRoundEdges="1"><set label="Leverling" value="100524"/><set label="Fuller" value="87790"/><set label="Davolio" value="81898"/><set label="Peacock" value="76438"/><set label="Callahan" value="55091"/></chart>');chartObj.render(myChartId+'container');/*]]>*/</script></p><p>In this tutorial, we will create the same chart using the .NET library.</p><h2>.NET library bundled with FusionCharts XT</h2><p>FusionCharts XT is essentially a JavaScript library. In order to render a chart, certain amount of HTML and JavaScript is required, along with the chart data in <a href="http://docs.fusioncharts.com/charts/contents/?DataFormats/XML/Overview.html" target="_blank">XML</a> or <a href="http://docs.fusioncharts.com/charts/contents/?DataFormats/JSON/Overview.html" target="_blank">JSON</a>.</p><p>In order to automate this, we provide a .NET library with FusionCharts XT, which generates the HTML and JavaScript required. You can find this library in <code class="codecolorer xml default"><span class="xml">FusionCharts XT Download Package &gt; Code &gt; CS &gt; Bin &gt; FusionCharts.dll</span></code>. By referencing this library, rendering charts is just one line of code! Let us see how..</p><h2>What we will need</h2><ul><li>Visual Studio or Visual Web Developer</li><li><a href="http://www.fusioncharts.com/download/trials/" target="_blank">The latest version of FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/Data.zip">Sample chart data</a></li></ul><h2>Preparing the project</h2><p>We will be using Visual Studio 2010 for this series. Visual Studio 2008 or Visual Web Developer will suit fine too.</p><ul><li>Create a blank ASP.NET (C#) web site and save it as <code class="codecolorer csharp default"><span class="csharp">FusionChartsXT_with_ASPNET</span></code>.</li><li>Right-click the project&#8217;s name in <code class="codecolorer xml default"><span class="xml">Solution Explorer &gt; Add New Item &gt; Web Form</span></code>. Keep the name as <code class="codecolorer csharp default"><span class="csharp"><span style="color: #0600FF; font-weight: bold;">Default</span><span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span></span></code>.</li><li>Copy the <code class="codecolorer csharp default"><span class="csharp">Charts</span></code> folder from the FusionCharts Download Package and paste it in the Solution Explorer.</li><li>Include the FusionCharts XT&#8217;s JavaScript file in <code class="codecolorer csharp default"><span class="csharp"><span style="color: #0600FF; font-weight: bold;">Default</span><span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span></span></code>:<div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container html4strict default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Charts/FusionCharts.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></div></div><div class="code-holder-bottom"></div></div></li><li>Copy the Sample Data folder and paste it in the Solution Explorer.</li><li>Right-click the project&#8217;s name in <code class="codecolorer xml default"><span class="xml">Solution Explorer &gt; Add Reference &gt; Browse</span></code>. Now browse to <code class="codecolorer xml default"><span class="xml">FusionCharts XT Download Package &gt; Code &gt; CS &gt; Bin &gt; FusionCharts.dll</span></code>.</li><li>In <code class="codecolorer csharp default"><span class="csharp"><span style="color: #0600FF; font-weight: bold;">Default</span><span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span><span style="color: #008000;">.</span><span style="color: #0000FF;">cs</span></span></code>, include the namespace of this library by writing<div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container csharp default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">InfoSoftGlobal</span><span style="color: #008000;">;</span></div></div><div class="code-holder-bottom"></div></div></li></ul><p>The above steps are necessary whenever you want to use FusionCharts XT in a .NET project.</p><p>Next, there are 2 ways by which you can supply data to your charts &#8211; the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataURL.html" target="_blank">Data URL method</a> and the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataXMLExp.html" target="_blank">Data String method</a>. Let us try each one of them.</p><h2>Creating a JavaScript chart using Data URL method</h2><p>In the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataURL.html" target="_blank">Data URL method</a>, you tell FusionCharts XT to load data from an XML or JSON file URL. This URL could also point to a virtual data provider, e.g., <code class="codecolorer html4strict default"><span class="html4strict">/path_to/data_provider.aspx</span></code>, which will execute queries on the database, construct the XML data and output it to the stream, with content type set to <code class="codecolorer html4strict default"><span class="html4strict">text/xml</span></code>. For this example, we will point FusionCharts XT to an XML file’s URL.</p><p>Create a <code class="codecolorer csharp default"><span class="csharp">Literal</span></code> tag in Default.aspx, and give it a unique ID.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container csharp default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Literal ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;literal_1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span><br /> <span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Literal<span style="color: #008000;">&gt;</span></div></div><div class="code-holder-bottom"></div></div><p>We will write the code required to generate a chart to this literal. Then, <code class="codecolorer html4strict default"><span class="html4strict">FusionCharts.js</span></code> would process this code and show a chart instead.</p><p>In <code class="codecolorer csharp default"><span class="csharp"><span style="color: #0600FF; font-weight: bold;">Default</span><span style="color: #008000;">.</span><span style="color: #0000FF;">aspx</span><span style="color: #008000;">.</span><span style="color: #0000FF;">cs</span></span></code>, within the <code class="codecolorer csharp default"><span class="csharp">Page_Load</span></code> method, write the following code:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container csharp default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">// Set the rendering mode to &quot;javascript&quot;. (Default is &quot;flash&quot;)</span><br /> FusionCharts<span style="color: #008000;">.</span><span style="color: #0000FF;">SetRenderer</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;javascript&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> <br /> literal_1<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> FusionCharts<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderChart</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FusionChartsXT/Column2D.swf&quot;</span>, <span style="color: #666666;">&quot;Data/Data.xml&quot;</span>, <span style="color: #666666;">&quot;&quot;</span>, <span style="color: #666666;">&quot;browser_share&quot;</span>, <span style="color: #666666;">&quot;640&quot;</span>, <span style="color: #666666;">&quot;340&quot;</span>, <span style="color: #0600FF; font-weight: bold;">false</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div><div class="code-holder-bottom"></div></div><p>Save. Run the project (F5). This is the chart that you should see:</p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='browser_share_2';var myChartSWF='/Assets/fusioncharts/Column2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData('<chart caption="Top 5 Employees for 2011" palette="3" showValues="0" numberPrefix="$" useRoundEdges="1"><set label="Leverling" value="100524"/><set label="Fuller" value="87790"/><set label="Davolio" value="81898"/><set label="Peacock" value="76438"/><set label="Callahan" value="55091"/></chart>');chartObj.render(myChartId+'container');/*]]>*/</script></p><p>You were able to render a chart in your .NET app with just one single line!</p><h2>Understanding the RenderChart() method</h2><p>The RenderChart() method does all the heavy lifting of generating HTML and JavaScript required to render a chart in the browser. It takes parameters in the following order:</p><ul><li><strong>Chart SWF name</strong>: The first parameter contains the Path and file name of the chart SWF file. We have to use the relative path to SWF file, which is recommended. When plotting charts in JavaScript, FusionCharts XT uses the SWF name to internally map to the chart’s JavaScript alias.</li><li><strong>URL to static XML file</strong>: If Data URL method is to be used. If you intend to use Data String method, leave this as blank.</li><li><strong>Variable containing XML data string</strong>: If Data String method is to be used. If you have specified data as a URL, leave this parameter as blank.</li><li><strong>ID of the chart</strong>: Each chart on the page needs a unique ID. This ID is different from the ID of the container DIV. As we will learn later, this ID is used to get a reference to the chart for manipulation using advanced JavaScript.</li><li><strong>Width and height in pixels</strong>: Each chart needs to be initialized with width and height, specified either in pixels (specified in numeric format, without appending px) or percentage. In this example, we have used pixels. You can also set it to percentage values. The FusionCharts JavaScript class will automatically convert the percentage dimensions to pixel dimensions, with respect to the parent container element in HTML, DIV in this case, and pass it to the chart.</li><li><strong>Boolean for Debug Mode</strong>: If you’re facing any issues while developing your charts, you can initialize them in debug mode by setting this parameter to true. The debug mode gives you behind-the-scenes information on where data is loaded from, errors etc. In our example, we are rendering the chart in normal mode, by setting this parameter to false.</li><li><strong>Boolean for Registering with JavaScript</strong>: In earlier versions of FusionCharts, the last parameter let you configure whether charts could be controlled using JavaScript. Now that FusionCharts is very tightly integrated with FusionCharts, this parameter is a mandatory true.</li></ul><h2>Creating a JavaScript chart using Data String method</h2><p>In the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataXMLExp.html" target="_blank">Data String method</a>, the XML or JSON data is embedded within the web page, along with the chart’s HTML and JavaScript code. This method doesn’t require a static data file or a virtual data provider. Moreover, once the chart has finished loading, the data is present locally within the page.</p><p>Let us create a chart using the Data String method below the first chart.</p><p>Create another <code class="codecolorer csharp default"><span class="csharp">Literal</span></code> tag with ID as <code class="codecolorer csharp default"><span class="csharp">literal_2</span></code>. In the code-behind, comment the line of the <code class="codecolorer csharp default"><span class="csharp">RenderChart<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></span></code> method, and write the following code after it:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container csharp default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-style: italic;">// xmlStr contains the XML data required for the chart</span><br /> <span style="color: #6666cc; font-weight: bold;">String</span> xmlStr <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&lt;chart caption='Top 5 Employees for 2011' palette='3' showValues='0' numberPrefix='$' useRoundEdges='1'&gt;&lt;set label='Leverling' value='100524'/&gt;&lt;set label='Fuller' value='87790'/&gt;&lt;set label='Davolio' value='81898'/&gt;&lt;set label='Peacock' value='76438'/&gt;&lt;set label='Callahan' value='55091'/&gt;&lt;/chart&gt;&quot;</span><span style="color: #008000;">;</span><br /> <br /> <span style="color: #008080; font-style: italic;">// Set rendering mode to &quot;javascript&quot;. &nbsp; &nbsp; &nbsp; &nbsp; </span><br /> FusionCharts<span style="color: #008000;">.</span><span style="color: #0000FF;">SetRenderer</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;javascript&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> literal_2<span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> FusionCharts<span style="color: #008000;">.</span><span style="color: #0000FF;">RenderChart</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;FusionChartsXT/Column2D.swf&quot;</span>, <span style="color: #666666;">&quot;&quot;</span>, xmlStr, <span style="color: #666666;">&quot;browser_share_2&quot;</span>, <span style="color: #666666;">&quot;640&quot;</span>, <span style="color: #666666;">&quot;340&quot;</span>, <span style="color: #0600FF; font-weight: bold;">false</span>, <span style="color: #0600FF; font-weight: bold;">true</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div><div class="code-holder-bottom"></div></div><p>Save. Run the project (F5). You should see the following chart:</p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='browser_share_3';var myChartSWF='/Assets/fusioncharts/Column2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData('<chart caption="Top 5 Employees for 2011" palette="3" showValues="0" numberPrefix="$" useRoundEdges="1"><set label="Leverling" value="100524"/><set label="Fuller" value="87790"/><set label="Davolio" value="81898"/><set label="Peacock" value="76438"/><set label="Callahan" value="55091"/></chart>');chartObj.render(myChartId+'container');/*]]>*/</script></p><h2>Providing chart data in JSON</h2><p><a href="http://docs.fusioncharts.com/charts/contents/?DataFormats/JSON/Overview.html" target="_blank">JSON</a> is another format that FusionCharts XT supports. If you want to provide data in JSON, simply write the following line before the <code class="codecolorer csharp default"><span class="csharp">RenderChart<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span></span></code> method:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container csharp default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">FusionCharts<span style="color: #008000;">.</span><span style="color: #0000FF;">SetDataFormat</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;json&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div><div class="code-holder-bottom"></div></div><p>We provide a tool to convert XML to JSON. You can find it in <code class="codecolorer xml default"><span class="xml">FusionCharts XT Download Package &gt; Tools &gt; FCDataConverter</span></code>. The JSON data for the above chart is:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container javascript default" style="border:1px solid #9F9F9F;width:435px;height:300px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span><br /> &nbsp; <span style="color: #3366CC;">&quot;chart&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;caption&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Top 5 Employees for 2011&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;palette&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;3&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;showvalues&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;numberprefix&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;$&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;useroundedges&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1&quot;</span><br /> &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; <span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Leverling&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;100524&quot;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Fuller&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;87790&quot;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Davolio&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;81898&quot;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Peacock&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;76438&quot;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Callahan&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;55091&quot;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> &nbsp; <span style="color: #009900;">&#93;</span><br /> <span style="color: #009900;">&#125;</span></div></div><div class="code-holder-bottom"></div></div><h2>Download the project source</h2><p><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionChartsXT_with_ASPNET.zip"><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/03/Download_Sample_Code4.png" alt="" title="Download Source Project " width="257" height="100" class="aligncenter size-full wp-image-2680" /></a></p><h2>Next article in this series: Create a chart using data from SQL Server</h2><p>In the next article, we will create a chart using data from a database. You can head over to our <a href="http://docs.fusioncharts.com/charts/" target="_blank">documentation</a> and read on how to <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/csnet/CS_DB.html" target="_blank">use FusionCharts XT to create charts using data from SQL Server</a>. Stay tuned.</p><div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-sql-server-data-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts using SQL Server data with FusionCharts XT &#8211; Part 2'>JavaScript charts using SQL Server data with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2'>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/' rel='bookmark' title='Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3'>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</title><link>http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/</link> <comments>http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/#comments</comments> <pubDate>Wed, 21 Mar 2012 12:04:42 +0000</pubDate> <dc:creator>Hrishikesh Choudhari</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[debugging]]></category> <category><![CDATA[errors]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[tips]]></category><guid isPermaLink="false">http://blog.fusioncharts.com/?p=2625</guid> <description><![CDATA[In the 5th and final part of the FusionCharts XT in PHP series, we will learn how to debug our charts. Debugging helps us know what happens behind the scenes while rendering a chart. With the FusionCharts JavaScript Debug Mode, we can generate a complete log of the internal events, as well as any errors that crop up. Since the JavaScript charts are rendered only by the browser, the debug]]></description> <content:encoded><![CDATA[<p></p><a href="http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/" title="Link to Debugging JavaScript charts with FusionCharts XT - Part 5"><img class="wppt_float_left" src="http://blog.fusioncharts.com/wp-post-thumbnail/hymySm.png" alt="" title="" width="88" height="88" /></a><p>In the 5th and final part of the FusionCharts XT in PHP series, we will learn how to debug our charts. Debugging helps us know what happens behind the scenes while rendering a chart. With the FusionCharts JavaScript Debug Mode, we can generate a complete log of the internal events, as well as any errors that crop up. Since the JavaScript charts are rendered only by the browser, the debug logs will be available in the browser&#8217;s Console Log. Let us begin debugging!<br /> <span id="more-2625"></span></p><blockquote><h3>FusionCharts XT in PHP Series</h3><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/" target="_blank">Part 1 &#8211; JavaScript charts in PHP using FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/" target="_blank">Part 2 &#8211; JavaScript charts in PHP and MySQL using FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/" target="_blank">Part 3 &#8211; Drill-down JavaScript charts in PHP and MySQL</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/" target="_blank">Part 4 &#8211; JavaScript LinkedCharts in PHP and MySQL</a></li><li><a href="http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/">Part 5 &#8211; Using Debugging Tools for JavaScript Charts</a></li></blockquote><p>We will understand the debugging process in three sections:</p><h2>Understanding Debug Messages</h2><p>To aid you in basic debugging, the charts show <a href="http://docs.fusioncharts.com/charts/contents/?Debug/Basic.html" target="_blank">certain messages when something goes wrong</a>. These messages will show up in place of the chart:</p><ul><li><strong>Error in Loading Data</strong>:<ul><li>Check if you&#8217;ve actually provided <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataURL.html" target="_blank">Data URL</a> or <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataXMLExp.html" target="_blank">Data String</a>.  If you do not provide either, FusionCharts looks for a default Data.xml file in the same path. Now, if that is also not found, it shows the &#8220;Error in Loading Data&#8221; error.</li><li>If you&#8217;re using Data URL method, paste this URL in your browser to check if it&#8217;s returning a valid XML. Make sure, there are no scripting or time-out errors and a valid XML is being returned. Also make sure that the XML isn&#8217;t intermingled with HTML content. The data provider page should return a clean XML only &#8211; not even HTML <code class="codecolorer html4strict default"><span class="html4strict"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span></span></code> or <code class="codecolorer html4strict default"><span class="html4strict"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span></span></code> tags.</li><li>Make sure you&#8217;re passing relative URLs for Data URL, and not absolute URLs.</li></ul></li><li><strong>Invalid XML Data</strong>:<br /> If you get an <code class="codecolorer html4strict default"><span class="html4strict">Invalid XML Data</span></code> message, it means that the XML data document is malformed. Check it for common errors like:</p><ul><li>Differences in case of tags. e.g., <code class="codecolorer xml default"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> should end with [cciel lang='xml']<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></span></code> and not <code class="codecolorer xml default"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></span></code> or <code class="codecolorer xml default"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/CHART<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></span></code></li><li>Missing opening/closing quotation marks for any attributes. e.g., <code class="codecolorer xml default"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart</span> <span style="color: #000066;">caption</span>=Monthly Sales<span style="color: #ff0000;">' ..&gt;</span></span></span></code> should be <code class="codecolorer xml default"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart</span> <span style="color: #000066;">caption</span>=<span style="color: #ff0000;">'Monthly Sales'</span> ..<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></code></li><li>Missing closing tag for any element. e.g., <code class="codecolorer xml default"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Services'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'26'</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span></span></code> should be <code class="codecolorer xml default"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Services'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'26'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></span></code></li><li>In Data String method, check for conflict of <code class="codecolorer xml default"><span class="xml">'</span></code> (XML Attribute Character) and <code class="codecolorer xml default"><span class="xml">&quot;</span></code> (HTML Parameter Character). e.g., if you&#8217;re using direct HTML embedding method, and using <code class="codecolorer xml default"><span class="xml">&quot;</span></code> for HTML parameters, then you need to make sure that all your XML attributes use <code class="codecolorer xml default"><span class="xml">'</span></code> as containers.</li><li>If you&#8217;ve quotes as part of your data, XML Encode them to <code class="codecolorer xml default"><span class="xml"><span style="color: #ddbb00;">&amp;apos;</span></span></code> e.g., <code class="codecolorer xml default"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'John&amp;apos;s House'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></span></code></li></ul></li><li><strong>No data to display</strong>:<ul><li>Your XML data doesn&#8217;t contain any data that could be plotted by FusionCharts. In this case, your XML just contains the <code class="codecolorer xml default"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></span></code> or <code class="codecolorer xml default"><span class="xml"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dataset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></span></code> tags without any data between them.</li><li>You might be using a single-series chart SWF and providing data in multi-series format or vice-versa.</li><li>In some Dual Y Combination charts, you need to provide at least one dataset for both the axis.</li></ul></li></ul><h2>FusionCharts XT JavaScript Debug Mode</h2><p>The <a href="http://docs.fusioncharts.com/charts/contents/?Debug/JS.html" target="_blank">FusionCharts XT JavaScript Debug Mode</a> provides a very developer-friendly way of debugging the charts.<br /> It enables you to log <em>all</em> the events that take place in the lifetime of a chart. All you need to write is:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container javascript default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span><br /> FusionCharts.<span style="color: #660066;">debugMode</span>.<span style="color: #660066;">enabled</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></div></div><div class="code-holder-bottom"></div></div><p>However, with the above line alone you will not be able to see any logs. To see the output, log it to the browser&#8217;s console by adding the following line:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container javascript default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">FusionCharts.<span style="color: #660066;">debugMode</span>.<span style="color: #660066;">outputTo</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><div class="code-holder-bottom"></div></div><p>You should see the following events being logged in the browser&#8217;s console:<br /> <a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionCharts_XT_JavaScript_Debug.png" rel="wp-prettyPhoto[g2625]"><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionCharts_XT_JavaScript_Debug.png" alt="FusionCharts XT JavaScript Debug" title="FusionCharts XT JavaScript Debug" width="663" height="266" class="aligncenter size-full wp-image-2630" /></a></p><p>If you are using Firebug, or Chrome&#8217;s Developer Tools, you can explore the object hierarchy by setting the output format to verbose:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container javascript default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">FusionCharts.<span style="color: #660066;">debugMode</span>.<span style="color: #660066;">outputFormat</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'verbose'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><div class="code-holder-bottom"></div></div><p><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionCharts-XT-JavaScript-Debugging-Verbose-Log.png" rel="wp-prettyPhoto[g2625]"><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionCharts-XT-JavaScript-Debugging-Verbose-Log.png" alt="FusionCharts XT JavaScript Debugging Verbose Log" title="FusionCharts XT JavaScript Debugging Verbose Log" width="663" height="332" class="aligncenter size-full wp-image-2631" /></a><br /> Being good (read lazy) developers ourselves, we write the above 3 lines in a more compact fashion:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container javascript default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">FusionCharts.<span style="color: #660066;">debugMode</span>.<span style="color: #660066;">enabled</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'verbose'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><div class="code-holder-bottom"></div></div><p>And for the rare bug-hunting session when you don&#8217;t have Firebug installed, you can include Firebug-Lite remotely:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container javascript default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">FusionCharts.<span style="color: #660066;">debugMode</span>._enableFirebugLite<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><div class="code-holder-bottom"></div></div><h2>Using Advanced Error and Warning Events</h2><p>The FusionCharts XT JavaScript Class fires events at every stage during the lifetime of a chart. You can listen for the events that fire upon errors in the chart. You can either listen to these events globally, or on a per-chart basis as shown below:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container javascript default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> myChartListener<span style="color: #009900;">&#40;</span>eventObject<span style="color: #339933;">,</span> argumentsObject<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> eventObject.<span style="color: #660066;">sender</span>.<span style="color: #660066;">id</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; has an error: &quot;</span> <span style="color: #339933;">+</span> argumentsObject.<span style="color: #660066;">message</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <span style="color: #009900;">&#125;</span><br /> FusionCharts<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;chart_id&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addEventListener</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Error&quot;</span> <span style="color: #339933;">,</span> myChartListener <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><div class="code-holder-bottom"></div></div><p>The first argument is eventObject which provides details of the event. It is an object which mainly provides three properties :<br /> <code class="codecolorer javascript default"><span class="javascript">eventId</span></code> : An unique ID given to the event<br /> <code class="codecolorer javascript default"><span class="javascript">eventType</span></code> : A string containing the name or the event type, for example, &#8220;rendered&#8221; etc.<br /> <code class="codecolorer javascript default"><span class="javascript">sender</span></code> : A FusionCharts JavaScript Object reference to the chart which has raised that event<br /> The second argument is <code class="codecolorer javascript default"><span class="javascript">argumentsObject</span></code> is an object and contains details of the event. As per the type of the event the properties of parameter objects varies.</p><p>You can read more about <a href="http://docs.fusioncharts.com/charts/contents/?JavaScript/JS_EventOverview.html" target="_blank">Listening to Events in the FusionCharts XT Documentation</a>.</p><h2>Concluding the series</h2><p>We&#8217;ve covered a lot of ground in this series. You can go back and read through the previous articles if you haven&#8217;t yet:</p><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/" target="_blank">Part 1 &#8211; JavaScript charts in PHP using FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/" target="_blank">Part 2 &#8211; JavaScript charts in PHP and MySQL using FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/" target="_blank">Part 3 &#8211; Drill-down JavaScript charts in PHP and MySQL</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/" target="_blank">Part 4 &#8211; JavaScript LinkedCharts in PHP and MySQL</a></li><p>Let us know in the comments how you liked this series. We&#8217;re putting out more interesting content for all you developers. Stay tuned..</p> ]]></content:encoded> <wfw:commentRss>http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>JavaScript LinkedCharts in PHP and MySQL using FusionCharts XT &#8211; Part 4</title><link>http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/</link> <comments>http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/#comments</comments> <pubDate>Tue, 20 Mar 2012 14:42:47 +0000</pubDate> <dc:creator>Hrishikesh Choudhari</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[drill down]]></category> <category><![CDATA[drilldown]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[linkedcharts]]></category> <category><![CDATA[php]]></category><guid isPermaLink="false">http://blog.fusioncharts.com/?p=2576</guid> <description><![CDATA[In the 4th part of FusionCharts XT in PHP series, we will create LinkedCharts in PHP. LinkedCharts is a pioneering concept introduced by FusionCharts which allows unlimited levels of drill-down. LinkedCharts help users maintain the context when drilling down (or up) in their data. The child LinkedCharts can be configured in every way possible. Let us create LinkedCharts using the bundled PHP script, which takes the hassle out by generating<div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/' rel='bookmark' title='Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3'>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2'>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1'>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p></p><a href="http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/" title="Link to JavaScript LinkedCharts in PHP and MySQL using FusionCharts XT - Part 4"><img class="wppt_float_left" src="http://blog.fusioncharts.com/wp-post-thumbnail/0Ux4ak.png" alt="" title="" width="88" height="88" /></a><p>In the 4th part of FusionCharts XT in PHP series, we will create LinkedCharts in PHP. LinkedCharts is a pioneering concept introduced by FusionCharts which allows unlimited levels of drill-down. LinkedCharts help users maintain the context when drilling down (or up) in their data. The child LinkedCharts can be configured in every way possible. Let us create LinkedCharts using the bundled PHP script, which takes the hassle out by generating the HTML, JavaScript and XML required to render any chart.<br /> <span id="more-2576"></span></p><blockquote><h3>FusionCharts XT in PHP Series</h3><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/" target="_blank">Part 1 &#8211; JavaScript charts in PHP using FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/" target="_blank">Part 2 &#8211; JavaScript charts in PHP and MySQL using FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/" target="_blank">Part 3 &#8211; Drill-down JavaScript charts in PHP and MySQL</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/">Part 4 &#8211; JavaScript LinkedCharts in PHP and MySQL</a></li><li><a href="http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/" target="_blank">Part 5 &#8211; Using Debugging Tools for JavaScript Charts</a></li></blockquote><h2>What we are going to visualize</h2><p>In the <a href="http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3" target="_blank">3rd part</a> of this series, we created a simple drill-down chart, where the parent chart shows the Top 10 Most Populous Countries, and the child chart shows the Top 10 Most Populous Cities of that country.</p><p>We will make use of the same data and create a LinkedChart as shown below:<br /> <iframe src="http://www.screenr.com/embed/vZB8" width="650" height="396" frameborder="0"></iframe></p><p>LinkedCharts provides a convenient way to navigate through the levels using the <code class="codecolorer xml default"><span class="xml">overlay button</span></code>. This helps immensely in maintaining context while traversing the data. There are a few more implementations of <a href="www.fusioncharts.com/demos/features/#linkedcharts-for-easy-drill-down" target="_blank">LinkedCharts in our Features Gallery</a>.</p><h2>What we will need</h2><ul><li>PHP running on any server</li><li>MySQL</li><li><a href="http://www.fusioncharts.com/download/trials/" target="_blank">The latest version of FusionCharts XT</a></li><li>The <a href="http://downloads.mysql.com/docs/world.sql.zip" target="_blank">sample World database provided by MySQL</a>. <a href="http://dev.mysql.com/doc/world-setup/en/world-setup.html" target="_blank">Read more</a> to understand the structure of this database and how to set it up.</li><li><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionCharts_XT_with_PHP_MySQL.zip">The source code for the 2nd part of the series</a></li></ul><p>Our installation process will be the same as we did in the previous article. You may use the same setup or create it as follows:</p><ol><li>Within the root directory of your web server, create a folder named <code class="codecolorer php default"><span class="php">FusionCharts_XT_with_PHP</span></code>. This will be our demo folder.</li><li>Copy the entire <code class="codecolorer php default"><span class="php">Charts</span></code> folder from the FusionCharts XT Download Package and paste it within our demo folder. This completes the installation of FusionCharts XT in our web application.</li><li>Copy the <code class="codecolorer php default"><span class="php">Includes</span></code> folder from <code class="codecolorer php default"><span class="php">FusionCharts XT Download Package <span style="color: #339933;">&gt;</span> Code <span style="color: #339933;">&gt;</span> PHP <span style="color: #339933;">&gt;</span> Includes</span></code> to our demo folder.</li><li>Copy the source files used in the previous article and paste them in our demo folder</li></ol><h2>Attributes of LinkedCharts</h2><p>When creating LinkedCharts, you will have to provide the data for the child charts in either Data URL or Data String formats using the <code class="codecolorer xml default"><span class="xml">link</span></code> attribute.</p><li><h3>LinkedCharts using Data URL</h3></li><p>In the Data URL method, we can point to a static XML file which provides the data for this particular child. The syntax for Data URL method is:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container xml default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'your_label'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'your_value'</span> <span style="color: #000066;">link</span>=<span style="color: #ff0000;">'newchart-xmlurl-{xml file URL}'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div><div class="code-holder-bottom"></div></div><p>The <code class="codecolorer xml default"><span class="xml">newChart</span></code> prefix is used to indicate that it must invoke LinkedCharts. <code class="codecolorer xml default"><span class="xml">xmlURL</span></code> indicates that Data URL method is used to specify XML data for the linked child charts. In case of JSON data, <code class="codecolorer xml default"><span class="xml">jsonurl</span></code> is used. <code class="codecolorer xml default"><span class="xml">URL</span></code> specifies the data path for the linked chart that opens when this column is clicked.<br /> So according to the syntax, you would provide the child chart&#8217;s data in this way:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container xml default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'China'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'1277558000'</span> <span style="color: #000066;">link</span>=<span style="color: #ff0000;">'newchart-xmlurl-China.xml'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div><div class="code-holder-bottom"></div></div><p>We can also point to a virtual data provider, such as a server-side script which returns <em>only</em> XML, with Content-type set to text/xml:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container xml default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'China'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'1277558000'</span> <span style="color: #000066;">link</span>=<span style="color: #ff0000;">'newchart-xmlurl-LinkedCharts_DataProvider.php?country=China'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div><div class="code-holder-bottom"></div></div><li><h3>LinkedCharts using Data String</h3></li><p>When using the Data String method, the child chart&#8217;s data will have to be <em>within</em> the parent chart. Each data plot item in the parent chart is then linked to the child chart&#8217;s data (embedded in parent data source) by means of a unique data identifier. The syntax for Data String method is:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container xml default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'your_label'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'your_value'</span> <span style="color: #000066;">link</span>=<span style="color: #ff0000;">'newchart-xml-{linked-data-ID}'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkeddata</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">'your_id'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart</span> <span style="color: #000066;">caption</span>=<span style="color: #ff0000;">'Child chart'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {child chart data comes here}<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/linkeddata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div><div class="code-holder-bottom"></div></div><p>According to this syntax, this demo&#8217;s code would have to be:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container xml default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'China'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'1277558000'</span> <span style="color: #000066;">link</span>=<span style="color: #ff0000;">'newchart-xml-China'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkeddata</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">'China'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart</span> caption = <span style="color: #ff0000;">'Top 10 Most Populous Cities in China'</span> <span style="color: #000066;">showValues</span>=<span style="color: #ff0000;">'0'</span> <span style="color: #000066;">useRoundEdges</span>=<span style="color: #ff0000;">'1'</span> <span style="color: #000066;">palette</span>=<span style="color: #ff0000;">'3'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Shanghai'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'9696300'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Peking'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'7472000'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Chongqing'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'6351600'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Tianjin'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'5286800'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Wuhan'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'4344600'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Harbin'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'4289800'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Shenyang'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'4265200'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Kanton [Guangzhou]'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'4256300'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Chengdu'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'3361500'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'Nanking [Nanjing]'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'2870300'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/linkeddata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div><div class="code-holder-bottom"></div></div><li><h3>Data URL or Data String?</h3></li><p>As is apparent from the samples above, the Data URL method is more concise than the Data String method. If you have more than 1 level of drill-down, your XML string will get large, and consequently difficult to debug. Loading times for your charts might suffer too.<br /> Therefore, we recommend the Data URL method to keep your code cleaner, and charts leaner.</p><h2>Creating LinkedCharts using Data URL method</h2><p>As you already know from the first 3 articles, the Data URL method requires 3 things:</p><ol><li>The parent chart (which we created in the 2nd article)</li><li>The correct path to the data provider in the <code class="codecolorer xml default"><span class="xml">link</span></code> attribute (see below)</li><li>The data provider (see further below!)</li></ol><p>Make a copy of <code class="codecolorer xml default"><span class="xml">FusionChartsXT_with_PHP_and_MySQL_DataString.php</span></code> and save it as <code class="codecolorer php default"><span class="php">FusionChartsXT_LinkedCharts_DataURL<span style="color: #339933;">.</span>php</span></code>. Edit the part where you create the dataplots as below:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Append the names of the countries and their respective populations to the chart's XML string.</span><br /> <span style="color: #666666; font-style: italic;">// Provide the path to the data provider in the 'link' attribute, along with the country's name in the querystring.</span><br /> <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;set label='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' value='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Population'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' link='newchart-xmlurl-LinkedCharts_DataProvider.php?country=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span></div></div><div class="code-holder-bottom"></div></div><p>Save this file. Let us now create the PHP script which will provide the data for the child charts:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Set the content type in the header to text/xml.</span><br /> <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: text/xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Include the DBConn.php and FusionCharts.php files, so that we can access their variables and functions.</span><br /> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Includes/DBConn.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Includes/FusionCharts.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Retrieve the name of the country passed from the parent chart's querystring.</span><br /> <span style="color: #000088;">$countryName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Use the connectToDB() function provided in DBConn.php, and establish the connection between PHP and the World database in our MySQL setup.</span><br /> <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> connectToDB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Form the SQL query which returns the Top 10 Most Populous Cities of the specified country.</span><br /> <span style="color: #000088;">$strQuery_cities</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT city.Name AS City, city.Population AS Population FROM city WHERE city.CountryCode = (SELECT country.Code FROM country WHERE country.Name = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$countryName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;) ORDER BY Population DESC LIMIT 10'</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Execute the query, or else return the error message.</span><br /> <span style="color: #000088;">$result_cities</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$strQuery_cities</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Form the chart data's XML string.</span><br /> <span style="color: #000088;">$strXML</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;chart caption = 'Top 10 Most Populous Cities in &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$countryName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' showValues='0' useRoundEdges='1' palette='3'&gt;&quot;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ors_cities</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result_cities</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Iterate through the result set and append the data plots to the XML string.</span><br /> &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;set label='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors_cities</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'City'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' value='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors_cities</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Population'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span><br /> <span style="color: #009900;">&#125;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Close the chart's XML string.</span><br /> <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/chart&gt;&quot;</span><span style="color: #339933;">;</span>&nbsp; <br /> <br /> <span style="color: #666666; font-style: italic;">// Return the valid XML string.</span><br /> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$strXML</span><span style="color: #339933;">;</span><br /> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div><div class="code-holder-bottom"></div></div><p>Save this file as <code class="codecolorer php default"><span class="php">FusionChartsXT_LinkedCharts_DataProvider<span style="color: #339933;">.</span>php</span></code>. Now navigate to the page which has the <em>parent</em> chart, and click on one of the columns. This is what you should see:<br /> <iframe src="http://www.screenr.com/embed/vZB8" width="650" height="396" frameborder="0"></iframe></p><h2>Creating LinkedCharts using Data String method</h2><p>As we&#8217;ve seen above, when using the Data String method, the child charts&#8217; data needs to be embedded within the parent chart&#8217;s data.<br /> Therefore, we need to have a single file only. Make another copy of <code class="codecolorer xml default"><span class="xml">FusionChartsXT_with_PHP_and_MySQL_DataString.php</span></code> and save it as <code class="codecolorer php default"><span class="php">FusionChartsXT_LinkedCharts_DataString<span style="color: #339933;">.</span>php</span></code>.<br /> New code needs to the written only within the <code class="codecolorer php default"><span class="php"><span style="color: #b1b100;">while</span> loop</span></code>; but we&#8217;re showing the code for the entire file below:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> &nbsp; &nbsp; <br /> <span style="color: #666666; font-style: italic;">// Include the DBConn.php and FusionCharts.php files, so that we can access their variables and functions.</span><br /> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Includes/DBConn.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Includes/FusionCharts.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Use the connectToDB() function provided in DBConn.php, and establish the connection between PHP and the World database in our MySQL setup.</span><br /> <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> connectToDB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Form the SQL query which will return the Top 10 Most Populous Countries.</span><br /> <span style="color: #000088;">$strQuery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT Name AS Country, Population FROM country ORDER BY Population DESC LIMIT 10'</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Execute the query, or else return the error message.</span><br /> <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$strQuery</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// If we get a valid response - </span><br /> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create the parent chart's XML string. We can add attributes here to customize our chart.</span><br /> &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;chart caption='Top 10 Most Populous Countries' showValues='0' useRoundEdges='1' palette='3'&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ors</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Append the names of the countries and their respective populations to the chart's XML string.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Provide the appropriate ID for the LinkedChart in the 'link' attribute.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;set label='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' value='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Population'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' link='newchart-xml-&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Form the SQL query which returns the Top 10 Most Populous Cities for the specified country.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strQuery_cities</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT city.Name AS City, city.Population AS Population FROM city WHERE city.CountryCode = (SELECT country.Code FROM country WHERE country.Name = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;) ORDER BY Population DESC LIMIT 10'</span><span style="color: #339933;">;</span><br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Execute the query, or else return the error message.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$result_cities</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$strQuery_cities</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Add the unique identifier for this particular child chart.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;linkeddata id='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create the child chart's XML. This chart can have all the attributes as any other regular chart.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;chart caption = 'Top 10 Most Populous Cities in &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' showValues='0' useRoundEdges='1' palette='3'&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ors_cities</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result_cities</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Append the names of the cities and their respective populations to the child chart's XML string.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;set label='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors_cities</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'City'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' value='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors_cities</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Population'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Close the child chart's XML string, and also close the unique identifier for this child chart.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/chart&gt;&lt;/linkeddata&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> <span style="color: #009900;">&#125;</span> &nbsp; <br /> <span style="color: #666666; font-style: italic;">// Close the parent chart's XML string.</span><br /> <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/chart&gt;&quot;</span><span style="color: #339933;">;</span>&nbsp; <br /> <span style="color: #000000; font-weight: bold;">?&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;<br /> &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br /> &lt;html&gt;<br /> &nbsp; &nbsp; &lt;head&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;title&gt;Drill-down charts using FusionCharts XT with PHP and MySQL&lt;/title&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- Include FusionCharts.js to provide client-side interactivity --&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;script type=&quot;text/javascript&quot; src=&quot;Charts/FusionCharts.js&quot;&gt;&lt;/script&gt;<br /> &nbsp; &nbsp; &lt;/head&gt;<br /> &nbsp; &nbsp; &lt;body&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- This DIV would be our chart container --&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;chartContainer&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the rendering mode to JavaScript</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FC_SetRenderer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'javascript'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Call the renderChart method, which would return the HTML and JavaScript required to generate the chart</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> renderChart<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Charts/Column2D.swf'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Path to chart type</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Empty string when using Data String method</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span><span style="color: #339933;">,</span><span style="color: #666666; font-style: italic;">// Variable which has the chart data</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'top10_most_populous_countries'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Unique chart ID</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'660'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'400'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Width and height in pixels</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>&nbsp; <span style="color: #666666; font-style: italic;">// Disable debug mode</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-weight: bold;">true</span>&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Enable 'Register with JavaScript' (Recommended)</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br /> &nbsp; &nbsp; &lt;/body&gt;<br /> &lt;/html&gt;</div></div><div class="code-holder-bottom"></div></div><p>Save this file. Navigate to this page using your browser, and this is what you should see:<br /> <iframe src="http://www.screenr.com/embed/vZB8" width="650" height="396" frameborder="0"></iframe></p><h2>Configuring LinkedCharts</h2><p>What we created above were <em>standard</em> LinkedCharts. The child charts used the same configuration and chart type as the parent chart.</p><p>Using the FusionCharts XT JavaScript API, you can configure every aspect of the child charts. For this, we&#8217;ve provided the <code class="codecolorer php default"><span class="php">configureLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> function. You can pass all the properties that a FusionCharts constructor accepts, as parameters to this function.</p><p>The syntax for the <code class="codecolorer php default"><span class="php">configureLink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> is:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">configureLink<span style="color: #009900;">&#40;</span>objConfiguration<span style="color: #339933;">:</span> Object<span style="color: #339933;">,</span> level<span style="color: #339933;">:</span>Number<span style="color: #009900;">&#41;</span></div></div><div class="code-holder-bottom"></div></div><p>As two separate parameters, the first parameter is an Object containing all configurations (chart and overlay-Button). The second parameter accepts a number which denotes the level being configured. The first drilldown level is 0 (zero).</p><p>Let us see how we can change the child chart we created above to a <code class="codecolorer xml default"><span class="xml">Area</span></code> chart. In <code class="codecolorer php default"><span class="php">FusionChartsXT_DrillDown_DataString<span style="color: #339933;">.</span>php</span></code>, write the following code <em>after</em> the <code class="codecolorer php default"><span class="php">&nbsp;<span style="color: #b1b100;">echo</span> renderChart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></span></code> line:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container javascript default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span><br /> &nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Specify the ID of the chart that you want to configure</span><br /> &nbsp; &nbsp; FusionCharts<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;top10_most_populous_countries&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">configureLink</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; swfUrl <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Charts/Area2D.swf&quot;</span>&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// Specify the chart type</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <br /> &nbsp; &nbsp; <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; &nbsp; <span style="color: #006600; font-style: italic;">// The first drill-down level is 0 (zero)</span><br /> <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></div></div><div class="code-holder-bottom"></div></div><p>Save the file, navigate to this page, and click on one of the columns again. This is what you should see:<br /> <iframe src="http://www.screenr.com/embed/PZB8" width="650" height="396" frameborder="0"></iframe></p><p>You can also render <a href="http://www.fusioncharts.com/demos/features/#linkedcharts-for-easy-drill-down" target="_blank">LinkedCharts in another container, or within a lightbox</a>. <a href="http://docs.fusioncharts.com/charts/contents/?JavaScript/API/Methods.html#constructor" target="_blank">Read more about such configurations</a> in our documentation.</p><h2>LinkedCharts Events</h2><p>The FusionCharts XT JavaScript API provides a number of events when LinkedCharts are in action. Each parent chart can listen to the events and can add more functionality to the implementation. The events are as follows:</p><ul><li><em>BeforeLinkedItemOpen</em>: Fires before a child chart is created</li><li><em>LinkedItemOpened</em>: Fires after a child chart is created</li><li><em>BeforeLinkItemClose</em>: Fires before a child chart is closed</li><li><em>LinkedItemClosed</em>: Fires after a child chart is closed</li></ul><p>Read more about <a href="http://docs.fusioncharts.com/charts/contents/?JavaScript/API/Events.html" target="_blank">Events in FusionCharts XT JavaScript API</a>.</p><h2>Download the source code</h2><p><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionChartsXT_LinkedCharts_in_PHP.zip"><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/03/Download_Sample_Code3.png" alt="" title="Download_Sample_Code" width="257" height="100" class="aligncenter size-full wp-image-2620" /></a></p><h2>Next in the series</h2><p>In the last part of the <em>FusionCharts XT in PHP</em> series, we will learn how to <a href="http://docs.fusioncharts.com/charts/contents/?Styles/Styles.html" target="_blank">apply styles</a> to our charts, <a href="http://docs.fusioncharts.com/charts/contents/?exporting-image/ECOverview.html" target="_blank">export</a> our charts, and <a href="http://docs.fusioncharts.com/charts/contents/?Debug/Basic.html" target="_blank">debug</a> our charts. Stay tuned!</p><div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/' rel='bookmark' title='Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3'>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2'>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1'>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</title><link>http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/</link> <comments>http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/#comments</comments> <pubDate>Mon, 19 Mar 2012 13:40:03 +0000</pubDate> <dc:creator>Hrishikesh Choudhari</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[drilldown]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[mysql]]></category> <category><![CDATA[php]]></category><guid isPermaLink="false">http://blog.fusioncharts.com/?p=2518</guid> <description><![CDATA[In the 3rd part of FusionCharts XT in PHP series, we will create drill-down charts in PHP using data from a MySQL database. Drill-down charts are immensely useful when you want to plot the subset of an aggregate data set. A generic use case can be world-wide sales data >> by country >> by state >> by city. FusionCharts XT supports unlimited levels of drill-down, and the chart types and<div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2'>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/' rel='bookmark' title='JavaScript LinkedCharts in PHP and MySQL using FusionCharts XT &#8211; Part 4'>JavaScript LinkedCharts in PHP and MySQL using FusionCharts XT &#8211; Part 4</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1'>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p></p><a href="http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/" title="Link to Drill-down JavaScript charts in PHP and MySQL - Part 3"><img class="wppt_float_left" src="http://blog.fusioncharts.com/wp-post-thumbnail/n3MFz.png" alt="" title="" width="88" height="88" /></a><p>In the 3rd part of FusionCharts XT in PHP series, we will create drill-down charts in PHP using data from a MySQL database. Drill-down charts are immensely useful when you want to plot the subset of an aggregate data set. A generic use case can be world-wide sales data >> by country >> by state >> by city. FusionCharts XT supports unlimited levels of drill-down, and the chart types and chart attributes can be configured for each level. To create drill-down charts in PHP, we will use the PHP script that is bundled with the FusionCharts Suite. This script automatically generates the HTML, JavaScript and XML required to plot your charts, so that you don&#8217;t need to.<br /> <span id="more-2518"></span></p><blockquote><h3>FusionCharts XT in PHP Series</h3><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/" target="_blank">Part 1 &#8211; JavaScript charts in PHP using FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/" target="_blank">Part 2 &#8211; JavaScript charts in PHP and MySQL using FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/">Part 3 &#8211; Drill-down JavaScript charts in PHP and MySQL</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/" target="_blank">Part 4 &#8211; JavaScript LinkedCharts in PHP and MySQL</a></li><li><a href="http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/" target="_blank">Part 5 &#8211; Using Debugging Tools for JavaScript Charts</a></li></blockquote><h2>What we are going to visualize</h2><p>In the <a href="http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/" target="_blank">2nd part</a>, we created a chart showing the Top 10 Most Populous Countries in the World. We will add drill-down functionality to it, such that upon clicking on one of the countries, it will show us the Top 10 Most Populous Cities of that particular country.<br /> <iframe src="http://www.screenr.com/embed/sxB8" width="650" height="396" frameborder="0"></iframe></p><h2>What we will need</h2><ul><li>PHP running on any server</li><li>MySQL</li><li><a href="http://www.fusioncharts.com/download/trials/" target="_blank">The latest version of FusionCharts XT</a></li><li>The <a href="http://downloads.mysql.com/docs/world.sql.zip" target="_blank">sample World database provided by MySQL</a>. <a href="http://dev.mysql.com/doc/world-setup/en/world-setup.html" target="_blank">Read more</a> to understand the structure of this database and how to set it up.</li><li><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionCharts_XT_with_PHP_MySQL.zip">The source code for the 2nd part of the series</a></li></ul><p>Our installation process will be the same as we did in the previous article. You may use the same setup or create it as follows:</p><ol><li>Within the root directory of your web server, create a folder named <code class="codecolorer php default"><span class="php">FusionCharts_XT_with_PHP</span></code>. This will be our demo folder.</li><li>Copy the entire <code class="codecolorer php default"><span class="php">Charts</span></code> folder from the FusionCharts XT Download Package and paste it within our demo folder. This completes the installation of FusionCharts XT in our web application.</li><li>Copy the <code class="codecolorer php default"><span class="php">Includes</span></code> folder from <code class="codecolorer php default"><span class="php">FusionCharts XT Download Package <span style="color: #339933;">&gt;</span> Code <span style="color: #339933;">&gt;</span> PHP <span style="color: #339933;">&gt;</span> Includes</span></code> to our demo folder.</li><li>Copy the source files used in the previous article and paste them in our demo folder</li></ol><h2>Attributes of a Drill-down chart</h2><p>To create a drill-down chart, you will require the following 3 things:</p><ol><li>A parent chart (which we already have)</li><li>The <code class="codecolorer xml default"><span class="xml">link</span></code> attribute added to the dataplots of the parent chart (see below how to add this attribute)</li><li>The child chart (we need to create this)</li></ol><p>To create a dataplot (be it column, pie or line/area anchor) in XML, you would have to specify the <code class="codecolorer xml default"><span class="xml">label</span></code> and the <code class="codecolorer xml default"><span class="xml">value</span></code> attributes for the <code class="codecolorer xml default"><span class="xml">set</span></code> element.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container xml default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'China'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'1277558000'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div><div class="code-holder-bottom"></div></div><p>Now to add drill-down to that dataplot, you will have to specify the <code class="codecolorer xml default"><span class="xml">link</span></code> attribute.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container xml default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">'China'</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">'1277558000'</span> <span style="color: #000066;">link</span>=<span style="color: #ff0000;">'DrillDown_Child_Chart.php?country=China'</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span></div></div><div class="code-holder-bottom"></div></div><p>With the above XML, the dataplot, when clicked, will go to the page <code class="codecolorer html4strict default"><span class="html4strict">DrillDown_Child_Chart.php?country=China</span></code>, which contains another chart to show some other data.</p><p>In <code class="codecolorer php default"><span class="php">FusionChartsXT_with_PHP_and_MySQL_DataString<span style="color: #339933;">.</span>php</span></code>, edit the part where you create the dataplots as below:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;set label='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' value='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Population'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' link='DrillDown_Child_Chart.php?country=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span></div></div><div class="code-holder-bottom"></div></div><p>Now that we have the first 2 things required for a drill-down chart, let us create the page that will show the child chart. This child chart needs to show a specific subset of the aggregate data; data related only to the parent dataplot.</p><h2></h2><p>Create a blank PHP file named <code class="codecolorer php default"><span class="php">DrillDown_Child_Chart<span style="color: #339933;">.</span>php</span></code> in our demo folder and write the following code in it:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> &nbsp; &nbsp; <br /> <span style="color: #666666; font-style: italic;">// Include the DBConn.php and FusionCharts.php files, so that we can access their variables and functions.</span><br /> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Includes/DBConn.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Includes/FusionCharts.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Retrieve the name of the country from the $_REQUEST parameter</span><br /> <span style="color: #000088;">$countryName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Use the connectToDB() function provided in DBConn.php, and establish the connection between PHP and the World database in our MySQL setup.</span><br /> <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> connectToDB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Form the SQL query which will return the Top 10 Most Populous Cities according to the specified Country.</span><br /> <span style="color: #000088;">$strQuery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT city.Name AS City, city.Population AS Population FROM city WHERE city.CountryCode = (SELECT country.Code FROM country WHERE country.Name = &quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$countryName</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;) ORDER BY Population DESC LIMIT 10'</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Execute the query, or else return the error message.</span><br /> <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$strQuery</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// If we get a valid response - </span><br /> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create the chart's XML string. We can add attributes here to customize our chart.</span><br /> &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;chart caption='Top 10 Most Populous Cities in <span style="color: #006699; font-weight: bold;">$countryName</span>' showValues='0' useRoundEdges='1' palette='3'&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ors</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Append the names of the cities and their respective populations to the chart's XML string.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;set label='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'City'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' value='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Population'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> <span style="color: #009900;">&#125;</span> &nbsp; <br /> <span style="color: #666666; font-style: italic;">// Close the chart's XML string.</span><br /> <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/chart&gt;&quot;</span><span style="color: #339933;">;</span>&nbsp; <br /> <span style="color: #000000; font-weight: bold;">?&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;<br /> &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br /> &lt;html&gt;<br /> &nbsp; &nbsp; &lt;head&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;title&gt;FusionCharts XT with PHP and MySQL&lt;/title&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- Include FusionCharts.js to provide client-side interactivity --&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;script type=&quot;text/javascript&quot; src=&quot;Charts/FusionCharts.js&quot;&gt;&lt;/script&gt;<br /> &nbsp; &nbsp; &lt;/head&gt;<br /> &nbsp; &nbsp; &lt;body&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- This DIV would be our chart container --&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;chartContainer&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the rendering mode to JavaScript</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FC_SetRenderer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'javascript'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Call the renderChart method, which would return the HTML and JavaScript required to generate the chart</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> renderChart<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Charts/Column2D.swf'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Path to chart type</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Empty string when using Data String method</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span><span style="color: #339933;">,</span><span style="color: #666666; font-style: italic;">// Variable which has the chart data</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'top10_most_populous_cities'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Unique chart ID</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'660'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'400'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Width and height in pixels</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>&nbsp; <span style="color: #666666; font-style: italic;">// Disable debug mode</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-weight: bold;">true</span>&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Enable 'Register with JavaScript' (Recommended)</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br /> &nbsp; &nbsp; &lt;/body&gt;<br /> &lt;/html&gt;</div></div><div class="code-holder-bottom"></div></div><p>Save this file. Navigate to <em>parent</em> chart first. On clicking one of the columns, it would load a new page with the child chart showing the relevant data.<br /> <iframe src="http://www.screenr.com/embed/sxB8" width="650" height="396" frameborder="0"></iframe></p><h2>Customizing the Drill-down chart</h2><p>In FusionCharts XT, you can define the following types of links:</p><ul><li>Links that <a href="http://docs.fusioncharts.com/charts/Code/DrillDown/SimpleExample.html" target="_blank">open in the same tab</a></li><li>Links that <a href="http://docs.fusioncharts.com/charts/Code/DrillDown/NewWindow.html" target="_blank">open in a new tab</a></li><li>Links that <a href="http://docs.fusioncharts.com/charts/Code/DrillDown/FrameExample.html" target="_blank">open in a specified frame</a></li><li>Links that <a href="http://docs.fusioncharts.com/charts/Code/DrillDown/PopUpExample.html" target="_blank">open in a new pop-up window</a></li><li>Links that <a href="http://docs.fusioncharts.com/charts/Code/DrillDown/JSExample.html" target="_blank">invoke JavaScript functions</a></li><li><a href="http://docs.fusioncharts.com/charts/Code/DrillDown/ChartHotSpot.html" target="_blank">Use the whole chart as a hotspot to use the simple link types named above</a></li></ul><p>You can <a href="http://docs.fusioncharts.com/charts/contents/?DrillDown/Simple.html" target="_blank">read more about customizing drill-down charts</a> in our documentation.</p><p>Another good read is our previous blog post where we talk about <a href="http://blog.fusioncharts.com/2011/02/4-things-to-know-to-create-an-intuitive-drill-down-interface/" target="_blank">making your drill-down charts more intuitive</a>.</p><h2>Download source files for these samples</h2><p><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/Drill_Down_Charts_in_PHP_MySQL_using_FusionChartsXT.zip"><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/03/Download_Sample_Code2.png" alt="" title="Download Source Code" width="257" height="100" class="aligncenter size-full wp-image-2555" /></a></p><h2>Next in the series</h2><p>In the next part of this series, we are going to tackle <a href="http://www.fusioncharts.com/demos/features/#linkedcharts-for-easy-drill-down" target="_blank">LinkedCharts</a>. It is a first-of-its-type concept using which you can create unlimited levels of drill-down charts. You may <a href="http://docs.fusioncharts.com/charts/contents/?DrillDown/LinkedCharts.html" target="_blank">read more about LinkedCharts</a> in our documentation.</p><div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2'>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/' rel='bookmark' title='JavaScript LinkedCharts in PHP and MySQL using FusionCharts XT &#8211; Part 4'>JavaScript LinkedCharts in PHP and MySQL using FusionCharts XT &#8211; Part 4</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1'>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</title><link>http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/</link> <comments>http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/#comments</comments> <pubDate>Fri, 16 Mar 2012 18:02:54 +0000</pubDate> <dc:creator>Hrishikesh Choudhari</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[analytics]]></category> <category><![CDATA[applications]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[php]]></category><guid isPermaLink="false">http://blog.fusioncharts.com/?p=2406</guid> <description><![CDATA[This the second part of the <em>FusionCharts XT with PHP</em> series. We will create interactive JavaScript charts using data from a MySQL database with FusionCharts XT. We will make use of the PHP library that is bundled with the FusionCharts Suite. To recap from the <a href="http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/" target="_blank">first article in this series</a>, FusionCharts XT is essentially a JavaScript charting library, which renders highly interactive charts in the browser. It<div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/' rel='bookmark' title='Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3'>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/' rel='bookmark' title='JavaScript LinkedCharts in PHP and MySQL using FusionCharts XT &#8211; Part 4'>JavaScript LinkedCharts in PHP and MySQL using FusionCharts XT &#8211; Part 4</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1'>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p></p><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/" title="Link to JavaScript charts in PHP and MySQL with FusionCharts XT - Part 2"><img class="wppt_float_left" src="http://blog.fusioncharts.com/wp-post-thumbnail/pvwTLi.png" alt="" title="" width="88" height="88" /></a><p>This the second part of the <em>FusionCharts XT with PHP</em> series. We will create interactive JavaScript charts using data from a MySQL database with FusionCharts XT. We will make use of the PHP library that is bundled with the FusionCharts Suite.</p><p>To recap from the <a href="http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/" target="_blank">first article in this series</a>, FusionCharts XT is essentially a JavaScript charting library, which renders highly interactive charts in the browser. It takes data in either <a href="http://docs.fusioncharts.com/charts/contents/?DataFormats/XML/Overview.html" target="_blank">XML</a> or <a href="http://docs.fusioncharts.com/charts/contents/?DataFormats/JSON/Overview.html" target="_blank">JSON</a>. To plot a chart using PHP, you need to include the HTML and JavaScript code to embed a chart object and then provide the requisite parameters. To make things simpler for you, we have put all this functionality in a PHP script named <code class="codecolorer php default"><span class="php">FusionCharts<span style="color: #339933;">.</span>php</span></code>. This script is bundled in <code class="codecolorer php default"><span class="php">FusionCharts XT Download Package <span style="color: #339933;">&gt;</span> Code <span style="color: #339933;">&gt;</span> PHP <span style="color: #339933;">&gt;</span> Includes <span style="color: #339933;">&gt;</span> FusionCharts<span style="color: #339933;">.</span>php</span></code>. So, whenever you need to work with FusionCharts XT in PHP, just include this file in your page and you&#8217;re good to go.<br /> <span id="more-2406"></span></p><blockquote><h3>FusionCharts XT in PHP Series</h3><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/" target="_blank">Part 1 &#8211; JavaScript charts in PHP using FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/">Part 2 &#8211; JavaScript charts in PHP and MySQL using FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/" target="_blank">Part 3 &#8211; Drill-down JavaScript charts in PHP and MySQL</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/" target="_blank">Part 4 &#8211; JavaScript LinkedCharts in PHP and MySQL</a></li><li><a href="http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/" target="_blank">Part 5 &#8211; Using Debugging Tools for JavaScript Charts</a></li></blockquote><h2>What we are going to visualize</h2><p>We will make use of the <a href="http://downloads.mysql.com/docs/world.sql.zip" target="_blank">sample World database provided by MySQL</a> and plot the Top 10 Most Populous Countries.<br /><script type="text/javascript" src="/Assets/fusioncharts/js/FusionCharts.js"></script></p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='top10_most_populous_countries';var myChartSWF='/Assets/fusioncharts/Column2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData("<chart caption='Top 10 Most Populous Countries' showValues='0' useRoundEdges='1' palette='3'><set label='China' value='1277558000' /><set label='India' value='1013662000' /><set label='United States' value='278357000' /><set label='Indonesia' value='212107000' /><set label='Brazil' value='170115000' /><set label='Pakistan' value='156483000' /><set label='Russian Federation' value='146934000' /><set label='Bangladesh' value='129155000' /><set label='Japan' value='126714000' /><set label='Nigeria' value='111506000' /></chart>");chartObj.render(myChartId+'container');/*]]>*/</script></p><h2>What we will need</h2><ul><li>PHP running on any server</li><li>MySQL</li><li><a href="http://www.fusioncharts.com/download/trials/" target="_blank">The latest version of FusionCharts XT</a></li><li>The <a href="http://downloads.mysql.com/docs/world.sql.zip" target="_blank">sample World database provided by MySQL</a>. <a href="http://dev.mysql.com/doc/world-setup/en/world-setup.html" target="_blank">Read more</a> to understand the structure of this database and how to set it up.</li></ul><p>Our installation process will be the same as we did in the previous article. You may use the same setup or create it as follows:</p><ol><li>Within the root directory of your web server, create a folder named <code class="codecolorer php default"><span class="php">FusionCharts_XT_with_PHP</span></code>. This will be our demo folder.</li><li>Copy the entire <code class="codecolorer php default"><span class="php">Charts</span></code> folder from the FusionCharts XT Download Package and paste it within our demo folder. This completes the installation of FusionCharts XT in our web application.</li><li>Copy the <code class="codecolorer php default"><span class="php">Includes</span></code> folder from <code class="codecolorer php default"><span class="php">FusionCharts XT Download Package <span style="color: #339933;">&gt;</span> Code <span style="color: #339933;">&gt;</span> PHP <span style="color: #339933;">&gt;</span> Includes</span></code> to our demo folder.</li></ol><h2>Connecting to the MySQL database</h2><p>In the <code class="codecolorer php default"><span class="php">Includes</span></code> folder, we provide you with <code class="codecolorer php default"><span class="php">DBConn<span style="color: #339933;">.</span>php</span></code>, which you can use to connect with your database. You may use this file to authenticate with your database if you aren&#8217;t using any other method. You would have to provide the relevant values to connect to your database. For instance, on our demo computer, we have the following values:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// These four parameters must be changed dependent on your MySQL settings</span><br /> &nbsp; &nbsp; <span style="color: #000088;">$hostdb</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">;</span> &nbsp; <span style="color: #666666; font-style: italic;">// MySQl host</span><br /> &nbsp; &nbsp; <span style="color: #000088;">$userdb</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'root'</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// MySQL username</span><br /> &nbsp; &nbsp; <span style="color: #000088;">$passdb</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// MySQL password</span><br /> &nbsp; &nbsp; <span style="color: #000088;">$namedb</span> <span style="color: #339933;">=</span> &nbsp;<span style="color: #000088;">$dbName</span> ? <span style="color: #000088;">$dbName</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'world'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// MySQL database name</span></div></div><div class="code-holder-bottom"></div></div><p><br/><br /> There are two ways using which you can provide data to the PHP library &#8211; <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataURL.html" target="_blank">Data URL</a> and <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataXMLExp.html" target="_blank">Data String</a>. Let us use both of them in detail.</p><h2>Creating the chart using the <em>Data URL</em> method</h2><p>In the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataURL.html" target="_blank">Data URL</a> method, you instruct FusionCharts to load XML or JSON data from a URL. This URL could refer to a static XML file that is already present on the server, or it could refer to a virtual data provider e.g., <code class="codecolorer php default"><span class="php"><span style="color: #339933;">/</span>path_to<span style="color: #339933;">/</span>DataProvider<span style="color: #339933;">.</span>php</span></code>, which executes queries the database, builds the XML data as string and finally outputs this XML string to the output stream with content type set to <code class="codecolorer html4strict default"><span class="html4strict">text/xml</span></code>, but without any HTML tags. We then need to create a second file, which would receive this XML string, pass it on to <code class="codecolorer php default"><span class="php">FusionCharts<span style="color: #339933;">.</span>php</span></code>, and then render the chart.</p><p>Let us create the first file named <code class="codecolorer php default"><span class="php">FusionChartsXT_with_PHP_and_MySQL_using_DataURL_DataProvider<span style="color: #339933;">.</span>php</span></code>. Write the following code in this file:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> <span style="color: #666666; font-style: italic;">// Set the content type in the header to text/xml.</span><br /> <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-type: text/xml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Include DBConn.php</span><br /> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Includes/DBConn.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Use the connectToDB() function provided in DBConn.php, and establish the connection between PHP and the World database in our MySQL setup.</span><br /> <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> connectToDB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Form the SQL query which will return the Top 10 Most Populous Countries.</span><br /> <span style="color: #000088;">$strQuery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT Name AS Country, Population FROM country ORDER BY Population DESC LIMIT 10'</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Execute the query, or else return the error message.</span><br /> <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$strQuery</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// If we get a valid response - </span><br /> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create the chart's XML string. We can add attributes here to customize our chart.</span><br /> &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;chart caption='Top 10 Most Populous Countries' showValues='0' useRoundEdges='1' palette='3'&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ors</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Append the names of the countries and their respective populations to the chart's XML string.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;set label='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' value='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Population'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> <span style="color: #009900;">&#125;</span> &nbsp; <br /> <span style="color: #666666; font-style: italic;">// Close the chart's XML string.</span><br /> <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/chart&gt;&quot;</span><span style="color: #339933;">;</span>&nbsp; <br /> <br /> <span style="color: #666666; font-style: italic;">// Return the valid XML string.</span><br /> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$strXML</span><span style="color: #339933;">;</span><br /> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div><div class="code-holder-bottom"></div></div><p>Save this file and navigate to it using your web browser. You should see the following XML displayed:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container xml default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;chart</span> <span style="color: #000066;">caption</span>=<span style="color: #ff0000;">&quot;Top 10 Most Populous Countries&quot;</span> <span style="color: #000066;">showValues</span>=<span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">useRoundEdges</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">palette</span>=<span style="color: #ff0000;">&quot;3&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;China&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;1277558000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;India&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;1013662000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;United States&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;278357000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Indonesia&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;212107000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Brazil&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;170115000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Pakistan&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;156483000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Russian Federation&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;146934000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Bangladesh&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;129155000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Japan&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;126714000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;set</span> <span style="color: #000066;">label</span>=<span style="color: #ff0000;">&quot;Nigeria&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;111506000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br /> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/chart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></div><div class="code-holder-bottom"></div></div><p>We now need to pass this XML data to <code class="codecolorer php default"><span class="php">FusionCharts<span style="color: #339933;">.</span>php</span></code>, which will generate the required HTML and JavaScript code to display our chart. Let us create a PHP file <code class="codecolorer php default"><span class="php">FusionChartsXT_with_PHP_and_MySQL_using_DataURL<span style="color: #339933;">.</span>php</span></code>. In this file, write the following code:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> <span style="color: #666666; font-style: italic;">// It would generate the HTML and JavaScript code required to render the chart. </span><br /> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Includes/FusionCharts.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <span style="color: #000000; font-weight: bold;">?&gt;</span><br /> &nbsp; &nbsp; <br /> &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;<br /> &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br /> &lt;html&gt;<br /> &nbsp; &nbsp; &lt;head&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;title&gt;FusionCharts XT with PHP and MySQL&lt;/title&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- Include FusionCharts.js to provide client-side interactivity --&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;script type=&quot;text/javascript&quot; src=&quot;FusionCharts/FusionCharts.js&quot;&gt;&lt;/script&gt;<br /> &nbsp; &nbsp; &lt;/head&gt;<br /> &nbsp; &nbsp; &lt;body&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- This DIV would be our chart container --&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;chartContainer&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the rendering mode to JavaScript</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FC_SetRenderer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'javascript'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Call the renderChart method, which would return the HTML and JavaScript required to generate the chart</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> renderChart<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FusionCharts/Column2D.swf'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Path to chart type</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'FusionChartsXT_with_PHP_and_MySQL_using_DataURL.php'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Path to the data provider</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Empty string when using Data URL Method</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'top10_most_populous_countries'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Unique chart ID</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'660'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'400'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Width and height in pixels</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>&nbsp; <span style="color: #666666; font-style: italic;">// Disable debug mode</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-weight: bold;">true</span>&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Enable 'Register with JavaScript' (Recommended)</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br /> &nbsp; &nbsp; &lt;/body&gt;<br /> &lt;/html&gt;</div></div><div class="code-holder-bottom"></div></div><p>Save this file and navigate to it using your web browser. This is the JavaScript chart that you should get to see:</p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='top10_most_populous_countries_1';var myChartSWF='/Assets/fusioncharts/Column2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData("<chart caption='Top 10 Most Populous Countries' showValues='0' useRoundEdges='1' palette='3'><set label='China' value='1277558000' /><set label='India' value='1013662000' /><set label='United States' value='278357000' /><set label='Indonesia' value='212107000' /><set label='Brazil' value='170115000' /><set label='Pakistan' value='156483000' /><set label='Russian Federation' value='146934000' /><set label='Bangladesh' value='129155000' /><set label='Japan' value='126714000' /><set label='Nigeria' value='111506000' /></chart>");chartObj.render(myChartId+'container');/*]]>*/</script></p><h2>Creating the chart using <em>Data String</em> method</h2><p>In the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataXMLExp.html" target="_blank">Data String</a> method, the XML or JSON data is embedded within a single web page, along with the chart&#8217;s HTML and JavaScript code. This method doesn&#8217;t require a static data file or a virtual data provider. Moreover, once the chart has finished loading, the data is present locally within the page.</p><p>Create a blank PHP file named <code class="codecolorer php default"><span class="php">FusionChartsXT_with_PHP_and_MySQL_using_DataString<span style="color: #339933;">.</span>php</span></code>. Write the following code in this file:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> &nbsp; &nbsp; <br /> <span style="color: #666666; font-style: italic;">// Include the DBConn.php and FusionCharts.php files, so that we can access their variables and functions.</span><br /> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Includes/DBConn.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Includes/FusionCharts.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Use the connectToDB() function provided in DBConn.php, and establish the connection between PHP and the World database in our MySQL setup.</span><br /> <span style="color: #000088;">$link</span> <span style="color: #339933;">=</span> connectToDB<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Form the SQL query which will return the Top 10 Most Populous Countries.</span><br /> <span style="color: #000088;">$strQuery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SELECT Name AS Country, Population FROM country ORDER BY Population DESC LIMIT 10'</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// Execute the query, or else return the error message.</span><br /> <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$strQuery</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #666666; font-style: italic;">// If we get a valid response - </span><br /> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create the chart's XML string. We can add attributes here to customize our chart.</span><br /> &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;chart caption='Top 10 Most Populous Countries' showValues='0' useRoundEdges='1' palette='3'&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <br /> &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ors</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Append the names of the countries and their respective populations to the chart's XML string.</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;set label='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Country'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' value='&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$ors</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Population'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;' /&gt;&quot;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> <span style="color: #009900;">&#125;</span> &nbsp; <br /> <span style="color: #666666; font-style: italic;">// Close the chart's XML string.</span><br /> <span style="color: #000088;">$strXML</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;/chart&gt;&quot;</span><span style="color: #339933;">;</span>&nbsp; <br /> <span style="color: #000000; font-weight: bold;">?&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;<br /> &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br /> &lt;html&gt;<br /> &nbsp; &nbsp; &lt;head&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;title&gt;FusionCharts XT with PHP and MySQL&lt;/title&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- Include FusionCharts.js to provide client-side interactivity --&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;script type=&quot;text/javascript&quot; src=&quot;FusionCharts/FusionCharts.js&quot;&gt;&lt;/script&gt;<br /> &nbsp; &nbsp; &lt;/head&gt;<br /> &nbsp; &nbsp; &lt;body&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;!-- This DIV would be our chart container --&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;div id=&quot;chartContainer&quot;&gt;<br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Set the rendering mode to JavaScript</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FC_SetRenderer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'javascript'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Call the renderChart method, which would return the HTML and JavaScript required to generate the chart</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> renderChart<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FusionCharts/Column2D.swf'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Path to chart type</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Empty string when using Data String method</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$strXML</span><span style="color: #339933;">,</span><span style="color: #666666; font-style: italic;">// Variable which has the chart data</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'top10_most_populous_countries'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Unique chart ID</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'660'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'400'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Width and height in pixels</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>&nbsp; <span style="color: #666666; font-style: italic;">// Disable debug mode</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-weight: bold;">true</span>&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Enable 'Register with JavaScript' (Recommended)</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">?&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br /> &nbsp; &nbsp; &lt;/body&gt;<br /> &lt;/html&gt;</div></div><div class="code-holder-bottom"></div></div><p>Save this file and navigate to it using your web browser. This is the JavaScript chart that you should get to see:</p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='top10_most_populous_countries_2';var myChartSWF='/Assets/fusioncharts/Column2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData("<chart caption='Top 10 Most Populous Countries' showValues='0' useRoundEdges='1' palette='3'><set label='China' value='1277558000' /><set label='India' value='1013662000' /><set label='United States' value='278357000' /><set label='Indonesia' value='212107000' /><set label='Brazil' value='170115000' /><set label='Pakistan' value='156483000' /><set label='Russian Federation' value='146934000' /><set label='Bangladesh' value='129155000' /><set label='Japan' value='126714000' /><set label='Nigeria' value='111506000' /></chart>");chartObj.render(myChartId+'container');/*]]>*/</script></p><h2>Download source files for these samples</h2><p><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionCharts_XT_with_PHP_MySQL.zip"><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/03/Download_Sample_Code1.png" alt="" title="Download Sample Code" width="257" height="100" class="aligncenter size-full wp-image-2509" /></a></p><h2>Next in the series</h2><p>In this article, the chart has top 10 countries by population. In the next article, we will see how to <a href="http://docs.fusioncharts.com/charts/contents/?DrillDown/Simple.html" target="_blank">add drill-down capability</a> to this MySQL data. So when you click on the column showing China&#8217;s population, you will be able to drill-down to the most populous cities in China.</p><div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/' rel='bookmark' title='Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3'>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/' rel='bookmark' title='JavaScript LinkedCharts in PHP and MySQL using FusionCharts XT &#8211; Part 4'>JavaScript LinkedCharts in PHP and MySQL using FusionCharts XT &#8211; Part 4</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1'>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</title><link>http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/</link> <comments>http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/#comments</comments> <pubDate>Thu, 15 Mar 2012 14:17:16 +0000</pubDate> <dc:creator>Hrishikesh Choudhari</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[ipad]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[php]]></category> <category><![CDATA[XML]]></category><guid isPermaLink="false">http://blog.fusioncharts.com/?p=2296</guid> <description><![CDATA[PHP developers often build applications that work on a diverse data spectrum like sales, marketing, finance, health care or government and beyond. For the end-users of such applications to be able to make sense and take the right actions, it is necessary to represent data in the right form as dashboards or reports. Dashboards, which are an inter-connected collection of charts, gauges and grids facilitate inference, insight and actions -<div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2'>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/' rel='bookmark' title='Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3'>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1'>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-sql-server-data-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts using SQL Server data with FusionCharts XT &#8211; Part 2'>JavaScript charts using SQL Server data with FusionCharts XT &#8211; Part 2</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p></p><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/" title="Link to JavaScript charts in PHP using FusionCharts XT - Part 1"><img class="wppt_float_left" src="http://blog.fusioncharts.com/wp-post-thumbnail/IR8d3E.png" alt="" title="" width="88" height="88" /></a><p>PHP developers often build applications that work on a diverse data spectrum like sales, marketing, finance, health care or government and beyond. For the end-users of such applications to be able to make sense and take the right actions, it is necessary to represent data in the right form as dashboards or reports. Dashboards, which are an inter-connected collection of charts, gauges and grids facilitate inference, insight and actions &#8211; the most critical aspects of any enterprise.</p><p>Many charting components are available for use in your PHP apps. While most of these are server side components that generate static images of charts and gauges, without any interactivity, a few are client-side solutions that use JavaScript or Flash to generate interactive charts, gauges and grids. Enter FusionCharts Suite, the industry&#8217;s leading enterprise-grade JavaScript charting solution. For PHP developers who wouldn&#8217;t want to dabble in JavaScript, it also provides server-side libraries which enable them to create delightful charts in JavaScript. These libraries help in connecting to data sources, producing the chart data, and generating the required HTML and JavaScript code, which can be easily embedded in any web page.<br /> <span id="more-2296"></span><br /> An example of a JavaScript chart generated by FusionCharts XT is shown below. Interact with it by hovering over a column to see the tool-tip, or use the scrollbar below the columns to see more data points, or click on the legend key to show/hide a data-series.<br /> <br /><script type="text/javascript" src="/Assets/fusioncharts/js/FusionCharts.js"></script></p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='most_multilingual_vs_population';var myChartSWF='/Assets/fusioncharts/ScrollCombiDY2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData('<chart caption="Top 25 Multilingual Countries vs Their Population" PYAxisName="Languages Spoken" SYAxisName="Population" showValues="0" useRoundEdges="1" palette="3" numVisiblePlot="5" sFormatNumberScale="1" lineThickness="5" anchorRadius="5"><categories><category label="Canada" /><category label="China" /><category label="India" /><category label="United States" /><category label="Russian Federation" /><category label="Tanzania" /><category label="South Africa" /><category label="Congo, The Democratic Republic of the" /><category label="Kenya" /><category label="Mozambique" /><category label="Philippines" /><category label="Uganda" /><category label="Nigeria" /><category label="Iran" /><category label="Sudan" /><category label="Angola" /><category label="Vietnam" /><category label="Indonesia" /><category label="Czech Republic" /><category label="Austria" /><category label="Pakistan" /><category label="Myanmar" /><category label="Chad" /><category label="Sierra Leone" /><category label="Namibia" /></categories><dataset seriesName="Languages Spoken" showValues="1"><set value="12" /><set value="12" /><set value="12" /><set value="12" /><set value="12" /><set value="11" /><set value="11" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="9" /><set value="9" /><set value="9" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /></dataset><dataset seriesName="Population" parentYAxis="S"><set value="31147000" /><set value="1277558000" /><set value="1013662000" /><set value="278357000" /><set value="146934000" /><set value="33517000" /><set value="40377000" /><set value="51654000" /><set value="30080000" /><set value="19680000" /><set value="75967000" /><set value="21778000" /><set value="111506000" /><set value="67702000" /><set value="29490000" /><set value="12878000" /><set value="79832000" /><set value="212107000" /><set value="10278100" /><set value="8091800" /><set value="156483000" /><set value="45611000" /><set value="7651000" /><set value="4854000" /><set value="1726000" /></dataset></chart>');chartObj.render(myChartId+'container');/*]]>*/</script></p><p>To plot a chart using PHP, you need to include the HTML and JavaScript code to embed a chart object and then provide the requisite parameters. To make things simpler for you, we have put all this functionality in a PHP script named <code class="codecolorer php default"><span class="php">FusionCharts<span style="color: #339933;">.</span>php</span></code>. This script is bundled in <code class="codecolorer php default"><span class="php">FusionCharts XT Download Package <span style="color: #339933;">&gt;</span> Code <span style="color: #339933;">&gt;</span> PHP <span style="color: #339933;">&gt;</span> Includes <span style="color: #339933;">&gt;</span> FusionCharts<span style="color: #339933;">.</span>php</span></code>. So, whenever you need to work with FusionCharts XT in PHP, just include this file in your page and you&#8217;re good to go.</p><p>In this series of blog posts, we will show you how to build interactive JavaScript charts using FusionCharts XT in your PHP applications. We will start with the basic charts and move on to advanced examples like powering the charts using databases, adding drill-down capabilities and more. Specifically, the series will be divided into the following posts:</p><ul><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/">Creating a simple chart in PHP using the FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/" target="_blank">Powering the charts in your PHP apps using data from MySQL database</a></li><li><a href="http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/" target="_blank">Adding drill-down capabilities to these charts in PHP</a></li><li><a href="http://blog.fusioncharts.com/2012/03/javascript-linkedcharts-in-php-and-mysql-using-fusioncharts-xt/" target="_blank">Creating LinkedCharts in PHP</a></li><li><a href="http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/" target="_blank">Using the Debugging Tools provided</a></li></ul><p>So let&#8217;s get started!</p><h2>What we are going to visualize</h2><p>The JavaScript chart shown above is specific chart type a <a href="http://docs.fusioncharts.com/charts/contents/?ChartSS/ScrollCombiDY2D.html" target="_blank">Scroll Combination chart with dual Y axes</a> in FusionCharts parlance. The data provided to it visualizes the Top 25 Multilingual Countries versus their population.</p><p>We will re-create this chart using the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataURL.html" target="_blank">Data URL</a> and the <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/how-fusioncharts-works/DataXMLExp.html" target="_blank">Data String</a> methods. You can use any of these methods you provide data to any chart created using FusionCharts XT.</p><p>FusionCharts XT understands data in either <a href="http://docs.fusioncharts.com/charts/contents/?DataFormats/XML/Overview.html" target="_blank">XML</a> or <a href="http://docs.fusioncharts.com/charts/contents/?DataFormats/JSON/Overview.html" target="_blank">JSON</a>. Depending upon the chart type being used, the structure of the XML or JSON will differ. We will try out both the formats in this post.</p><h2>What we will need</h2><ul><li>PHP running on any server</li><li><a href="http://www.fusioncharts.com/download/trials/" target="_blank">The latest version of FusionCharts XT</a></li><li><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/XML_and_JSON.zip" target="_blank">XML file containing the chart data</a></li></ul><ol><li>Within the root directory of your web server, create a folder named <code class="codecolorer php default"><span class="php">FusionCharts_XT_with_PHP</span></code>. This will be our demo folder.</li><li>Copy the entire <code class="codecolorer php default"><span class="php">Charts</span></code> folder from the FusionCharts XT Download Package and paste it within our demo folder. This completes the installation of FusionCharts XT in our web application.</li><li>Copy the <code class="codecolorer php default"><span class="php">Includes</span></code> folder from <code class="codecolorer php default"><span class="php">FusionCharts XT Download Package <span style="color: #339933;">&gt;</span> Code <span style="color: #339933;">&gt;</span> PHP <span style="color: #339933;">&gt;</span> Includes</span></code> to our demo folder.</li></ol><h2>Why use the Scroll Column chart with Dual Y Axes?</h2><p>Plotting 25 columns within this blog&#8217;s width would crunch them together. So we pick the well spaced Scroll Column charts over the regular Column charts. Secondly, the chart will have values in 2 different units &#8211; number of languages spoken and the population. Plotting values of different units on the same Y axis would lead to incorrect visualization; therefore we would use the Scroll Column 2D Dual Y axes chart.</p><h2>Creating a chart from static XML</h2><p>In the Data URL method, you tell FusionCharts XT to load data from an XML or JSON file URL. This URL could also point to a virtual data provider, e.g., <code class="codecolorer php default"><span class="php"><span style="color: #339933;">/</span>path_to<span style="color: #339933;">/</span>data_provider<span style="color: #339933;">.</span>php</span></code>, which will execute queries on the database, construct the XML data and output it to the stream, with content type set to <code class="codecolorer php default"><span class="php">text<span style="color: #339933;">/</span>xml</span></code>. For this example, we will point FusionCharts XT to an XML file&#8217;s URL.</p><p>Create a blank PHP file within the demo folder and save it as <code class="codecolorer php default"><span class="php">FusionCharts_XT_Data_URL<span style="color: #339933;">.</span>php</span></code>.<br /> Include the <code class="codecolorer php default"><span class="php">FusionCharts<span style="color: #339933;">.</span>php</span></code> library, and create a simple HTML page. Include <code class="codecolorer html4strict default"><span class="html4strict">FusionCharts.js</span></code> in the <code class="codecolorer html4strict default"><span class="html4strict">head</span></code> tag.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container html4strict default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;?php </span><br /> <span style="color: #009900;">include<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Includes/FusionCharts.php'</span><span style="color: #66cc66;">&#41;</span>;</span><br /> <span style="color: #009900;">?&gt;</span><br /> <br /> <span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span><br /> <span style="color: #00bbdd;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Using FusionCharts XT with PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Charts/FusionCharts.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;chartContainer&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></div></div><div class="code-holder-bottom"></div></div><p>Within the <code class="codecolorer php default"><span class="php">chartContainer</span></code> div, we will call the <code class="codecolorer php default"><span class="php">renderChart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> method. This method generates all the HTML and JavaScript code required to create a chart. We will write this generated code within the container <code class="codecolorer php default"><span class="php">div</span></code>. Since we want to render the chart in JavaScript, we need to specify this before rendering the chart:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br /> FC_SetRenderer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'javascript'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <br /> <span style="color: #b1b100;">echo</span> renderChart<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Charts/ScrollCombiDY2D.swf'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Most_Multilingual_Countries_VS_Their_Population.xml'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'using_setXMLUrl'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'660'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'400'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br /> <span style="color: #000000; font-weight: bold;">?&gt;</span></div></div><div class="code-holder-bottom"></div></div><p>Save this page, and navigate to this page using your web browser. This is the JavaScript chart that you should get to see:</p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='most_multilingual_vs_population1';var myChartSWF='/Assets/fusioncharts/ScrollCombiDY2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData('<chart caption="Top 25 Multilingual Countries vs Their Population" PYAxisName="Languages Spoken" SYAxisName="Population" showValues="0" useRoundEdges="1" palette="3" numVisiblePlot="5" sFormatNumberScale="1" lineThickness="5" anchorRadius="5"><categories><category label="Canada" /><category label="China" /><category label="India" /><category label="United States" /><category label="Russian Federation" /><category label="Tanzania" /><category label="South Africa" /><category label="Congo, The Democratic Republic of the" /><category label="Kenya" /><category label="Mozambique" /><category label="Philippines" /><category label="Uganda" /><category label="Nigeria" /><category label="Iran" /><category label="Sudan" /><category label="Angola" /><category label="Vietnam" /><category label="Indonesia" /><category label="Czech Republic" /><category label="Austria" /><category label="Pakistan" /><category label="Myanmar" /><category label="Chad" /><category label="Sierra Leone" /><category label="Namibia" /></categories><dataset seriesName="Languages Spoken" showValues="1"><set value="12" /><set value="12" /><set value="12" /><set value="12" /><set value="12" /><set value="11" /><set value="11" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="9" /><set value="9" /><set value="9" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /></dataset><dataset seriesName="Population" parentYAxis="S"><set value="31147000" /><set value="1277558000" /><set value="1013662000" /><set value="278357000" /><set value="146934000" /><set value="33517000" /><set value="40377000" /><set value="51654000" /><set value="30080000" /><set value="19680000" /><set value="75967000" /><set value="21778000" /><set value="111506000" /><set value="67702000" /><set value="29490000" /><set value="12878000" /><set value="79832000" /><set value="212107000" /><set value="10278100" /><set value="8091800" /><set value="156483000" /><set value="45611000" /><set value="7651000" /><set value="4854000" /><set value="1726000" /></dataset></chart>');chartObj.render(myChartId+'container');/*]]>*/</script></p><p>The <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/php/PHP_BasicExample.html" target="_blank">renderChart()</a> method takes parameters in the following order:</p><ul><li>Chart SWF name: The first parameter contains the Path and file name of the chart SWF file. We have to use the relative path to SWF file, which is recommended. When plotting charts in JavaScript, FusionCharts XT uses the SWF name to internally map to the chart&#8217;s JavaScript alias.</li><li>URL to static XML file, if Data URL method is to be used. If you intend to use Data String method, leave this as blank.</li><li>Variable containing XML data string, if Data String method is to be used. If you have specified data as a URL, leave this parameter as blank.</li><li>ID of the chart – Each chart on the page needs a unique ID. This ID is different from the ID of the container DIV. As we will learn later, this ID is used to get a reference to the chart for manipulation using advanced JavaScript.</li><li>Width and height in pixels – Each chart needs to be initialized with width and height, specified either in pixels (specified in numeric format, without appending px) or percentage. In this example, we have used pixels. You can also set it to percentage values. The FusionCharts JavaScript class will automatically convert the percentage dimensions to pixel dimensions, with respect to the parent container element in HTML, DIV in this case, and pass it to the chart.</li><li>Boolean for Debug Mode – If you&#8217;re facing any issues while developing your charts, you can initialize them in debug mode by setting this parameter to <code class="codecolorer php default"><span class="php"><span style="color: #009900; font-weight: bold;">true</span></span></code>. The debug mode gives you behind-the-scenes information on where data is loaded from, errors etc. In our example, we are rendering the chart in normal mode, by setting this parameter to <code class="codecolorer php default"><span class="php"><span style="color: #009900; font-weight: bold;">false</span></span></code>.</li><li>Boolean for Registering with JavaScript &#8211; In earlier versions of FusionCharts, the last parameter let you configure whether charts could be controlled using JavaScript. Now that FusionCharts is very tightly integrated with FusionCharts, this parameter is a mandatory <code class="codecolorer php default"><span class="php"><span style="color: #009900; font-weight: bold;">true</span></span></code>.</li></ul><h2>Creating a chart from XML string</h2><p>In the Data String method, the XML or JSON data is embedded within the web page, along with the chart&#8217;s HTML and JavaScript code. This method doesn&#8217;t require a static data file or a virtual data provider. Moreover, once the chart has finished loading, the data is present locally within the page.</p><p>Create a blank PHP file within the demo folder and save it as <code class="codecolorer php default"><span class="php">FusionCharts_XT_Data_String<span style="color: #339933;">.</span>php</span></code>.<br /> Include the <code class="codecolorer php default"><span class="php">FusionCharts<span style="color: #339933;">.</span>php library</span></code>. We will create a string variable which will hold the XML data for our chart. Let us make use of the same XML file we used before for the Data URL method. Copy the contents of the file and paste it as the content for the string variable.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container html4strict default" style="border:1px solid #9F9F9F;width:435px;height:300px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;?php</span><br /> <span style="color: #009900;"> include<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'Includes/FusionCharts.php'</span><span style="color: #66cc66;">&#41;</span>;</span><br /> <br /> <span style="color: #009900;">$strXML <span style="color: #66cc66;">=</span> <span style="color: #ff0000;">'&lt;chart caption=&quot;Top 25 Multilingual Countries vs Their Population&quot; PYAxisName=&quot;Languages Spoken&quot; SYAxisName=&quot;Population&quot; showValues=&quot;0&quot; useRoundEdges=&quot;1&quot; palette=&quot;3&quot; numVisiblePlot=&quot;5&quot; sFormatNumberScale=&quot;1&quot; lineThickness=&quot;5&quot; anchorRadius=&quot;5&quot;&gt;</span></span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;categories&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Canada&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;China&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;India&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;United States&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Russian Federation&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Tanzania&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;South Africa&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Congo, The Democratic Republic of the&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Kenya&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Mozambique&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Philippines&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Uganda&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Nigeria&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Iran&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Sudan&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Angola&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Vietnam&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Indonesia&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Czech Republic&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Austria&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Pakistan&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Myanmar&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Chad&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Sierra Leone&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;category <span style="color: #000066;">label</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Namibia&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>categories&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;dataset seriesName<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Languages Spoken&quot;</span> showValues<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;12&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;12&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;12&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;12&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;12&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;11&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;11&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;9&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;9&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;9&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>dataset&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;dataset seriesName<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Population&quot;</span> parentYAxis<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;S&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;31147000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1277558000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1013662000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;278357000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;146934000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;33517000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;40377000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;51654000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;30080000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;19680000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;75967000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;21778000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;111506000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;67702000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;29490000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;12878000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;79832000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;212107000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;10278100&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;8091800&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;156483000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;45611000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;7651000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4854000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;set <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1726000&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>dataset&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>chart&gt;</span>';<br /> ?&gt;<br /> <br /> <span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span><br /> <span style="color: #00bbdd;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Using FusionCharts XT with PHP<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Charts/FusionCharts.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;chartContainer&quot;</span>&gt;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FC_SetRenderer('javascript');<br /> <br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo renderChart('Charts/ScrollCombiDY2D.swf', '', $strXML, 'using_setXMLData', '660', '400', false, true);<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span><br /> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></div></div><div class="code-holder-bottom"></div></div><p>Again we will call the <code class="codecolorer php default"><span class="php">renderChart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> method within the <code class="codecolorer php default"><span class="php">div</span></code> container. However, we will leave the second parameter blank (which takes in the path to the URL) and make use of the third parameter to provide the variable that holds the XML data.</p><p>Save this page, and navigate to this page using your web browser. You should get to see the same JavaScript chart as before:</p><p><script type="text/javascript">/*<![CDATA[*/FusionCharts.setCurrentRenderer('javascript');var myChartId='most_multilingual_vs_population2';var myChartSWF='/Assets/fusioncharts/ScrollCombiDY2D.swf';var myChartWidth='660';var myChartHeight='400';document.write('<span id="'+myChartId+'container">');var chartObj=new FusionCharts(myChartSWF,myChartId,myChartWidth,myChartHeight);chartObj.setXMLData('<chart caption="Top 25 Multilingual Countries vs Their Population" PYAxisName="Languages Spoken" SYAxisName="Population" showValues="0" useRoundEdges="1" palette="3" numVisiblePlot="5" sFormatNumberScale="1" lineThickness="5" anchorRadius="5"><categories><category label="Canada" /><category label="China" /><category label="India" /><category label="United States" /><category label="Russian Federation" /><category label="Tanzania" /><category label="South Africa" /><category label="Congo, The Democratic Republic of the" /><category label="Kenya" /><category label="Mozambique" /><category label="Philippines" /><category label="Uganda" /><category label="Nigeria" /><category label="Iran" /><category label="Sudan" /><category label="Angola" /><category label="Vietnam" /><category label="Indonesia" /><category label="Czech Republic" /><category label="Austria" /><category label="Pakistan" /><category label="Myanmar" /><category label="Chad" /><category label="Sierra Leone" /><category label="Namibia" /></categories><dataset seriesName="Languages Spoken" showValues="1"><set value="12" /><set value="12" /><set value="12" /><set value="12" /><set value="12" /><set value="11" /><set value="11" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="10" /><set value="9" /><set value="9" /><set value="9" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /><set value="8" /></dataset><dataset seriesName="Population" parentYAxis="S"><set value="31147000" /><set value="1277558000" /><set value="1013662000" /><set value="278357000" /><set value="146934000" /><set value="33517000" /><set value="40377000" /><set value="51654000" /><set value="30080000" /><set value="19680000" /><set value="75967000" /><set value="21778000" /><set value="111506000" /><set value="67702000" /><set value="29490000" /><set value="12878000" /><set value="79832000" /><set value="212107000" /><set value="10278100" /><set value="8091800" /><set value="156483000" /><set value="45611000" /><set value="7651000" /><set value="4854000" /><set value="1726000" /></dataset></chart>');chartObj.render(myChartId+'container');/*]]>*/</script></p><h2>Providing data in JSON</h2><p>To provide JSON data to the chart, instead of XML, you can call the following method before the <code class="codecolorer php default"><span class="php">renderChart<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span></span></code> method of the specific chart:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">FC_SetDataFormat<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><div class="code-holder-bottom"></div></div><p>We provide a tool with which you can convert chart data from XML to JSON. You can find it in the <code class="codecolorer html4strict default"><span class="html4strict">FusionCharts Download Package &gt; Tools &gt; FCDataConverter</span></code>. You can paste in the XML provided above and get the chart data in JSON:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container javascript default" style="border:1px solid #9F9F9F;width:435px;height:300px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span><br /> &nbsp; <span style="color: #3366CC;">&quot;chart&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;caption&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Top 25 Multilingual Countries vs Their Population&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;pyaxisname&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Languages Spoken&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;syaxisname&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Population&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;showvalues&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;0&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;useroundedges&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;palette&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;3&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;numvisibleplot&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;5&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;sformatnumberscale&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;linethickness&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;5&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #3366CC;">&quot;anchorradius&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;5&quot;</span><br /> &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; <span style="color: #3366CC;">&quot;categories&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;category&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Canada&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;China&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;India&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;United States&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Russian Federation&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Tanzania&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;South Africa&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Congo, The Democratic Republic of the&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Kenya&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Mozambique&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Philippines&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Uganda&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Nigeria&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Iran&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sudan&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Angola&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Vietnam&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Indonesia&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Czech Republic&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Austria&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Pakistan&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Myanmar&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Chad&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sierra Leone&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;label&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Namibia&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#93;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> &nbsp; <span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><br /> &nbsp; <span style="color: #3366CC;">&quot;dataset&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;seriesname&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Languages Spoken&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;showvalues&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;12&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;12&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;12&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;12&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;12&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;11&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;11&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;10&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;10&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;10&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;10&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;10&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;10&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;10&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;10&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;9&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;9&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;9&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;8&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;8&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;8&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;8&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;8&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;8&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;8&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#93;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;seriesname&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Population&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;parentyaxis&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;S&quot;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;data&quot;</span><span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;31147000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1277558000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1013662000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;278357000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;146934000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;33517000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;40377000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;51654000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;30080000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;19680000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;75967000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;21778000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;111506000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;67702000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;29490000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;12878000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;79832000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;212107000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;10278100&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;8091800&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;156483000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;45611000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;7651000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;4854000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">&quot;value&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;1726000&quot;</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#93;</span><br /> &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br /> &nbsp; <span style="color: #009900;">&#93;</span><br /> <span style="color: #009900;">&#125;</span></div></div><div class="code-holder-bottom"></div></div><p>If you change the chart&#8217;s data format to JSON and provide this JSON data, you would get the same chart as before. JSON can be provided using the Data URL and Data String method too, just like XML.</p><h2>Download the source files for this demo</h2><p><a href="http://blog.fusioncharts.com/wp-content/uploads/2012/03/FusionChartsXT_in_PHP.zip"><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/03/Download_Sample_Code.png" alt="" title="Download Sample Code" width="257" height="100" class="aligncenter size-full wp-image-2471" /></a></p><h2>Next article in this series: Create a chart using data from a database</h2><p>In the next article, we will create a chart using data from a database.  If, however, you&#8217;re feeling impatient, you can head over to our <a href="http://docs.fusioncharts.com/charts/" target="_blank">documentation</a> and read on <a href="http://docs.fusioncharts.com/charts/contents/?guide-for-web-developers/php/PHP_DB.html" target="_blank">how to use FusionCharts XT to create charts using data from a database</a>. Stay tuned.</p><div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-php-and-mysql-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2'>JavaScript charts in PHP and MySQL with FusionCharts XT &#8211; Part 2</a></li><li><a href='http://blog.fusioncharts.com/2012/03/drill-down-javascript-charts-in-php-and-mysql-part-3/' rel='bookmark' title='Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3'>Drill-down JavaScript charts in PHP and MySQL &#8211; Part 3</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-with-asp-net-c-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1'>JavaScript charts with ASP.NET (C#) using FusionCharts XT &#8211; Part 1</a></li><li><a href='http://blog.fusioncharts.com/2012/03/debugging-javascript-charts-with-fusioncharts-xt-part-5/' rel='bookmark' title='Debugging JavaScript charts with FusionCharts XT &#8211; Part 5'>Debugging JavaScript charts with FusionCharts XT &#8211; Part 5</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-using-sql-server-data-with-fusioncharts-xt-part-2/' rel='bookmark' title='JavaScript charts using SQL Server data with FusionCharts XT &#8211; Part 2'>JavaScript charts using SQL Server data with FusionCharts XT &#8211; Part 2</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Create charts for iPhone and iPad apps using FusionCharts XT</title><link>http://blog.fusioncharts.com/2012/02/create-charts-for-iphone-and-ipad-apps-using-fusioncharts-xt/</link> <comments>http://blog.fusioncharts.com/2012/02/create-charts-for-iphone-and-ipad-apps-using-fusioncharts-xt/#comments</comments> <pubDate>Wed, 29 Feb 2012 05:58:12 +0000</pubDate> <dc:creator>Hrishikesh Choudhari</dc:creator> <category><![CDATA[Tutorials]]></category> <category><![CDATA[ipad]]></category> <category><![CDATA[iphone]]></category> <category><![CDATA[javascript]]></category><guid isPermaLink="false">http://blog.fusioncharts.com/?p=2206</guid> <description><![CDATA[To provide executives with access to business data on the go, enterprises are adopting iPhones and iPads in droves. Many of these applications have need for smart data visualizations, but are currently restricted by the limited capabilities of available charting libraries for iOS. Some have limited chart types, whereas others lack the visual appeal and interactivity. Open source libraries are not backed by proper technical support either. So what are<div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2010/09/fusioncharts-is-now-ipad-ready/' rel='bookmark' title='FusionCharts is now iPad ready!'>FusionCharts is now iPad ready!</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p></p><a href="http://blog.fusioncharts.com/2012/02/create-charts-for-iphone-and-ipad-apps-using-fusioncharts-xt/" title="Link to Create charts for iPhone and iPad apps using FusionCharts XT"><img class="wppt_float_left" src="http://blog.fusioncharts.com/wp-post-thumbnail/JPuxn2.png" alt="" title="" width="88" height="88" /></a><p>To provide executives with access to business data on the go, enterprises are adopting iPhones and iPads in droves. Many of these applications have need for smart data visualizations, but are currently restricted by the limited capabilities of available charting libraries for iOS. Some have limited chart types, whereas others lack the visual appeal and interactivity. Open source libraries are not backed by proper technical support either. So what are your options?</p><p>Enter FusionCharts XT, which addresses all these concerns. Being a JavaScript charting library, it can easily render charts and widgets within the UIWebView control of an iOS application. With over 90 chart types that are animated and interactive, it augments the visual appeal and functionality of your iOS applications. In addition, dedicated tech support is there to answer any or all of your queries.<br /> <span id="more-2206"></span><br /> You can either obtain the data from a remote web service, or access the local data stores on the device. This data needs to be provided in XML or JSON format that the FusionCharts JavaScript object understands. In this blog post, we will show you how to use FusionCharts XT in an iOS app and power it using data from a web service. We will create the necessary XML and HTML required for the UIWebView to display our chart.</p><h2>Example &#8211; An iOS app to plot Twitter data using FusionCharts XT</h2><p>We will be plotting the count of mentions of &#8216;HTML5&#8242; for each of the last 7 days in a UIWebView control using FusionCharts XT. This is how your chart will finally look like in an iPhone:<br /> <img src="http://blog.fusioncharts.com/wp-content/uploads/2012/02/FusionCharts-XT-in-iPhone-Simulator-156x304.png" alt="" title="FusionCharts XT in iPhone Simulator" width="156" height="304" class="aligncenter size-medium wp-image-2236" /></p><h2>Requirements</h2><ul><li>Xcode 3.2 and above</li><li><a href="http://www.fusioncharts.com/download/trials/" target="_blank">The latest version of FusionCharts XT</a></li><li><a href="https://github.com/johnezang/JSONKit" target="_blank">JSONKit library</a></li><li>You would need to have internet access too. We will be using the <code class="codecolorer html4strict default"><span class="html4strict">searchhistogram</span></code> query from the Topsy API. The exact query is <code class="codecolorer html4strict default"><span class="html4strict">http://otter.topsy.com/searchhistogram.json?q=html5<span style="color: #ddbb00;">&amp;slice=86400&amp;period=7</span></span></code>. You may <a href="http://otter.topsy.com/searchhistogram.json?q=html5&amp;slice=86400&amp;period=7" target="_blank">run this query</a> and see the JSON response, which returns the number of times &#8216;HTML5&#8242; was mentioned everyday for the last 7 days.</li></ul><h2>How we will create the chart</h2><p>To create the chart, we will go through the following steps:</p><ul><li>Create a View-based project in Xcode</li><li>Use <a href="http://code.google.com/p/otterapi/wiki/Resources?tm=6#/searchhistogram" target="_blank">Topsy&#8217;s Otter API</a> to get the count of mentions of &#8216;HTML5&#8242; over the last 7 days</li><li>Use <a href="https://github.com/johnezang/JSONKit" target="_blank">JSONKit</a> to parse through the received JSON response</li><li>Create the XML data for the chart</li><li>Create the HTML required to show the chart</li><li>Enable rotation of the chart according to the device&#8217;s orientation, so that the chart will fit the screen whether the device is in landscape or portrait mode</li></ul><h2>Creating the Xcode project</h2><p>Let us open Xcode and create a View-based project, and save it as <em>FusionChartsXTiOSDemo</em>.</p><p><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/02/Create-a-View-based-project-in-Xcode-304x247.png" alt="" title="Create a View-based project in Xcode" width="304" height="247" class="aligncenter size-medium wp-image-2213" /></p><p>We now need to add FusionCharts XT&#8217;s JavaScript files to our project. Copy the JavaScript files present in <code class="codecolorer html4strict default"><span class="html4strict">Download Package &gt; Charts</span></code> to the Xcode Resources project group. Make sure you select the <code class="codecolorer html4strict default"><span class="html4strict">Copy items into destination group’s folder (if needed)</span></code> checkbox on the top. Doing so would ensure that you have a copy of all the JavaScript files local to your application. Click <code class="codecolorer html4strict default"><span class="html4strict">Add</span></code> to add your files to your project.</p><p>We need to modify Xcode’s compilation step a little bit. Xcode considers JavaScript files as code (rightfully so) and tries to compile them. However, we want these files to render charts inside our UIWebView and not compiled. Expand the <code class="codecolorer html4strict default"><span class="html4strict">Targets</span></code> group and your project target. Our target is called <code class="codecolorer html4strict default"><span class="html4strict">FusionChartsXTiOSDemo</span></code>. Also expand the <code class="codecolorer html4strict default"><span class="html4strict">Copy Bundle Resources</span></code> and <code class="codecolorer html4strict default"><span class="html4strict">Compile Sources</span></code> build phases. Select all the JavaScript filesand drag them from the compile stage to the copy bundle build phase.</p><p><img class="aligncenter size-full wp-image-2214" title="JavaScript files in Copy Bundle" src="http://blog.fusioncharts.com/wp-content/uploads/2012/02/JavaScript-files-in-Copy-Bundle.png" alt="" width="321" height="306" /></p><p>Add the JSONKit files, namely <code class="codecolorer objc default"><span class="objc">JSONKit.h</span></code> and <code class="codecolorer objc default"><span class="objc">JSONKit.m</span></code> to your project too. We have now prepared Xcode with all the files necessary. Let us begin designing and coding!</p><h2>Designing and coding</h2><p>In <code class="codecolorer objc default"><span class="objc">FusionChartsXTiOSDemo.h</span></code>, add an <code class="codecolorer objc default"><span class="objc">IBOutlet</span></code> for the WebView.<br /> <code class="codecolorer objc default"><span class="objc"><span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> IBOutlet UIWebView <span style="color: #002200;">*</span>webView;</span></code></p><p>Also <code class="codecolorer objc default"><span class="objc"><span style="color: #a61390;">@synthesize</span></span></code>, and <code class="codecolorer objc default"><span class="objc">release</span></code> this accordingly.</p><p>Open your project’s main view controller Interface Builder file (inside the Resources group). For our project this file is called <code class="codecolorer objc default"><span class="objc">FusionChartsXTiOSDemoViewController.xib</span></code>. To add a WebView control to your app, drag a UIWebView from Interface Builder’s library to our view.</p><p><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/02/UIWebView-control-193x304.png" alt="" title="UIWebView control" width="193" height="304" class="aligncenter size-medium wp-image-2217" /></p><p>We now need to connect the UIWebView outlet to this UIWebView. From the Document Window in Interface Builder, Ctrl+Drag from <code class="codecolorer objc default"><span class="objc">File’s Owner</span></code> to the <code class="codecolorer objc default"><span class="objc">UIWebView</span></code>. You should get a popup bubble, click <code class="codecolorer objc default"><span class="objc">webView</span></code> . Save your work and close Interface Builder.</p><p>Next, we will add the required properties needed to create the chart data and its configuration. We will write the following code in <code class="codecolorer objc default"><span class="objc">FusionChartsXTiOSDemo.h</span></code>:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// Chart properties.</span></div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>htmlContent;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>javascriptPath;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>chartData;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>chartType;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> UIInterfaceOrientation currentOrientation;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> CGFloat chartWidth;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> CGFloat chartHeight;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>debugMode;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>registerWithJavaScript;</div></li></ol></div><div class="code-holder-bottom"></div></div><p>Let us also add the properties we require to perform the HTTP request and to handle the response data:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// Twitter data.</span></div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>twitterQuery;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSMutableData</span> <span style="color: #002200;">*</span>twitterData;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, retain<span style="color: #002200;">&#41;</span> <span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>twitterDataDictionary;</div></li><li><div> <span style="color: #a61390;">@property</span> <span style="color: #002200;">&#40;</span>nonatomic, assign<span style="color: #002200;">&#41;</span> <span style="color: #a61390;">BOOL</span> twitterDataError;</div></li></ol></div><div class="code-holder-bottom"></div></div><p>Remember to <code class="codecolorer objc default"><span class="objc"><span style="color: #a61390;">@synthesize</span></span></code> and <code class="codecolorer objc default"><span class="objc">release</span></code> the above properties correctly.</p><p>Declare the following 4 methods here; we will define them later.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>displayDataError;</div></li><li><div> <span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>createChartData<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIInterfaceOrientation<span style="color: #002200;">&#41;</span>interfaceOrientation;</div></li><li><div> <span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>plotChart;</div></li><li><div> <span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>removeChart;</div></li></ol></div><div class="code-holder-bottom"></div></div><p>As a best practice, let us keep our first task to handle any error that might crop up because of connectivity issues. For this, we need define the <code class="codecolorer objc default"><span class="objc">displayDataError</span></code> method. We need to create the HTML that displays the error in plain English to the user in his WebView.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>displayDataError</div></li><li><div> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>displayErrorHTML <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableString</span> stringWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;html&gt;&lt;head&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#91;</span>displayErrorHTML appendString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;title&gt;Chart Error&lt;/title&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#91;</span>displayErrorHTML appendString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;/head&gt;&lt;body&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#91;</span>displayErrorHTML appendString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;p&gt;Unable to plot chart.&lt;br/&gt;Error receiving data from Twitter.&lt;/p&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#91;</span>displayErrorHTML appendString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div>&nbsp;</div></li><li><div> <span style="color: #002200;">&#91;</span>self.webView loadHTMLString<span style="color: #002200;">:</span>displayErrorHTML baseURL<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>We have created the HTML content to be shown in the WebView in case of a network error, or in case the Topsy API is unable to respond. For testing this method, we could simulate a network error either by unplugging the LAN cable or turning off the WiFi. When you&#8217;ve done either of these, run the project, and this is the error that you should see:<br /> <img src="http://blog.fusioncharts.com/wp-content/uploads/2012/02/Displaying-the-error-in-the-WebView-156x304.png" alt="" title="Displaying the error in the WebView" width="156" height="304" class="aligncenter size-medium wp-image-2246" /></p><p>After this, let us concern ourselves with the HTTP query and handling it&#8217;s JSON response.</p><p>Uncomment the <code class="codecolorer objc default"><span class="objc">viewDidLoad</span></code> method, and create and execute the query to Topsy&#8217;s API:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #11740a; font-style: italic;">// Setting up the Twitter query.</span></div></li><li><div> &nbsp; self.twitterQuery <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;http://otter.topsy.com/searchhistogram.json?q=html5&amp;slice=86400&amp;period=7&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #400080;">NSURLRequest</span> <span style="color: #002200;">*</span>request <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLRequest</span> requestWithURL<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> URLWithString<span style="color: #002200;">:</span>self.twitterQuery<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span>connection <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURLConnection</span> alloc<span style="color: #002200;">&#93;</span> initWithRequest<span style="color: #002200;">:</span>request delegate<span style="color: #002200;">:</span>self<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp;</div></li><li><div> &nbsp; <span style="color: #11740a; font-style: italic;">// Check whether we have a valid connection.</span></div></li><li><div> &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>connection<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Create the NSMutableData to hold the received data.</span></div></li><li><div> &nbsp; &nbsp; self.twitterData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableData</span> data<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Error in receiving data.</span></div></li><li><div> &nbsp; &nbsp; self.twitterDataError <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#125;</span></div></li><li><div>&nbsp;</div></li><li><div> &nbsp; <span style="color: #11740a; font-style: italic;">// Done using the connection.</span></div></li><li><div> &nbsp; <span style="color: #002200;">&#91;</span>connection release<span style="color: #002200;">&#93;</span>;</div></li></ol></div><div class="code-holder-bottom"></div></div><p>Now that we have made the connection, we need to prepare the 4 delegates of <code class="codecolorer objc default"><span class="objc"><span style="color: #400080;">NSURLConnection</span></span></code>.</p><p>We should reset all previous data each time we receive a message at <code class="codecolorer objc default"><span class="objc">connection<span style="color: #002200;">:</span>didReceiveResponse</span></code>.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection didReceiveResponse<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLResponse</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>response</div></li><li><div> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// This method is called when the server has determined that it</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// has enough information to create the NSURLResponse.</span></div></li><li><div> &nbsp;</div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// It can be called multiple times, for example in the case of a</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// redirect, so each time we reset the data.</span></div></li><li><div> &nbsp;</div></li><li><div> &nbsp; <span style="color: #11740a; font-style: italic;">// (Re)Initialize the Twitter data store.</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.twitterData setLength<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>Let us implement the delegate that stores the newly sent data.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection didReceiveData<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>data</div></li><li><div> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Store received data.</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.twitterData appendData<span style="color: #002200;">:</span>data<span style="color: #002200;">&#93;</span>;</div></li><li><div> <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>If NSURLConnection returns an error while loading the data, let us explain it in plain English to the user using our own method <code class="codecolorer objc default"><span class="objc">displayDataError</span></code>.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connection<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection didFailWithError<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>error</div></li><li><div> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; <span style="color: #11740a; font-style: italic;">// Display an error on connection failure.</span></div></li><li><div> &nbsp; <span style="color: #002200;">&#91;</span>self displayDataError<span style="color: #002200;">&#93;</span>;</div></li><li><div> <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>Finally, using JSONKit, let us convert the data stored in <code class="codecolorer objc default"><span class="objc">self.twitterData</span></code> to a dictionary. Once the data has been converted, we call the <code class="codecolorer objc default"><span class="objc">createChartData<span style="color: #002200;">::</span><span style="color: #002200;">&#40;</span>UIInterfaceOrientation<span style="color: #002200;">&#41;</span>interfaceOrientation</span></code> method.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>connectionDidFinishLoading<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSURLConnection</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>connection</div></li><li><div> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; <span style="color: #11740a; font-style: italic;">// Convert received JSON data to an Objective-C dictionary.</span></div></li><li><div> &nbsp; self.twitterDataDictionary <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.twitterData objectFromJSONData<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp;</div></li><li><div> &nbsp; <span style="color: #11740a; font-style: italic;">// Create chart as per current orientation.</span></div></li><li><div> &nbsp; self.currentOrientation <span style="color: #002200;">=</span> self.interfaceOrientation;</div></li><li><div> &nbsp; <span style="color: #002200;">&#91;</span>self createChartData<span style="color: #002200;">:</span>self.currentOrientation<span style="color: #002200;">&#93;</span>;</div></li><li><div> <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>In the <code class="codecolorer objc default"><span class="objc">createChartData<span style="color: #002200;">::</span><span style="color: #002200;">&#40;</span>UIInterfaceOrientation<span style="color: #002200;">&#41;</span>interfaceOrientation</span></code> method, we need to parse through the dictionary and form our XML. Note that the dictionary has two keys named <code class="codecolorer objc default"><span class="objc">request</span></code> and <code class="codecolorer objc default"><span class="objc">response</span></code>. Within <code class="codecolorer objc default"><span class="objc">response</span></code>, there is an array named <code class="codecolorer objc default"><span class="objc">histogram</span></code>, which holds the count of mentions of &#8216;HTML5&#8242; for the last 7 days. We need to get hold of this array in <code class="codecolorer objc default"><span class="objc"><span style="color: #400080;">NSArray</span></span></code>.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>createChartData<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIInterfaceOrientation<span style="color: #002200;">&#41;</span>interfaceOrientation</div></li><li><div> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; <span style="color: #11740a; font-style: italic;">// Check whether we have valid data.</span></div></li><li><div> &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self.twitterDataError<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self displayDataError<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Valid data.</span></div></li><li><div> &nbsp; &nbsp; &nbsp; &nbsp;</div></li><li><div> &nbsp; &nbsp; self.chartWidth <span style="color: #002200;">=</span> <span style="color: #2400d9;">300</span>;</div></li><li><div> &nbsp; &nbsp; self.chartHeight <span style="color: #002200;">=</span> <span style="color: #2400d9;">440</span>;</div></li><li><div>&nbsp;</div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Setup chart XML.</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #400080;">NSDictionary</span> <span style="color: #002200;">*</span>responseData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self.twitterDataDictionary objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;response&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>histogramData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>responseData objectForKey<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;histogram&quot;</span><span style="color: #002200;">&#93;</span>;</div></li></ol></div><div class="code-holder-bottom"></div></div><p>We continue the same code block to iterate through <code class="codecolorer objc default"><span class="objc">histogramData</span></code> and form the chart data in XML. Since the numbers in the array are for the previous 7 days, starting from yesterday, we need to calculate and format the date accordingly.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; self.chartData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableString</span> <span style="color: #a61390;">string</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.chartData appendFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;chart caption='Twitter mentions of HTML5' subCaption='In the last 7 days' showValues='0'&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #400080;">NSDateFormatter</span> <span style="color: #002200;">*</span>dateFormatter <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDateFormatter</span> alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>dateFormatter setDateStyle<span style="color: #002200;">:</span>NSDateFormatterShortStyle<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; <span style="color: #002200;">&#91;</span>histogramData count<span style="color: #002200;">&#93;</span>; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.chartData appendFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;set label='%@' value='%@' /&gt;&quot;</span>, <span style="color: #002200;">&#91;</span>dateFormatter stringFromDate<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSDate</span> dateWithTimeIntervalSinceNow<span style="color: #002200;">:-</span><span style="color: #002200;">&#40;</span>i<span style="color: #002200;">+</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">*</span><span style="color: #2400d9;">86400</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&#91;</span>histogramData objectAtIndex<span style="color: #002200;">:</span>i<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#125;</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.chartData appendFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;/chart&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>dateFormatter release<span style="color: #002200;">&#93;</span>;</div></li></ol></div><div class="code-holder-bottom"></div></div><p>In the same code block, we create the HTML required to show the chart. Note the path of <code class="codecolorer html4strict default"><span class="html4strict">FusionCharts.js</span></code> in the <code class="codecolorer html4strict default"><span class="html4strict"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span>&gt;</span></span></code> tag. We will provide the base URL when we actually load the HTML in the WebView.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Setup chart HTML.</span></div></li><li><div> &nbsp; &nbsp; self.htmlContent <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@&quot;</span>, <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;html&gt;&lt;head&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.htmlContent appendString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;script type='text/javascript' src='FusionCharts.js'&gt;&lt;/script&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.htmlContent appendString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;/head&gt;&lt;body&gt;&lt;div id='chart_container'&gt;Chart will render here.&lt;/div&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.htmlContent appendString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;script type='text/javascript'&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.htmlContent appendFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;var chart_object = new FusionCharts('Column3D.swf', 'twitter_data_chart', '%f', '%f', '0', '1');&quot;</span>, self.chartWidth, self.chartHeight<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.htmlContent appendFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;chart_object.setXMLData(<span style="color: #2400d9;">\&quot;</span>%@<span style="color: #2400d9;">\&quot;</span>);&quot;</span>, self.chartData<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.htmlContent appendString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;chart_object.render('chart_container');&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self.htmlContent appendString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;/script&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li></ol></div><div class="code-holder-bottom"></div></div><p>Finally, we send the <code class="codecolorer objc default"><span class="objc">plotChart</span></code> message to <code class="codecolorer objc default"><span class="objc">self</span></code>.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Draw the actual chart.</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self plotChart<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#125;</span></div></li><li><div> <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>Thereafter, we will define the <code class="codecolorer objc default"><span class="objc">plotChart</span></code> method. In this method we will provide the <code class="codecolorer objc default"><span class="objc">baseURL</span></code>, and load the HTML string we created.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>plotChart</div></li><li><div> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; <span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>baseURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSURL</span> fileURLWithPath<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithFormat<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;%@&quot;</span>, <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> bundlePath<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#91;</span>self.webView loadHTMLString<span style="color: #002200;">:</span>self.htmlContent baseURL<span style="color: #002200;">:</span>baseURL<span style="color: #002200;">&#93;</span>;</div></li><li><div> <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>Run this project in the iPhone Simulator, you would get the following chart:<br /> <img class="aligncenter size-full wp-image-2236" title="FusionCharts XT in iPhone Simulator" src="http://blog.fusioncharts.com/wp-content/uploads/2012/02/FusionCharts-XT-in-iPhone-Simulator.png" alt="" width="368" height="716" /></p><h2>Making FusionCharts aware of the orientation</h2><p>However, our work here is not done yet. We still need to add orientation support to this project.</p><p>Let us override the default value to allow autorotation according to the orientation.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// Override to allow orientations other than the default portrait orientation.</span></div></li><li><div> <span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">BOOL</span><span style="color: #002200;">&#41;</span>shouldAutorotateToInterfaceOrientation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIInterfaceOrientation<span style="color: #002200;">&#41;</span>interfaceOrientation <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Return YES since we support all orientations.</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #a61390;">YES</span>;</div></li><li><div> <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>We need to dispose of the chart before we render it again according to the new orientation. To do this, we can can empty <code class="codecolorer html4strict default"><span class="html4strict">chart_container</span></code> of all the HTML. Let us write the <code class="codecolorer objc default"><span class="objc">removeChart</span></code> method to do this.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>removeChart</div></li><li><div> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>emptyChartContainer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&lt;script type='text/javascript'&gt;document.getElementById('chart_container').innerHTML='';&lt;/script&gt;&quot;</span><span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#91;</span>self.webView stringByEvaluatingJavaScriptFromString<span style="color: #002200;">:</span>emptyChartContainer<span style="color: #002200;">&#93;</span>;</div></li><li><div> <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>Next, we need to know exactly when the device <em>begins</em> to rotate. For this, we have the <code class="codecolorer objc default"><span class="objc"><span style="color: #002200;">&#41;</span>willRotateToInterfaceOrientation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIInterfaceOrientation<span style="color: #002200;">&#41;</span>toInterfaceOrientation duration<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSTimeInterval<span style="color: #002200;">&#41;</span>duration</span></code> class method. In this method, we will first check if the data is valid; so that an error message will be displayed even upon rotation. Next, we store the orientation to which the device is rotating to. Then we remove the chart and render it again according to the new orientation.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">// Handle interface rotation.</span></div></li><li><div> <span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>willRotateToInterfaceOrientation<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>UIInterfaceOrientation<span style="color: #002200;">&#41;</span>toInterfaceOrientation duration<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>NSTimeInterval<span style="color: #002200;">&#41;</span>duration</div></li><li><div> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; <span style="color: #11740a; font-style: italic;">// Check whether we have valid data.</span></div></li><li><div> &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self.twitterDataError<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self displayDataError<span style="color: #002200;">&#93;</span>;&nbsp; &nbsp;</div></li><li><div> &nbsp; <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Valid data.</span></div></li><li><div> &nbsp; &nbsp;</div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Store new orientation.</span></div></li><li><div> &nbsp; &nbsp; self.currentOrientation <span style="color: #002200;">=</span> toInterfaceOrientation;</div></li><li><div> &nbsp; &nbsp;</div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Remove existing chart and recreating it</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// as per the new orientation.</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self removeChart<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>self createChartData<span style="color: #002200;">:</span>self.currentOrientation<span style="color: #002200;">&#93;</span>;</div></li><li><div> &nbsp; <span style="color: #002200;">&#125;</span></div></li><li><div> <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>In the <code class="codecolorer objc default"><span class="objc">createChart</span></code> method, we need to supply the new chart dimensions to the FusionCharts object according to the orientation. So let us add the following code just before the block where we create the chart XML:</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container objc default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><ol style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;" style='margin-left:30px;'><li><div><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Set chart width and height depending on the screen's orientation.</span></div></li><li><div> &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>interfaceOrientation <span style="color: #002200;">==</span> UIInterfaceOrientationPortrait || interfaceOrientation <span style="color: #002200;">==</span> UIInterfaceOrientationPortraitUpsideDown<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; &nbsp; self.chartWidth <span style="color: #002200;">=</span> <span style="color: #2400d9;">300</span>;</div></li><li><div> &nbsp; &nbsp; &nbsp; self.chartHeight <span style="color: #002200;">=</span> <span style="color: #2400d9;">440</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#125;</span> <span style="color: #a61390;">else</span> <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>interfaceOrientation <span style="color: #002200;">==</span> UIInterfaceOrientationLandscapeLeft || interfaceOrientation <span style="color: #002200;">==</span> UIInterfaceOrientationLandscapeRight<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span></div></li><li><div> &nbsp; &nbsp; &nbsp; self.chartWidth <span style="color: #002200;">=</span> <span style="color: #2400d9;">440</span>;</div></li><li><div> &nbsp; &nbsp; &nbsp; self.chartHeight <span style="color: #002200;">=</span> <span style="color: #2400d9;">280</span>;</div></li><li><div> &nbsp; &nbsp; <span style="color: #002200;">&#125;</span></div></li></ol></div><div class="code-holder-bottom"></div></div><p>Let us now run this project. Rotate your iPhone Simulator by ⌘+Left Arrow or ⌘+Right Arrow.<br /> <img class="aligncenter size-large wp-image-2239" title="FusionCharts XT in iPhone Simulator with orientation support - Landscape mode" src="http://blog.fusioncharts.com/wp-content/uploads/2012/02/FusionCharts-XT-in-iPhone-Simulator-with-orientation-support-Landscape-mode-616x316.png" alt="" width="616" height="316" /></p><h2>Download sample project</h2><p>The sample project that we created is available for download. We used Xcode 3.2 and the target was iOS 4.2.<br /> <a href="http://blog.fusioncharts.com/wp-content/uploads/2012/02/FusionChartsXTiOSDemo.zip"><img src="http://blog.fusioncharts.com/wp-content/uploads/2012/02/Download_Sample_Code.png" alt="" title="Download the sample Xcode project" width="257" height="100" class="aligncenter size-full wp-image-2283" /></a></p><h2>Taking it further</h2><p>You can expand on this project by using the other chart types provided by FusionCharts. You can interface with a database on the backend, and provide a UI to create the SQL queries in the WebView itself. You could make use of the Spark Line charts provided in FusionWidgets XT and create a dashboard for your iPhone and iPad users. Drill-down charts are also super easy to create. The field is open for experimentation. Do share your implementations with us.</p><div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2010/09/fusioncharts-is-now-ipad-ready/' rel='bookmark' title='FusionCharts is now iPad ready!'>FusionCharts is now iPad ready!</a></li><li><a href='http://blog.fusioncharts.com/2012/03/javascript-charts-in-php-using-fusioncharts-xt-part-1/' rel='bookmark' title='JavaScript charts in PHP using FusionCharts XT &#8211; Part 1'>JavaScript charts in PHP using FusionCharts XT &#8211; Part 1</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://blog.fusioncharts.com/2012/02/create-charts-for-iphone-and-ipad-apps-using-fusioncharts-xt/feed/</wfw:commentRss> <slash:comments>4</slash:comments> </item> <item><title>Generate chart images on the server using FusionCharts</title><link>http://blog.fusioncharts.com/2012/02/generate-chart-images-on-the-server-using-fusioncharts/</link> <comments>http://blog.fusioncharts.com/2012/02/generate-chart-images-on-the-server-using-fusioncharts/#comments</comments> <pubDate>Fri, 03 Feb 2012 10:38:03 +0000</pubDate> <dc:creator>Hrishikesh Choudhari</dc:creator> <category><![CDATA[News & Announcements]]></category> <category><![CDATA[export]]></category> <category><![CDATA[image]]></category> <category><![CDATA[open source]]></category><guid isPermaLink="false">http://blog.fusioncharts.com/?p=2087</guid> <description><![CDATA[FusionCharts helps you make kick-ass dashboards that can be viewed on a PC, Mac, iPad, iPhone or a majority of mobile devices. To view these dashboards, you open your favorite browser, go to the URL of the dashboard either by typing in or clicking through, the browser loads the content and FusionCharts, and you finally get to see your interactive dashboards. It all works fine! But, what if your management<div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2009/05/export-your-charts-as-images-or-pdfs/' rel='bookmark' title='Export your charts as images or PDFs'>Export your charts as images or PDFs</a></li></ol></div>]]></description> <content:encoded><![CDATA[<p></p><a href="http://blog.fusioncharts.com/2012/02/generate-chart-images-on-the-server-using-fusioncharts/" title="Link to Generate chart images on the server using FusionCharts"><img class="wppt_float_left" src="http://blog.fusioncharts.com/wp-post-thumbnail/220GbE.jpg" alt="" title="" width="88" height="88" /></a><p>FusionCharts helps you make kick-ass dashboards that can be viewed on a PC, Mac, iPad, iPhone or a majority of mobile devices. To view these dashboards, you open your favorite browser, go to the URL of the dashboard either by typing in or clicking through, the browser loads the content and FusionCharts, and you finally get to see your interactive dashboards. It all works fine! But, what if your management asks you to deliver the dashboard through email at the end of each day, so that they do not have to remember to visit the dashboard?<br /> <span id="more-2087"></span><br /> While you try and explain them that they&#8217;ll lose all the interactivity in the dashboard like drill-down, slicing and tool-tips, which they&#8217;re used to in the web version, they still want to be able to see elements like tables and charts in their email. This lands you into another problem. While tables and other HTML elements can be easily rendered in an email, the charts in that are rendered through JavaScript in a browser would not render in an email client, owing to security reasons. So, the only option you have is to convert these charts to images, server-side, before the email is composed. In this post, we will explore how to achieve this using a community plugin &#8211; <a href="http://fcimg.org/">FCImg</a>.</p><h2>What is <em>FCImg</em>?</h2><p><em>FCImg</em> is a free PHP library that allows you to generate PNG and JPEG images of your charts on the server, without even rendering the chart in a browser. It renders the JavaScript version of FusionCharts at the server and and then internally uses the open-source <a href="http://code.google.com/p/wkhtmltopdf/downloads/detail?name=wkhtmltoimage-0.11.0_rc1-static-i386.tar.bz2">wkhtmltoimage</a> shell utility to convert the charts to images. See live generation of chart images at <a href="http://fcimg.org/#gallery">FCimg gallery</a>.</p><p><img src="http://blog.fusioncharts.com/wp-content/uploads/2011/11/samples-616x611.png" alt="FCImg Gallery" title="FCImg Gallery" width="616" height="611" class="aligncenter size-large wp-image-2088" /></p><p>The chart images generated by <em>FCImg</em> could be used in the following scenarios:</p><ul><li>When you need to email dashboards or reports containing FusionCharts</li><li>When you need to build PDFs of reports or dashboards and embed FusionCharts</li><li>When you need to render images of charts on devices that do not support both Flash or JavaScript</li></ul><h2>Setting up <em>FCImg</em></h2><p>To get <em>FCImg</em> for your server, choose the right variant from the list below:</p><ul><li><a href="http://fcimg.org/release/fcimg-0.1.3-windows.zip">Windows (32 Bit &#038; 64 Bit)</a> [8.9 MB] [ZIP]</li><li><a href="http://fcimg.org/release/fcimg-0.1.3-linux32bit.tar.gz">Linux (32 Bit)</a> [10 MB] [tar.gz]</li><li><a href="http://fcimg.org/release/fcimg-0.1.3-linux64bit.tar.gz">Linux (64 Bit)</a> [10 MB] [tar.gz]</li></ul><p>The system requirements to run <em>FCImg</em> are:</p><ul><li>Linux or Windows operating systems. Shared hosts are also supported. <code class="codecolorer bash default"><span class="bash">safe_mode</span></code> should not be enabled. (Note that <code class="codecolorer bash default"><span class="bash">safe_mode</span></code> is deprecated and disabling it is highly recommended. Most hosts disable <code class="codecolorer bash default"><span class="bash">safe_mode</span></code> by default).</li><li>PHP 5.2 or above.</li></ul><p>After downloading the appropriate variant, extract the package to a path on your server that is accessible by your PHP Scripts. You will find that there is only one folder &#8211; <code class="codecolorer javascript default"><span class="javascript">fcimg</span></code>. Inside this folder, you will find a <code class="codecolorer javascript default"><span class="javascript"><span style="color: #339933;">/</span>bin</span></code> sub-folder, <code class="codecolorer javascript default"><span class="javascript">fcimg.<span style="color: #660066;">php</span></span></code> and <code class="codecolorer javascript default"><span class="javascript">template.<span style="color: #660066;">txt</span></span></code>. Next, you will need to set the right permission for the <code class="codecolorer javascript default"><span class="javascript"><span style="color: #339933;">/</span>bin</span></code> folder contained within this folder. On Linux systems, the contents of <code class="codecolorer javascript default"><span class="javascript"><span style="color: #339933;">/</span>bin</span></code> needs to be executable. If you downloaded and extract the files directly on the server, the file permissions are already set. However, if you transferred the files using FTP, then you need to set the permissions manually using this command from the directory where you extracted fcimg:</p><p><code class="codecolorer bash default"><span class="bash"><span style="color: #c20cb9; font-weight: bold;">chmod</span> +x fcimg<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/*</span></span></code></p><h2>Using <em>FCImg</em></h2><p>Using <em>FCImg</em> is fairly simple. You include the <code class="codecolorer php default"><span class="php">fcimg<span style="color: #339933;">.</span>php</span></code> file and invoke <code class="codecolorer php default"><span class="php">fusioncharts_to_image</span></code> function with a bunch of parameters, as listed and explained below.</p><div class="codeHolder"><div class="code-holder-top"></div><div class="codecolorer-container php default" style="border:1px solid #9F9F9F;width:435px;height:auto;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">require</span> <span style="color: #0000ff;">&quot;fcimg/fcimg.php&quot;</span><span style="color: #339933;">;</span><br /> fusioncharts_to_image <span style="color: #009900;">&#40;</span><br /> &nbsp; &nbsp; <span style="color: #0000ff;">&quot;/var/www/report.png&quot;</span><span style="color: #339933;">,</span>&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Full path to output image, including name.</span><br /> &nbsp; &nbsp; <span style="color: #0000ff;">&quot;Column3D.swf&quot;</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// SWF Alias of chart. Note: SWF File is NOT required. </span><br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// It's just a pointer to which chart type to render.</span><br /> &nbsp; &nbsp; <span style="color: #000088;">$inputString</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// The input XML data string for the chart</span><br /> &nbsp; &nbsp; <span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Height and width of the chart</span><br /> &nbsp; &nbsp; <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Additional options for conversion</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'imageType'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'jpg'</span><span style="color: #339933;">,</span> &nbsp; <span style="color: #666666; font-style: italic;">// Setting image type as JPG</span><br /> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'quality'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">75</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Increase output quality</span><br /> <span style="color: #009900;">&#41;</span><br /> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div><div class="code-holder-bottom"></div></div><p>The <code class="codecolorer php default"><span class="php">fusioncharts_to_image</span></code> method takes the following arguments, listed in order:</p><ul><li> <code class="codecolorer php default"><span class="php">outputFilePath</span></code>: The full path to the output image. If this file already exists, it will be overwritten.</li><li> <code class="codecolorer php default"><span class="php">swfName</span></code>: The FusionCharts SWF filename which will be used to determine which type of chart to render.</li><li> <code class="codecolorer php default"><span class="php">inputString</span></code>: The Data String in XML or JSON format. Note that the converter will automatically determine whether the input is XML or JSON.</li><li> <code class="codecolorer php default"><span class="php">height</span></code>: The height of the chart in pixels.</li><li> <code class="codecolorer php default"><span class="php">width</span></code>: The width of the chart in pixels.</li><li> <code class="codecolorer php default"><span class="php">options</span></code>: This is an array to configure optional parameters. This is treated as a key-value set.<ul><li><code class="codecolorer php default"><span class="php"><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;imageType&quot;</span></span></code>]: Specifies the type of the image (png/jpg). Default: png.</li><li><code class="codecolorer php default"><span class="php"><span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;quality&quot;</span></span></code>]: The Image quality (0-100). Note that a higher quality might take longer to render. Default: 70.</li></ul></li></ul><p>When you now run this script on your server, you will find the output chart image file <code class="codecolorer text default"><span class="text">report.png</span></code> under <code class="codecolorer bash default"><span class="bash"><span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www</span></code> folder of your server.</p><h2>What happened behind the scenes?</h2><p>When this script executed, the following actions happened behind the scenes:</p><ul><li><em>FCImg</em> created a HTML file, which included the FusionCharts XT JavaScript files (the evaluation version is stored in <code class="codecolorer javascript default"><span class="javascript">template.<span style="color: #660066;">txt</span></span></code>), and the data in XML or JSON. If you opened this file in a regular browser, you would see this chart.</li><li>It created a virtual Webkit browser and opened the generated HTML file inside that browser.</li><li>It waited 1500 milliseconds for the animations to complete.</li><li>It captured the image on this virtual Webkit browser, converted that into image using <em>wkhtmltoimage</em>, and saved it at the path provided.</li></ul><p><em>FCImg</em> takes a couple of seconds to export a single chart on a basic server. This delay is intended because the default animations of FusionCharts take up to 1.5 seconds to complete on certain charts. The <code class="codecolorer php default"><span class="php">fusioncharts_to_image</span></code> function is a blocking call. It means that the PHP script will not continue until the rendering process is complete (unlike event based callback systems). It is best to call this method in PHP scripts that run on the server directly and do not serve output to browsers e.g., in a script that generates emailed reports, or a script that is executed through a cron-job.</p><h2>Changing the FusionCharts JavaScript library used in <em>FCImg</em></h2><p>By default, <em>FCImg</em> ships with an evaluation copy of FusionCharts JavaScript version, which is not the latest as well. To update to the latest, or even point to your licensed copy of FusionCharts JavaScript, you will need to do the following changes:</p><ul><li>Remove the contents of <code class="codecolorer javascript default"><span class="javascript">template.<span style="color: #660066;">txt</span></span></code> found in the <code class="codecolorer javascript default"><span class="javascript">fcimg</span></code> directory</li><li>Add all the code from <code class="codecolorer javascript default"><span class="javascript">jquery.<span style="color: #660066;">min</span>.<span style="color: #660066;">js</span></span></code> to <code class="codecolorer javascript default"><span class="javascript">template.<span style="color: #660066;">txt</span></span></code></li><li>Add all the code from <code class="codecolorer javascript default"><span class="javascript">FusionCharts.<span style="color: #660066;">js</span></span></code> to <code class="codecolorer javascript default"><span class="javascript">template.<span style="color: #660066;">txt</span></span></code></li><li>Add all the code from <code class="codecolorer javascript default"><span class="javascript">FusionCharts.<span style="color: #660066;">HC</span>.<span style="color: #660066;">js</span></span></code> to <code class="codecolorer javascript default"><span class="javascript">template.<span style="color: #660066;">txt</span></span></code></li><li>Add all the code from <code class="codecolorer javascript default"><span class="javascript">FusionCharts.<span style="color: #660066;">HC</span>.<span style="color: #660066;">Charts</span>.<span style="color: #660066;">js</span></span></code> to <code class="codecolorer javascript default"><span class="javascript">template.<span style="color: #660066;">txt</span></span></code></li></ul><p>Note that the order of files added is important.</p><h2>Getting on with it</h2><p>Do give <em>FCImg</em> a spin. It&#8217;s useful. It&#8217;s free. And if you encounter some painful situations, give a shout to the developer at <a href="mailto:contact@fcimg.org">contact@fcimg.org</a>. It will help if you include details like the XML/JSON data.</p><div class="footNotes m0"><h3>Related posts:</h3><ol><li><a href='http://blog.fusioncharts.com/2009/05/export-your-charts-as-images-or-pdfs/' rel='bookmark' title='Export your charts as images or PDFs'>Export your charts as images or PDFs</a></li></ol></div>]]></content:encoded> <wfw:commentRss>http://blog.fusioncharts.com/2012/02/generate-chart-images-on-the-server-using-fusioncharts/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 12/115 queries in 0.134 seconds using disk: basic
Object Caching 14675/14777 objects using disk: basic

Served from: blog.fusioncharts.com @ 2012-04-12 10:39:45 -->
