Dev Direct Solution Center

For more information and to buy this product...

How to produce a bar chart with a trend line in ASP.Net

 Note: This solution requires the component to be installed first.
To download the installer, click here

Introduction

The csASPNetGraph component is used to generate the image of a bar graph with a trend line.

Detail

The csASPNetGraph component runs server side in a .aspx script to produce a graph which is streamed to the browser as a GIF image. There are two scripts needed. The first is standard HTML containing an IMG tag which acts as a placeholder for the graph image. The second script produces the image and is called as the URL inside the SRC attribute.

The placeholder script is called "webpage.aspx" and this is the IMG tag:

<img src="bargraph.aspx" width="400" height="300">

The script "bargraph.aspx" is shown next:

<%@ Page language="vb" debug="true" %>
<%@ Import NameSpace = "csASPNetGraphTrial" %>
<%
Response.Buffer = true
Response.Expires = 0
Response.Clear
Dim Graph As New GraphClass

'Add some data
Graph.AddData("Item 1", 17, "ff0000")
Graph.AddData("Item 2", 28, "00ff00")
Graph.AddData("Item 3", 5, "0000ff")
Graph.AddData("Item 4", 10, "ffff00")

'Some general properties
Graph.Title = "Bar graph with trend line"
Graph.BGColor = "eeeeee"
Graph.LabelBGColor = "eeeeee"
Graph.TitleBGColor = "eeeeee"

'Trend line properties
Graph.ShowTrendLine = true
Graph.TrendLineColor = "ff00ff"
Graph.TrendLineWidth = 2
Graph.TrendLineName = "Trend"

'Set the graph type to draw a bar chart
Graph.GraphType = 1

'The graph is streamed in GIF format
Graph.GraphToBrowser(1)
%>

The trial version of csASPNetGraph must be placed in the bin directory for the web application. The namespace is imported as shown.

Passing parameters through the application

This example shows static, hard coded, data values. This is partly for simplicity and partly because the question is not specific about the source of the data. If data needs to be passed into the graph generation script it is possible to include variables in the URL to "bargraph.aspx" and they can be read using Request.QueryString. These variables could be the data values themselves, or a value to identify a database record.

Visit Chestysoft for more information and more samples.