There are two ways to create an instance of the Chart control manually:
- Using XML tags.
- Using server-side script.
This topic discuss both of these techniques, and provides an overview of their inherent advantages, and disadvantages.
Creating a Chart Instance Using HTML Tags
This method involves using tags in a web form (.aspx page) to define a chart. It can be implemented using a text editor, but is most easily accomplished using Visual Studio .NET.
If you are using Visual Studio .NET, then the installation procedure will add the chart control to the Toolbox. This means that the chart control can be added to a web page, at design-time, either by double-clicking on the chart control icon, or clicking once on the chart control icon and drawing your chart onto the form using the left-mouse button. In either case, Visual Studio .NET will automatically generate the necessary HTML code to create the chart. You can inspect this code by switching from design view to HTML view.
The following example demonstrates the code that Visual Studio creates for you.
<%@ Register Assembly="DundasWebChart" Namespace="Dundas.Charting.WebControl"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
The Register Directive, which is inserted at the top of the page above the tag, specifies several items including:
- The assembly.
- A tag prefix.
- The namespace associated with the tag prefix.
The tags used to instantiate the control, and set its properties, occur within the body of the document. The main tag is the <<strong>dcwc> tag, which is defined in the above mentioned Register Directive.Example The following example demonstrates the code that Visual Studio creates for you.
When your aspx web page is executed at the server, the chart control will get instantiated, and will become available during the Page_Load event. Using this event is the easiest, and most common way to work with the chart at the client.
|When you use this method to create a chart, the code-behind pages can be used to handle numerous events. For simplicity and clarity, we have used the code-behind pages in most of the distributed samples.|
Creating a Chart Instance Using Script
A chart can be created using inline script using the <% %> delimiters. The script is used within the body of the document, and determines the placement of the chart within your web page.
Advantages and Disadvantages
The advantage in using this method to create your chart is that your chart can be dynamically created only when it is needed. This is usually done using an If Then Else statement.
The disadvantage in using this method is that the Design Editor cannot be used to quickly, and easily set the chart's properties, since all properties must be set using server-side code.
The following example demonstrates the process of creating a chart using a script.
|Visual Basic||Copy Code|