Skip to content

Commit beb6542

Browse files
Copilotcsharpfritz
andauthored
Add Chart control reference samples to BeforeWebForms (#330)
* Initial plan * Add Chart control samples to BeforeWebForms project Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com> * Add documentation for Chart control samples Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csharpfritz <78577+csharpfritz@users.noreply.github.com>
1 parent 8e555f1 commit beb6542

14 files changed

+602
-0
lines changed

samples/BeforeWebForms/BeforeWebForms.csproj

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<Reference Include="System.Xml.Linq" />
5555
<Reference Include="System.Drawing" />
5656
<Reference Include="System.Web" />
57+
<Reference Include="System.Web.DataVisualization" />
5758
<Reference Include="System.Xml" />
5859
<Reference Include="System.Configuration" />
5960
<Reference Include="System.Web.Services" />
@@ -108,6 +109,10 @@
108109
<Content Include="Content\Images\C#.png" />
109110
<Content Include="Content\Site.css" />
110111
<Content Include="ControlSamples\Button\default.aspx" />
112+
<Content Include="ControlSamples\Chart\Default.aspx" />
113+
<Content Include="ControlSamples\Chart\PieChart.aspx" />
114+
<Content Include="ControlSamples\Chart\LineChart.aspx" />
115+
<Content Include="ControlSamples\Chart\DataBinding.aspx" />
111116
<Content Include="ControlSamples\DataList\RepeatColumns.aspx" />
112117
<Content Include="ControlSamples\DataList\StyleAttributes.aspx" />
113118
<Content Include="ControlSamples\DataList\FlowLayout.aspx" />
@@ -184,6 +189,34 @@
184189
<Compile Include="ControlSamples\Button\default.aspx.designer.cs">
185190
<DependentUpon>default.aspx</DependentUpon>
186191
</Compile>
192+
<Compile Include="ControlSamples\Chart\Default.aspx.cs">
193+
<DependentUpon>Default.aspx</DependentUpon>
194+
<SubType>ASPXCodeBehind</SubType>
195+
</Compile>
196+
<Compile Include="ControlSamples\Chart\Default.aspx.designer.cs">
197+
<DependentUpon>Default.aspx</DependentUpon>
198+
</Compile>
199+
<Compile Include="ControlSamples\Chart\PieChart.aspx.cs">
200+
<DependentUpon>PieChart.aspx</DependentUpon>
201+
<SubType>ASPXCodeBehind</SubType>
202+
</Compile>
203+
<Compile Include="ControlSamples\Chart\PieChart.aspx.designer.cs">
204+
<DependentUpon>PieChart.aspx</DependentUpon>
205+
</Compile>
206+
<Compile Include="ControlSamples\Chart\LineChart.aspx.cs">
207+
<DependentUpon>LineChart.aspx</DependentUpon>
208+
<SubType>ASPXCodeBehind</SubType>
209+
</Compile>
210+
<Compile Include="ControlSamples\Chart\LineChart.aspx.designer.cs">
211+
<DependentUpon>LineChart.aspx</DependentUpon>
212+
</Compile>
213+
<Compile Include="ControlSamples\Chart\DataBinding.aspx.cs">
214+
<DependentUpon>DataBinding.aspx</DependentUpon>
215+
<SubType>ASPXCodeBehind</SubType>
216+
</Compile>
217+
<Compile Include="ControlSamples\Chart\DataBinding.aspx.designer.cs">
218+
<DependentUpon>DataBinding.aspx</DependentUpon>
219+
</Compile>
187220
<Compile Include="ControlSamples\DataList\RepeatColumns.aspx.cs">
188221
<DependentUpon>RepeatColumns.aspx</DependentUpon>
189222
<SubType>ASPXCodeBehind</SubType>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<%@ Page Title="Chart - Data Binding" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="DataBinding.aspx.cs" Inherits="BeforeWebForms.ControlSamples.Chart.DataBinding" %>
2+
<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
3+
4+
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
5+
6+
<h2>Chart Control - Data Binding Example</h2>
7+
8+
<div>
9+
<a href="Default.aspx">Column Chart</a> | <a href="PieChart.aspx">Pie Chart</a> | <a href="LineChart.aspx">Line Chart</a> | <a href="DataBinding.aspx">Data Binding</a>
10+
</div>
11+
12+
<p>This example demonstrates binding a Chart control to a collection of objects (similar to GridView data binding).</p>
13+
14+
<asp:Chart ID="Chart1" runat="server" Width="700px" Height="400px"
15+
BackColor="WhiteSmoke" BorderColor="#999999" BorderWidth="1"
16+
BorderDashStyle="Solid" DataSourceID="ObjectDataSource1">
17+
<Series>
18+
<asp:Series Name="CustomerSales" ChartType="Bar"
19+
Color="MediumSeaGreen" BorderColor="Black" BorderWidth="1"
20+
XValueMember="CompanyName" YValueMembers="TotalSales">
21+
</asp:Series>
22+
</Series>
23+
<ChartAreas>
24+
<asp:ChartArea Name="ChartArea1"
25+
BackColor="White"
26+
BorderColor="Black"
27+
BorderWidth="1"
28+
BorderDashStyle="Solid">
29+
<AxisX Title="Company" IsLabelAutoFit="true">
30+
<MajorGrid LineColor="LightGray" />
31+
</AxisX>
32+
<AxisY Title="Total Sales ($)">
33+
<MajorGrid LineColor="LightGray" />
34+
</AxisY>
35+
</asp:ChartArea>
36+
</ChartAreas>
37+
<Titles>
38+
<asp:Title Text="Customer Sales Report" Font="Arial, 14pt, style=Bold" />
39+
</Titles>
40+
</asp:Chart>
41+
42+
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
43+
TypeName="BeforeWebForms.ControlSamples.Chart.DataBinding"
44+
SelectMethod="GetCustomerSales">
45+
</asp:ObjectDataSource>
46+
47+
</asp:Content>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.UI;
6+
using System.Web.UI.WebControls;
7+
8+
namespace BeforeWebForms.ControlSamples.Chart
9+
{
10+
public partial class DataBinding : System.Web.UI.Page
11+
{
12+
protected void Page_Load(object sender, EventArgs e)
13+
{
14+
}
15+
16+
/// <summary>
17+
/// Data source method for ObjectDataSource
18+
/// Returns a collection of customer sales data
19+
/// </summary>
20+
public static List<CustomerSales> GetCustomerSales()
21+
{
22+
return new List<CustomerSales>
23+
{
24+
new CustomerSales { CompanyName = "Contoso Ltd", TotalSales = 125000 },
25+
new CustomerSales { CompanyName = "Fabrikam Inc", TotalSales = 95000 },
26+
new CustomerSales { CompanyName = "Adventure Works", TotalSales = 150000 },
27+
new CustomerSales { CompanyName = "Northwind Traders", TotalSales = 110000 },
28+
new CustomerSales { CompanyName = "Wide World Importers", TotalSales = 135000 }
29+
};
30+
}
31+
}
32+
33+
/// <summary>
34+
/// Simple data class for customer sales information
35+
/// </summary>
36+
public class CustomerSales
37+
{
38+
public string CompanyName { get; set; }
39+
public decimal TotalSales { get; set; }
40+
}
41+
}

samples/BeforeWebForms/ControlSamples/Chart/DataBinding.aspx.designer.cs

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<%@ Page Title="Chart - Column Chart" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="BeforeWebForms.ControlSamples.Chart.Default" %>
2+
<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
3+
4+
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
5+
6+
<h2>Chart Control - Column Chart</h2>
7+
8+
<div>
9+
<a href="Default.aspx">Column Chart</a> | <a href="PieChart.aspx">Pie Chart</a> | <a href="LineChart.aspx">Line Chart</a> | <a href="DataBinding.aspx">Data Binding</a>
10+
</div>
11+
12+
<p>This is a basic example of a Column Chart displaying monthly sales data.</p>
13+
14+
<asp:Chart ID="Chart1" runat="server" Width="600px" Height="400px"
15+
BackColor="WhiteSmoke" BorderColor="#999999" BorderWidth="1"
16+
BorderDashStyle="Solid">
17+
<Series>
18+
<asp:Series Name="Sales" ChartType="Column"
19+
Color="SteelBlue" BorderColor="Black" BorderWidth="1">
20+
</asp:Series>
21+
</Series>
22+
<ChartAreas>
23+
<asp:ChartArea Name="ChartArea1"
24+
BackColor="White"
25+
BorderColor="Black"
26+
BorderWidth="1"
27+
BorderDashStyle="Solid">
28+
<AxisX Title="Month">
29+
<MajorGrid LineColor="LightGray" />
30+
</AxisX>
31+
<AxisY Title="Sales ($)">
32+
<MajorGrid LineColor="LightGray" />
33+
</AxisY>
34+
</asp:ChartArea>
35+
</ChartAreas>
36+
<Titles>
37+
<asp:Title Text="Monthly Sales Report" Font="Arial, 14pt, style=Bold" />
38+
</Titles>
39+
</asp:Chart>
40+
41+
</asp:Content>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.UI;
6+
using System.Web.UI.WebControls;
7+
8+
namespace BeforeWebForms.ControlSamples.Chart
9+
{
10+
public partial class Default : System.Web.UI.Page
11+
{
12+
protected void Page_Load(object sender, EventArgs e)
13+
{
14+
if (!IsPostBack)
15+
{
16+
// Add data points to the chart
17+
Chart1.Series["Sales"].Points.AddXY("January", 12000);
18+
Chart1.Series["Sales"].Points.AddXY("February", 15000);
19+
Chart1.Series["Sales"].Points.AddXY("March", 18000);
20+
Chart1.Series["Sales"].Points.AddXY("April", 16000);
21+
Chart1.Series["Sales"].Points.AddXY("May", 21000);
22+
Chart1.Series["Sales"].Points.AddXY("June", 25000);
23+
}
24+
}
25+
}
26+
}

samples/BeforeWebForms/ControlSamples/Chart/Default.aspx.designer.cs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<%@ Page Title="Chart - Line Chart" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="LineChart.aspx.cs" Inherits="BeforeWebForms.ControlSamples.Chart.LineChart" %>
2+
<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
3+
4+
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
5+
6+
<h2>Chart Control - Line Chart with Multiple Series</h2>
7+
8+
<div>
9+
<a href="Default.aspx">Column Chart</a> | <a href="PieChart.aspx">Pie Chart</a> | <a href="LineChart.aspx">Line Chart</a> | <a href="DataBinding.aspx">Data Binding</a>
10+
</div>
11+
12+
<p>This is an example of a Line Chart displaying multiple data series for comparison (Actual vs Target sales).</p>
13+
14+
<asp:Chart ID="Chart1" runat="server" Width="700px" Height="400px"
15+
BackColor="WhiteSmoke" BorderColor="#999999" BorderWidth="1"
16+
BorderDashStyle="Solid">
17+
<Series>
18+
<asp:Series Name="ActualSales" ChartType="Line"
19+
Color="Blue" BorderWidth="3" MarkerStyle="Circle" MarkerSize="8">
20+
</asp:Series>
21+
<asp:Series Name="TargetSales" ChartType="Line"
22+
Color="Green" BorderWidth="3" MarkerStyle="Diamond" MarkerSize="8" BorderDashStyle="Dash">
23+
</asp:Series>
24+
</Series>
25+
<ChartAreas>
26+
<asp:ChartArea Name="ChartArea1"
27+
BackColor="White"
28+
BorderColor="Black"
29+
BorderWidth="1"
30+
BorderDashStyle="Solid">
31+
<AxisX Title="Quarter" Interval="1">
32+
<MajorGrid LineColor="LightGray" />
33+
</AxisX>
34+
<AxisY Title="Sales ($1000s)">
35+
<MajorGrid LineColor="LightGray" />
36+
</AxisY>
37+
</asp:ChartArea>
38+
</ChartAreas>
39+
<Titles>
40+
<asp:Title Text="Quarterly Sales: Actual vs Target" Font="Arial, 14pt, style=Bold" />
41+
</Titles>
42+
<Legends>
43+
<asp:Legend Name="Legend1" Docking="Bottom" Alignment="Center" />
44+
</Legends>
45+
</asp:Chart>
46+
47+
</asp:Content>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Web;
5+
using System.Web.UI;
6+
using System.Web.UI.WebControls;
7+
8+
namespace BeforeWebForms.ControlSamples.Chart
9+
{
10+
public partial class LineChart : System.Web.UI.Page
11+
{
12+
protected void Page_Load(object sender, EventArgs e)
13+
{
14+
if (!IsPostBack)
15+
{
16+
// Add data points for Actual Sales
17+
Chart1.Series["ActualSales"].Points.AddXY("Q1", 45);
18+
Chart1.Series["ActualSales"].Points.AddXY("Q2", 52);
19+
Chart1.Series["ActualSales"].Points.AddXY("Q3", 58);
20+
Chart1.Series["ActualSales"].Points.AddXY("Q4", 65);
21+
22+
// Add data points for Target Sales
23+
Chart1.Series["TargetSales"].Points.AddXY("Q1", 50);
24+
Chart1.Series["TargetSales"].Points.AddXY("Q2", 55);
25+
Chart1.Series["TargetSales"].Points.AddXY("Q3", 60);
26+
Chart1.Series["TargetSales"].Points.AddXY("Q4", 70);
27+
28+
// Enable point labels to show values
29+
Chart1.Series["ActualSales"].IsValueShownAsLabel = true;
30+
Chart1.Series["TargetSales"].IsValueShownAsLabel = true;
31+
}
32+
}
33+
}
34+
}

samples/BeforeWebForms/ControlSamples/Chart/LineChart.aspx.designer.cs

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)