Gallery
XAxis Zoom
<%@ Page Language="C#" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<script runat="server">
void Page_Load(Object sender,EventArgs e)
{
Chart.Type = ChartType.Combo;//Horizontal;
Chart.Size = "800x450";
Chart.TempDirectory = "temp";
// Demonstrates an interactive way to zoom a section of an axis.
Chart.ChartAreaLayout.Mode = ChartAreaLayoutMode.Horizontal;
Chart.DefaultSeries.Type = SeriesType.Line;
Chart.DefaultElement.Marker.Visible = false;
Chart.LegendBox.Orientation = dotnetCHARTING.Orientation.Bottom;
Chart.ChartAreaSpacing = 15;
Chart.ChartArea.Label.Text = "Click any two points on this chart.";
// Add the random data.
SeriesCollection sc = getRandomData();
Chart.SeriesCollection.Add(sc);
// Setup x axis ticks.
Chart.XAxis.TimeScaleLabels.RangeMode = TimeScaleLabelRangeMode.Dynamic;
Chart.XAxis.TimeScaleLabels.Mode = TimeScaleLabelMode.Hidden;
Chart.XAxis.TimeScaleLabels.DayTick.Label.Text = "";
Chart.XAxis.DefaultTick.Label.Font = new Font("Arial",8,FontStyle.Bold);
Chart.XAxis.Orientation = dotnetCHARTING.Orientation.Top;
// Generate the chart.
Bitmap bp = null;
if(Page.Request.Params["x2"] != null || Page.Request.Params["x"] != null)
{// Only generate the chart the first time if necessary.
bp = Chart.GetChartBitmap();
}
// Check if the start and end range is specified
if(Page.Request.Params["x2"] != null && Page.Request.Params["x"] != null)
{
// Get x and y points
int x = Convert.ToInt32( Page.Request.Params["x"]);
int y = Convert.ToInt32(Page.Request.Params["y"]);
int x2 = Convert.ToInt32( Page.Request.Params["x2"]);
int y2 = Convert.ToInt32(Page.Request.Params["y2"]);
// Get the axis values at xy positions.
object va = Chart.XAxis.GetValueAtX(x+","+y);
object va2 = Chart.XAxis.GetValueAtX(x2+","+y2);
if(va != null && va2 != null)
{// If both click positions were valid:
// add a zoom area.
DateTime val = Convert.ToDateTime(va);
DateTime val2 = Convert.ToDateTime(va2);
Chart.XAxis.Markers.Clear();
ChartArea ca = Chart.ChartArea.GetXZoomChartArea(Chart.XAxis, new ScaleRange(val, val2),new Line(Color.LightGreen,DashStyle.Dash));
Chart.ExtraChartAreas.Add(ca);
}
}
else if(Page.Request.Params["y"] != null)
{// If only one click position is available:
// Get the value and draw a line marker.
int x = Convert.ToInt32( Page.Request.Params["x"]);
int y = Convert.ToInt32(Page.Request.Params["y"]);
object va = Chart.XAxis.GetValueAtX(x+","+y);
if(va != null)
{
DateTime val = Convert.ToDateTime(va);
AxisMarker am = new AxisMarker("",Color.Red,val);
Chart.XAxis.Markers.Add(am);
// Pass the current click position with the next click.
imageLabel.Text += "<input type=hidden name=x2 value="+x+">";
imageLabel.Text += "<input type=hidden name=y2 value="+y+">";
}
}
// Generate the chart again.
bp = Chart.GetChartBitmap();
string fileName = Chart.FileManager.SaveImage(bp);
imageLabel.Text += "<input type=image value=\"submit\" border=0 src=\"" +fileName+ "\" ISMAP>";
bp.Dispose();
}
SeriesCollection getRandomData()
{
SeriesCollection SC = new SeriesCollection();
Random myR = new Random(1);
DateTime dt = new DateTime(2006,1,1);
for(int a = 1; a < 2; a++)
{
Series s = new Series();
s.Name = "Series " + a;
for(int b = 1; b < 2051; b++)
{
Element e = new Element();
e.YValue = myR.Next(20)+20;
s.Elements.Add(e);
e.XDateTime = dt = dt.AddDays(1);
}
SC.Add(s);
}
return SC;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
</head>
<body>
<form action="XAxisZoom.aspx" method="get" >
<asp:Label ID="imageLabel2" runat="server"/>
<asp:Label ID="imageLabel" runat="server"/>
</form>
<div style="text-align:center">
<dotnet:Chart id="Chart" runat="server" Width="568px" Height="344px" visible="false">
</dotnet:Chart>
</div>
</body>
</html>
<%@ Page Language="vb" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Chart.Type = ChartType.Combo 'Horizontal;
Chart.Size = "800x450"
Chart.TempDirectory = "temp"
' Demonstrates an interactive way to zoom a section of an axis.
Chart.ChartAreaLayout.Mode = ChartAreaLayoutMode.Horizontal
Chart.DefaultSeries.Type = SeriesType.Line
Chart.DefaultElement.Marker.Visible = False
Chart.LegendBox.Orientation = dotnetCHARTING.Orientation.Bottom
Chart.ChartAreaSpacing = 15
Chart.ChartArea.Label.Text = "Click any two points on this chart."
' Add the random data.
Dim sc As SeriesCollection = getRandomData()
Chart.SeriesCollection.Add(sc)
' Setup x axis ticks.
Chart.XAxis.TimeScaleLabels.RangeMode = TimeScaleLabelRangeMode.Dynamic
Chart.XAxis.TimeScaleLabels.Mode = TimeScaleLabelMode.Hidden
Chart.XAxis.TimeScaleLabels.DayTick.Label.Text = ""
Chart.XAxis.DefaultTick.Label.Font = New Font("Arial",8,FontStyle.Bold)
Chart.XAxis.Orientation = dotnetCHARTING.Orientation.Top
' Generate the chart.
Dim bp As Bitmap = Nothing
If Not Page.Request.Params("x2") Is Nothing OrElse Not Page.Request.Params("x") Is Nothing Then
bp = Chart.GetChartBitmap()
End If
' Check if the start and end range is specified
If Not Page.Request.Params("x2") Is Nothing AndAlso Not Page.Request.Params("x") Is Nothing Then
' Get x and y points
Dim x As Integer = Convert.ToInt32(Page.Request.Params("x"))
Dim y As Integer = Convert.ToInt32(Page.Request.Params("y"))
Dim x2 As Integer = Convert.ToInt32(Page.Request.Params("x2"))
Dim y2 As Integer = Convert.ToInt32(Page.Request.Params("y2"))
' Get the axis values at xy positions.
Dim va As Object = Chart.XAxis.GetValueAtX(x & "," & y)
Dim va2 As Object = Chart.XAxis.GetValueAtX(x2 & "," & y2)
If Not va Is Nothing AndAlso Not va2 Is Nothing Then
' add a zoom area.
Dim val As DateTime = Convert.ToDateTime(va)
Dim val2 As DateTime = Convert.ToDateTime(va2)
Chart.XAxis.Markers.Clear()
Dim ca As ChartArea = Chart.ChartArea.GetXZoomChartArea(Chart.XAxis, New ScaleRange(val, val2),New Line(Color.LightGreen,DashStyle.Dash))
Chart.ExtraChartAreas.Add(ca)
End If
ElseIf Not Page.Request.Params("y") Is Nothing Then
' Get the value and draw a line marker.
Dim x As Integer = Convert.ToInt32(Page.Request.Params("x"))
Dim y As Integer = Convert.ToInt32(Page.Request.Params("y"))
Dim va As Object = Chart.XAxis.GetValueAtX(x & "," & y)
If Not va Is Nothing Then
Dim val As DateTime = Convert.ToDateTime(va)
Dim am As AxisMarker = New AxisMarker("",Color.Red,val)
Chart.XAxis.Markers.Add(am)
' Pass the current click position with the next click.
imageLabel.Text &= "<input type=hidden name=x2 value=" & x & ">"
imageLabel.Text &= "<input type=hidden name=y2 value=" & y & ">"
End If
End If
' Generate the chart again.
bp = Chart.GetChartBitmap()
Dim fileName As String = Chart.FileManager.SaveImage(bp)
imageLabel.Text &= "<input type=image value=""submit"" border=0 src=""" & fileName & """ ISMAP>"
bp.Dispose()
End Sub
Function getRandomData() As SeriesCollection
Dim SC As SeriesCollection = New SeriesCollection()
Dim myR As Random = New Random(1)
Dim dt As DateTime = New DateTime(2006,1,1)
For a As Integer = 1 To 1
Dim s As Series = New Series()
s.Name = "Series " & a
For b As Integer = 1 To 2050
Dim e As Element = New Element()
e.YValue = myR.Next(20)+20
s.Elements.Add(e)
dt = dt.AddDays(1)
e.XDateTime = dt
Next b
SC.Add(s)
Next a
Return SC
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
</head>
<body>
<form action="XAxisZoom.aspx" method="get" >
<asp:Label ID="imageLabel2" runat="server"/>
<asp:Label ID="imageLabel" runat="server"/>
</form>
<div style="text-align:center">
<dotnet:Chart id="Chart" runat="server" Width="568px" Height="344px" visible="false">
</dotnet:Chart>
</div>
</body>
</html>
- Sample FilenameXAxisZoom.aspx
- Version4.0
- Uses DatabaseNo