Gallery
Difference Series
<%@ Page Language="C#" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
<script runat="server">
void Page_Load(Object sender,EventArgs e)
{
Chart.Type = ChartType.Combo;//Horizontal;
Chart.Width = 600;
Chart.Height = 350;
Chart.TempDirectory = "temp";
Chart.Debug = true;
// Demonstrates how a calculated series can be created and placed in a chart area.
// *DYNAMIC DATA NOTE*
// This sample uses random data to populate the chart. To populate
// a chart with database data see the following resources:
// - Classic samples folder
// - Help File > Data Tutorials
// - Sample: features/DataEngine.aspx
SeriesCollection mySC = getRandomData();
ChartArea ca1 = new ChartArea();
ChartArea ca2 = new ChartArea();
ca2.Label.Text = "Difference";
// Create the difference series.
Series diffSeries = mySC[1] - mySC[0];
diffSeries.DefaultElement.Color = Color.Red;
diffSeries.Name = "Difference";
// Iterate the elements and change their colors based on value.
foreach(Element el in diffSeries.Elements)
if(el.YValue > 0)
el.Color = Color.Green;
else
el.Color = Color.Red;
// Add the series and chart areas to the chart.
Chart.SeriesCollection.Add(mySC[0]);
ca1.SeriesCollection.Add(mySC[1]);
ca2.SeriesCollection.Add(diffSeries);
Chart.ExtraChartAreas.Add(ca1, ca2);
}
SeriesCollection getRandomData()
{
SeriesCollection SC = new SeriesCollection();
Random myR = new Random(1);
for(int a = 1; a < 3; a++)
{
Series s = new Series();
s.Name = "Series " + a;
for(int b = 1; b < 16; b++)
{
Element e = new Element();
e.Name = "Element " + b;
e.YValue = myR.Next(50);
s.Elements.Add(e);
}
SC.Add(s);
}
return SC;
}
</script>
</head>
<body>
<div style="text-align:center">
<dotnet:Chart id="Chart" runat="server" Width="568px" Height="344px">
</dotnet:Chart>
</div>
</body>
</html>
<%@ Page Language="vb" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Chart.Type = ChartType.Combo 'Horizontal;
Chart.Width = 600
Chart.Height = 350
Chart.TempDirectory = "temp"
Chart.Debug = True
' Demonstrates how a calculated series can be created and placed in a chart area.
' *DYNAMIC DATA NOTE*
' This sample uses random data to populate the chart. To populate
' a chart with database data see the following resources:
' - Classic samples folder
' - Help File > Data Tutorials
' - Sample: features/DataEngine.aspx
Dim mySC As SeriesCollection = getRandomData()
Dim ca1 As ChartArea = New ChartArea()
Dim ca2 As ChartArea = New ChartArea()
ca2.Label.Text = "Difference"
' Create the difference series.
Dim diffSeries As Series = mySC(1) - mySC(0)
diffSeries.DefaultElement.Color = Color.Red
diffSeries.Name = "Difference"
' Iterate the elements and change their colors based on value.
For Each el As Element In diffSeries.Elements
If el.YValue > 0 Then
el.Color = Color.Green
Else
el.Color = Color.Red
End If
Next el
' Add the series and chart areas to the chart.
Chart.SeriesCollection.Add(mySC(0))
ca1.SeriesCollection.Add(mySC(1))
ca2.SeriesCollection.Add(diffSeries)
Chart.ExtraChartAreas.Add(ca1, ca2)
End Sub
Function getRandomData() As SeriesCollection
Dim SC As SeriesCollection = New SeriesCollection()
Dim myR As Random = New Random(1)
For a As Integer = 1 To 2
Dim s As Series = New Series()
s.Name = "Series " & a
For b As Integer = 1 To 15
Dim e As Element = New Element()
e.Name = "Element " & b
e.YValue = myR.Next(50)
s.Elements.Add(e)
Next b
SC.Add(s)
Next a
Return SC
End Function
</script>
</head>
<body>
<div style="text-align:center">
<dotnet:Chart id="Chart" runat="server" Width="568px" Height="344px">
</dotnet:Chart>
</div>
</body>
</html>
- Sample FilenameDifferenceSeries.aspx
- VersionLegacy (Pre 3.0)
- Uses DatabaseNo