Chapter 12: WebPages Chart

The Chart Helper is one of the most “wow” features of classic ASP.NET Web Pages. With just a few lines of code, you can generate professional-looking bar charts, line graphs, pie charts, area charts, and more — directly as an image — and embed them in your .cshtml page.

No JavaScript libraries, no external services, no complicated setup — just pure server-side chart rendering.

Why Was Chart Helper So Loved? (Teacher Story Time)

In 2010–2015 era:

  • Most people were still using plain HTML + maybe Flash or early jQuery plugins for charts
  • Setting up Google Charts / Highcharts / Chart.js required client-side code, JSON data, AJAX calls
  • ASP.NET Web Pages said: “Why not just do it on the server with one object?”

→ You write C# code → Chart Helper creates a PNG image → browser shows it like any <img>

Perfect for reports, dashboards, sales summaries, student grades — especially when you already have data from Database or file.

1. Core Idea – How Chart Helper Works

You create a Chart object → add title, series (data sets), legend, themes → call .Write() or .GetUrl() to output it.

Basic flow:

HTML

That’s it — one object, chainable methods, done.

2. Full Practical Example – Monthly Sales Chart (from Database)

Let’s make it real. Assume we have the SmallBakery database from earlier lessons, but we’ll add a simple Sales table or just use hard-coded data for clarity.

File: SalesChart.cshtml

HTML

What you get in browser:

  • A nice line chart with two series (2025 vs 2026)
  • Title at top
  • Legend on right
  • Axis labels
  • Green theme (you can choose Blue, Vanilla, etc. or custom XML theme)

3. Common Chart Types (Supported by Chart Helper)

chartType value Visual style Best for
Column Vertical bars Comparing categories
Bar Horizontal bars Long category names
Line Connected points Trends over time
Pie Circular slices Percentage distribution
Area Filled under line Cumulative trends
Doughnut Pie with hole Looks modern
Stock Candlestick (for finance) Stock prices
Scatter Points without lines Correlations

Example pie chart (quick one):

HTML

4. Useful Options & Formatting (from W3Schools + Extras)

HTML

You can also:

  • Use .GetUrl() → returns /ChartImg.axd?… URL → use in <img src=”@chart.GetUrl()” />
  • Save to file: .Save(“~/charts/sales.png”)
  • Themes: Green, Blue, Vanilla, Yellow (or custom XML file)

5. Real-World Tip: From Database (Combining with Previous Lessons)

HTML

6. 2026 Perspective – Where Did It Go?

  • Chart Helper was server-side → generated images → no interactivity (no hover tooltips, no zoom)
  • In ASP.NET Core → Microsoft removed it → now people use:
    • Chart.js (client-side, interactive)
    • Plotly.NET
    • Syncfusion / Telerik / DevExpress (paid)
    • Quick-and-dirty: SVG via Razor or libraries
  • But learning Chart Helper is still excellent for understanding data visualization basics

Summary – Blackboard Close

ASP.NET Web Pages Chart Helper = server-side chart image generator:

  • new Chart(width, height) → start
  • .AddTitle(), .AddSeries(…), .AddLegend(), .AddXAxis/YAxis()
  • .Write() or .GetUrl() → show image
  • Types: Column, Line, Pie, Area, etc.
  • Themes & formatting → quick professional look
  • Great for static reports/dashboards when you have DB or array data

Next class?

  • Want example with 3D charts, multiple Y-axes, or stock chart?
  • How to make dynamic chart from form input (user selects year)?
  • Or move to WebPages Email (sending mails with charts attached 😄)?

Tell me — you’re doing amazing in this full W3Schools ASP track from Hyderabad! Keep the energy up! 🚀🇮🇳

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *