Gallery
JS Axis Tick Goal
<%@ Page Language="C#" Description="dotnetCHARTING Component" %>
<%@ Register TagPrefix="dotnet" Namespace="dotnetCHARTING" Assembly="dotnetCHARTING"%>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>.netCHARTING Sample</title>
<script runat="server">
void Page_Load(Object sender,EventArgs e)
{
// Demonstrates a custom tick with JSCharting and adjusting the axis range so it is always visible.
// Set the chart type
Chart.Type = ChartType.Combo;
//Enable JS Charting
Chart.JS.Enabled = true;
// Set the size
Chart.Width = 650;
Chart.Height = 350;
// Set the temp directory
Chart.TempDirectory = "temp";
// Debug mode. ( Will show generated errors if any )
Chart.Debug = false;
//Chart.Title = "My Chart";
// Axis Labels
Chart.XAxis.Label.Text = "X Axis Label";
Chart.YAxis.Label.Text = "Y Axis Label";
Chart.LegendBox.Visible = false;
Chart.DefaultSeries.Type = SeriesType.Line;
//Create a custom tick to add to the Y Axis.
AxisTick at = new AxisTick(80, "Goal");
at.Label.Font = new Font("Arial", 11, FontStyle.Bold);
at.Label.Color = Color.Green;
at.GridLine.Color = Color.Green;
//Adjust axis range to show tick if necessary.
at.IncludeInAxisScale = true;
Chart.YAxis.ExtraTicks.Add(at);
// *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();
// Add the random data.
Chart.SeriesCollection.Add(mySC);
}
SeriesCollection getRandomData()
{
SeriesCollection SC = new SeriesCollection();
DateTime dt = new DateTime(2021, 1, 1);
Random myR = new Random();
for(int a = 1; a < 2; a++)
{
Series s = new Series();
s.Name = "Series " + a;
for(int b = 1; b < 27; b++)
{
Element e = new Element();
e.XDateTime = dt.AddDays(b);
e.YValue = 20+myR.Next(50);
s.Elements.Add(e);
}
SC.Add(s);
}
return SC;
}
</script>
</head>
<body>
<div align="center">
<div align="center">
<dotnet:Chart id="Chart" runat="server"/>
</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" %>
<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)
' Demonstrates a custom tick with JSCharting and adjusting the axis range so it is always visible.
' Set the chart type
Chart.Type = ChartType.Combo
'Enable JS Charting
Chart.JS.Enabled = True
' Set the size
Chart.Width = 650
Chart.Height = 350
' Set the temp directory
Chart.TempDirectory = "temp"
' Debug mode. ( Will show generated errors if any )
Chart.Debug = False
'Chart.Title = "My Chart";
' Axis Labels
Chart.XAxis.Label.Text = "X Axis Label"
Chart.YAxis.Label.Text = "Y Axis Label"
Chart.LegendBox.Visible = False
Chart.DefaultSeries.Type = SeriesType.Line
'Create a custom tick to add to the Y Axis.
Dim at As AxisTick = New AxisTick(80, "Goal")
at.Label.Font = New Font("Arial", 11, FontStyle.Bold)
at.Label.Color = Color.Green
at.GridLine.Color = Color.Green
'Adjust axis range to show tick if necessary.
at.IncludeInAxisScale = True
Chart.YAxis.ExtraTicks.Add(at)
' *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()
' Add the random data.
Chart.SeriesCollection.Add(mySC)
End Sub
Function getRandomData() As SeriesCollection
Dim SC As SeriesCollection = New SeriesCollection()
Dim dt As DateTime = New DateTime(2021, 1, 1)
Dim myR As Random = New Random()
For a As Integer = 1 To 1
Dim s As Series = New Series()
s.Name = "Series " & a
For b As Integer = 1 To 26
Dim e As Element = New Element()
e.XDateTime = dt.AddDays(b)
e.YValue = 20+myR.Next(50)
s.Elements.Add(e)
Next b
SC.Add(s)
Next a
Return SC
End Function
</script>
</head>
<body>
<div align="center">
<div align="center">
<dotnet:Chart id="Chart" runat="server"/>
</div>
</body>
</html>
- Sample FilenameJsAxisTickGoal.aspx
- Version8.4
- Uses DatabaseNo