In this article we will discuss, how to display data using asp.net chart control. We want to display weekly visitors of the website.
Step 1: Drag and drop chart control from the toolbox.
Step 2: Copy and paste the following code.
<asp:Chart ID="Chart2" runat="server" Width="350">
<Titles>
<asp:Title Text="website visitors">
</asp:Title>
</Titles>
<Series>
<asp:Series Name="Series1" ChartArea="ChartArea1">
<Points>
<asp:DataPoint AxisLabel="sun" YValues="800" />
<asp:DataPoint AxisLabel="mon" YValues="900" />
<asp:DataPoint AxisLabel="tue" YValues="700" />
<asp:DataPoint AxisLabel="wed" YValues="900" />
<asp:DataPoint AxisLabel="thr" YValues="600" />
<asp:DataPoint AxisLabel="fri" YValues="750" />
<asp:DataPoint AxisLabel="sat" YValues="950" />
</Points>
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
<AxisX Title="week">
</AxisX>
<AxisY Title="visitors per day">
</AxisY>
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
In chart we need to provide title for the chart using <Titles>.I There are two main components series & chartAreas.
Series: It is a collection of data points
ChartAreas: we have to provide title for x-axis and y-axis. Here AxisX elements denotes the visitors of website and AxisY for week.
Step 3: Please make sure to register the assembly top of the page.
<%@ Register Assembly="System.Web.DataVisualization,Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI.DataVisualization.Charting" TagPrefix="asp" %>
Run the application and view the output displaying data in a barchart as expected.
Output:
Post your comments / questions
Recent Article
- Your system's memory configuration has changed since it entered hibernation.
- Save image to client browser using jQuery?
- Get filename of image jQuery?
- How to get the image src using JavaScript?
- System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Net.Http.Formatting' with identity 'System.Net.Http.Formatting, Version=4.0.0.0
- Cordova Android build error "Cannot read property 'length' of undefined". An error occurred while running subprocess cordova.
- ERROR in The Angular Compiler requires TypeScript >=3.9.2 and <4.0.0 but 3.8.3 was found instead
- Code ENOLOCAL Could not install from "android" as it does not contain a package.json file.
Related Article