• Home
  • Jobs
  • Courses
  • Certifications
  • Companies
  • Online IDE
  • Login
  • Signup
MYTAT
  • Home
  • Jobs
  • Courses
  • Certifications
  • Companies
  • Online IDE
  • Login
  • Signup
ASP And ASP.NET Tutorials
  • ASP.NET Web Pages - Tutorial
  • ASP.NET Web Pages - Adding Razor Code
  • ASP.NET Web Pages - Page Layout
  • ASP.NET Web Pages - Folders
  • ASP.NET Web Pages - Global Pages
  • ASP.NET Web Pages - HTML Forms
  • ASP.NET Web Pages - Objects
  • ASP.NET Web Pages - Files
  • ASP.NET Web Pages - Databases
  • ASP.NET Web Pages - Helpers
  • ASP.NET Web Pages - The WebGrid Helper
  • ASP.NET Web Pages - The Chart Helper
  • ASP.NET Web Pages - The WebMail Helper
  • ASP.NET Web Pages - WebSecurity Object
  • ASP.NET Web Pages - Publishing The Website
  • ASP.NET Web Pages - Classes
  • ASP.NET Razor - Markup
  • ASP.NET Razor - C# And VB Code Syntax
  • ASP.NET Razor - C# Variables
  • ASP.NET Razor - C# Loops And Arrays
  • ASP.NET Razor - C# Logic Conditions
  • ASP.NET Razor - VB Variables
  • ASP.NET Razor - VB Loops And Arrays
  • ASP.NET Razor - VB Logic Conditions
  • ASP Tutorial
  • ASP Syntax
  • ASP Variables
  • ASP Procedures
  • VBScript Conditional Statements
  • VBScript Looping
  • ASP Forms And User Input
  • ASP Cookies
  • ASP Session Object
  • ASP Application Object
  • ASP Including Files
  • ASP The Global.asa File
  • ASP AJAX
  • ASP Sending E-mail With CDOSYS
  • VBScript Functions
  • VBScript Keywords
  • ASP Response Object
  • ASP Application Object
  • ASP Session Object
  • ASP Server Object
  • ASP ASPError Object
  • ASP FileSystemObject Object
  • ASP TextStream Object
  • ASP Drive Object
  • ASP File Object
  • ASP Folder Object
  • ASP Dictionary Object
  • ASP AdRotator Component
  • ASP Browser Capabilities Component
  • ASP Content Linking Component
  • ASP Content Rotator Component (ASP 3.0)
  • ASP Quick Reference
  • ADO Introduction
  • ADO Database Connection
  • ADO Recordset
  • ADO Display
  • ADO Queries
  • ADO Sort
  • ADO Add Records
  • ADO Update Records
  • ADO Delete Records
  • ADO Demonstration
  • ADO Speed Up With GetString()
  • ADO Command Object
  • ADO Connection Object
  • ADO Error Object
  • ADO Field Object
  • ADO Parameter Object
  • ADO Property Object
  • ADO Record Object
  • ADO Recordset Object
  • ADO Stream Object
  • ADO Data Types
  • Home
  • Courses
  • ASP And ASP.NET Tutorials
  • ASP.NET Web Pages - The Chart Helper

ASP.NET Web Pages - The Chart Helper

Previous Next

The Chart Helper

In the previous chapters, you learned how to use an ASP.NET "Helper".

You learned how to display data in a grid using the "WebGrid Helper".

This chapter explains how to display data in graphical form, using the "Chart Helper".

The "Chart Helper" can create chart images of different types with many formatting options and labels. It can create standard charts like area charts, bar charts, column charts, line charts, and pie charts, along with more specialized charts like stock charts.

chart chart

The data you display in a chart can be from an array, from a database, or from data in a file.



Practice Excercise Practice now

Chart From An Array

The example below shows the code needed to display a chart from an array of values:

@{ 
var myChart = new Chart(width: 600, height: 400) 
   .AddTitle("Employees") 
   .AddSeries(chartType: "column",
      xValue: new[] {  "Peter", "Andrew", "Julie", "Mary", "Dave" }, 
      yValues: new[] { "2", "6", "4", "5", "3" }) 
   .Write();
}

- new Chart creates a new chart object and sets its width and height

- the AddTitle method specifies the chart title

- the AddSeries method adds data to the chart

- the chartType parameter defines the type of chart

- the xValue parameter defines x-axis names

- the yValues parameter defines the y-axis values

- the Write() method displays the chart 



Practice Excercise Practice now

Chart From Database Data

You can run a database query and then use data from the results to create a chart:

@{ 
var db = Database.Open("SmallBakery"); 
var dbdata = db.Query("SELECT Name, Price FROM Product"); 
var myChart = new Chart(width: 600, height: 400) 
   .AddTitle("Product Sales") 
   .DataBindTable(dataSource: dbdata, xField: "Name")
   .Write();
}
 

- var db = Database.Open opens the database (and assigns the database object to the variable db)

- var dbdata = db.Query runs a database query and stores the result in dbdata

- new Chart creates a chart new object and sets its width and height

- the AddTitle method specifies the chart title

- the DataBindTable method binds the data source to the chart

- the Write() method displays the chart 

An alternative to using the DataBindTable method is to use AddSeries (See previous example). DataBindTable is easier to use, but AddSeries is more flexible because you can specify the chart and data more explicitly:

Example

@{ 
var db = Database.Open("SmallBakery"); 
var dbdata = db.Query("SELECT Name, Price FROM Product"); 
var myChart = new Chart(width: 600, height: 400) 
   .AddTitle("Product Sales") 
   .AddSeries(chartType:"Pie",
      xValue: dbdata, xField: "Name",
      yValues: dbdata, yFields: "Price")
   .Write();
}


 



Practice Excercise Practice now

Chart From XML Data

The third option for charting is to use an XML file as the data for the chart

Example

@using System.Data;

@{
var dataSet = new DataSet();
dataSet.ReadXmlSchema(Server.MapPath("data.xsd"));
dataSet.ReadXml(Server.MapPath("data.xml"));
var dataView = new DataView(dataSet.Tables[0]);
var myChart = new Chart(width: 600, height: 400)
   .AddTitle("Sales Per Employee")
   .AddSeries("Default", chartType: "Pie",
      xValue: dataView, xField: "Name",
      yValues: dataView, yFields: "Sales")
   .Write();}
}



Practice Excercise Practice now

Chart Object Reference

Helper Description
Chart(width, height [, template] [, templatePath]) Initializes a chart.
Chart.AddLegend([title] [, name]) Adds a legend to a chart.
Chart.AddSeries([name] [, chartType] [, chartArea]
  [, axisLabel] [, legend] [, markerStep] [, xValue]
  [, xField] [, yValues] [, yFields] [, options])
Adds a series of values 



Practice Excercise Practice now

Previous Next
COMPANY
  • About us
  • Careers
  • Contact Us
  • In Press
  • People
  • Companies List
Products
  • Features
  • Coding Assessments
  • Psychometric Assessment
  • Aptitude Assessments
  • Tech/Functional Assessments
  • Video Assessment
  • Fluency Assessment
  • Campus
 
  • Learning
  • Campus Recruitment
  • Lateral Recruitment
  • Enterprise
  • Education
  • K 12
  • Government
OTHERS
  • Blog
  • Terms of Services
  • Privacy Policy
  • Refund Policy
  • Mart Category
Partner
  • Partner Login
  • Partner Signup

Copyright © RVR Innovations LLP 2025 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP