FusionCharts XT with ASP.NET is a new series in which we walk you through the fundamentals of creating a Javascript Interactive Graph with your.NET skills. FusionCharts is the industry’s most popular enterprise-grade JavaScript charting solution. Our enterprise customers have endorsed our products and services, and we are constantly adding newer products and features to our solution. FusionCharts Suite meets all of your charting needs, whether they are simple column or pie charts, gauges, advanced zoom and scroll charts, or specialized financial charts. All of the charts include interactive features such as tooltips, drill-downs, and exporting as an image, PDF, or CSV. We’re also iPhone and iPad ready!
With FusionCharts XT, you can leverage your .NET skills to create JavaScript charts. We provide a .NET library that generates all the HTML and JavaScript required to create charts. If you’re looking for a ASP.NET plugin that comes with event support for mouse, keyboard, and more, enabling you to add charts in runtime during any lifecycle phase of the application. Try the ASP.NET Plugin for FusionCharts and download it for free!
Table of Contents
FusionCharts XT with ASP.NET
- Part 1 – Create JavaScript charts in ASP.NET (C#)
- Part 2 – Plot JavaScript charts using SQL Server data
- Part 3 – Create Drill-Down charts in ASP.NET(C#)
- Part 4 – Create LinkedCharts in ASP.NET(C#)
The chart below shows data of Top 5 Employees of a fictitious company.
In this tutorial, we will create the same chart using the .NET library.
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 XML or JSON.
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 FusionCharts XT Download Package > Code > CS > Bin > FusionCharts.dll. By referencing this library, rendering charts is just one line of code! Let us see how..
We will be using Visual Studio 2010 for this series. Visual Studio 2008 or Visual Web Developer will suit fine too.
FusionChartsXT_with_ASPNET.Solution Explorer > Add New Item > Web Form. Keep the name as Default.aspx.Charts folder from the FusionCharts Download Package and paste it in the Solution Explorer.Default.aspx: <script src="Charts/FusionCharts.js" type="text/javascript"></script>
Solution Explorer > Add Reference > Browse. Now browse to FusionCharts XT Download Package > Code > CS > Bin > FusionCharts.dll.Default.aspx.cs, include the namespace of this library by writing using InfoSoftGlobal;
The above steps are necessary whenever you want to use FusionCharts XT in a .NET project.
Next, there are 2 ways by which you can supply data to your charts – the Data URL method and the Data String method. Let us try each one of them.
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., /path_to/data_provider.aspx, which will execute queries on the database, construct the XML data and output it to the stream, with content type set to text/xml. For this example, we will point FusionCharts XT to an XML file’s URL.
Create a Literal tag in Default.aspx, and give it a unique ID.
We will write the code required to generate a chart to this literal. Then, FusionCharts.js would process this code and show a chart instead.
In Default.aspx.cs, within the Page_Load method, write the following code:
// Set the rendering mode to "javascript". (Default is "flash")
FusionCharts.SetRenderer("javascript");
literal_1.Text = FusionCharts.RenderChart("FusionChartsXT/Column2D.swf", "Data/Data.xml", "", "browser_share", "640", "340", false, true);
Save. Run the project (F5). This is the chart that you should see:
You were able to render a chart in your .NET app with just one single line!
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:
In the Data String 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.
Let us create a chart using the Data String method below the first chart.
Create another Literal tag with ID as literal_2. In the code-behind, comment the line of the RenderChart() method, and write the following code after it:
// xmlStr contains the XML data required for the chart
String xmlStr = "";
// Set rendering mode to "javascript".
FusionCharts.SetRenderer("javascript");
literal_2.Text = FusionCharts.RenderChart("FusionChartsXT/Column2D.swf", "", xmlStr, "browser_share_2", "640", "340", false, true);
Save. Run the project (F5). You should see the following chart: // < ![CDATA[
// < ![CDATA[
// < ![CDATA[
// < ![CDATA[
FusionCharts.setCurrentRenderer('javascript');
var myChartId = 'browser_share_3';
var myChartSWF = '/Assets/fusioncharts/Column2D.swf';
var myChartWidth = '660';
var myChartHeight = '400';
document.write('‘);
var chartObj = new FusionCharts( myChartSWF, myChartId, myChartWidth, myChartHeight);
chartObj.setXMLData(”);
chartObj.render(myChartId + ‘container’);
// ]]>
JSON is another format that FusionCharts XT supports. If you want to provide data in JSON, simply write the following line before the RenderChart() method:
FusionCharts.SetDataFormat("json");
We provide a tool to convert XML to JSON. You can find it in FusionCharts XT Download Package > Tools > FCDataConverter. The JSON data for the above chart is:
{
"chart": {
"caption": "Top 5 Employees for 2011",
"palette": "3",
"showvalues": "0",
"numberprefix": "$",
"useroundedges": "1"
},
"data": [
{
"label": "Leverling",
"value": "100524"
},
{
"label": "Fuller",
"value": "87790"
},
{
"label": "Davolio",
"value": "81898"
},
{
"label": "Peacock",
"value": "76438"
},
{
"label": "Callahan",
"value": "55091"
}
]
}
In the next article, we will create a chart using data from a database. You can head over to our documentation and read on how to use FusionCharts XT to create charts using data from SQL Server. Stay tuned.
You can build complex web applications easily with Angular. But it’s a challenge to present…
JavaScript charts help transform raw data into clear, interactive visualizations that users can easily understand.…
Modern web applications depend on data visualization to transform complex information into clear, actionable insights.…
Data is a big part of modern software. Companies use charts to track sales, monitor…
Every day, businesses get more data than ever before. Looking at endless rows and columns…
Building interactive React charts from scratch can quickly become complicated. It becomes even more challenging…
View Comments
Not working ...=
Can you please let us know the issue faced?
I've downloaded your source code and ran it. But chart isn't displaying. Within the code there is a methoda FusionCharts.RenderChart("FusionChartsXT/Column2D.swf) but the swf file is not there in the folder
Hi Raghu,
The charts SWF files and JavaScript files are not uploaded to the FusionCharts XT folder. As per your requirement, paste the contents of the Charts folder obtained while downloading the package.
Download link:https://www.fusioncharts.com/download/trials/
Hi. i have all the file that are needed, but its not giving output...
its only showing message --- " Loading chart. Please wait "
With out this line " FusionCharts.SetRenderer("javascript");" i'm getting output normally. but i need to render in javascript which is very important. please help me on this issue.
Hi Tarun,
To render a Javascript charts, please ensure FusionCharts.HC.js, FusionCharts.HC.Charts.js and jquery.min.js are present in the same folder as FusionCharts.js.
Hi, I was able to get the XML example working as expected, but when following the steps for the json example, the chart does not render.
I changed the dataUrl from Data/Data.xml to Data/Data.json and set the FusionCharts.SetDataFormat("json") before calling the FusionCharts.RenderChart method. Does something else need to be done?