NetCharts® Server: ASP.NET Toolkit getChartAsImageAndMap Example using C#
This example shows how to utilize the NetCharts Server ASP.NET Toolkit using C# to add an interactive chart to an ASPX page.
Web Form
<%@ Register TagPrefix="ns" Namespace="NetChartsServer" Assembly="NetChartsServer" %>
<%@ Page language="c#" Codebehind="nswebchart.aspx.cs" AutoEventWireup="false" Inherits="cstoolkitexample.nswebchart" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>NetCharts Server .NET Toolkit - NSWebChart Control Example</title>
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<link REL="stylesheet" HREF="styles.css" TYPE="text/css">
</HEAD>
<body>
<p align="center"><a href="http://www.visualmining.com" target="vmwindow"><img border="0" src="images/start-page-illo2.jpg"></a></p>
<P><B>Information:</B><br>
The <I><B>NSWebChart</B></I> control is a custom control that developers can
"drag" onto a WebForm to represent a chart from <STRONG>NetCharts Server</STRONG>.
By setting the properties of the <i><B>NSWebChart</B></i> control a developer
can quickly integrate a chart without the need for an ASP Literal control or
coding. CDX variables can be sent via the <i>Variables</i> property of
the <I><B>NSWebChart</B></I> control. If more control over the chart is
needed, consider using the <i>getChartAsImageAndMap</i> API function.
Click <a href="getChartAsImageAndMap.aspx">here</a> for a example.</P>
<P>The <I><B>NSWebChart</B></I> control uses a Model-II Architecture when producing
chart images. When the <I><B>NSWebChart</B></I> control produces the HTML
elements to include within a page using a Model-II Architecture, the image is
placed within the HTTP Session to be retrieved during the second pass. An HTML <i>img</i>
element is produced and included in the HTML returned from the <I><B>NSWebChart</B></I>
control. The <i>src</i> attribute of the generated <i>img</i> element points to
a location that is able to retrieve the image from the HTTP session and return
it to the browser.
</P>
<P>
Included with the .NET Toolkit is a WebForm, <i>getncsimage.aspx</i>, that can
be used to retrieve the image from the HTTP Session and return it to the
browser. Copy the <i>getncsimage.aspx</i> and <i>getncsimage.aspx.cs</i> files
from the <i>asp.net</i> directory of the toolkit installation into the Web
Application root directory (e.g. C:\InetPub\wwwroot\WebApplication) and import
them into your application before requesting any NetCharts Server chart. </P>
<P><b>Example:</b><br>
<ns:NSWebChart id="NSWebChart1" runat="server" Height="238px" Width="524px" ChartFile="basicbar.cdx"
Project="Examples/Suppliers"></ns:NSWebChart>
</P>
<p><b>Source Code:</b><br>
<span class="code">Hashtable hashTable = NSWebChart1.Variables;<br>
if (hashTable == null) {<br>
hashTable = new Hashtable();<br>
}<br>
hashTable.Add("THETITLE", "Example Chart Using the NSWebChart Control");<br>
NSWebChart1.Variables = hashTable;</span></p>
</body>
</HTML>
Source Code
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace cstoolkitexample
{
/// <summary>
/// Summary description for nswebchart.
/// </summary>
public class nswebchart : System.Web.UI.Page
{
protected NetChartsServer.NSWebChart NSWebChart1;
private void Page_Load(object sender, System.EventArgs e)
{
Hashtable hashTable = NSWebChart1.Variables;
if (hashTable == null) {
hashTable = new Hashtable();
}
hashTable.Add("THETITLE", "Example Chart Using the NSWebChart Control");
NSWebChart1.Variables = hashTable;
}#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);}
#endregion
}
}
![]()



