Sorting ASP NET Chart Control using Sort method

preview_player
Показать описание
Text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

Slides

All ASP .NET Chart Control Text Articles and Slides

ASP.NET Charts Playlist

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic

In this video we will discuss sorting ASP.NET chart control using Sort() method. This is continuation to Part 9. Please watch Part 9 before proceeding.

To use Sort() method

[table style="font-family: Arial; border: 1px solid black"]
[tr]
[td]
Sort By :
[asp:DropDownList ID="ddlSortBy" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="ddlSortBy_SelectedIndexChanged"]
[asp:ListItem Text="Student Name" Value="AxisLabel"][/asp:ListItem]
[asp:ListItem Text="Total Marks" Value="Y"][/asp:ListItem]
[/asp:DropDownList]
[/td]
[td]
Sort Direction :
[asp:DropDownList ID="ddlSortDirection" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="ddlSortDirection_SelectedIndexChanged"]
[asp:ListItem Text="Ascending" Value="ASC"][/asp:ListItem]
[asp:ListItem Text="Descending" Value="DESC"][/asp:ListItem]
[/asp:DropDownList]
[/td]
[/tr]
[tr]
[td colspan="2"]
[asp:Chart ID="Chart1" runat="server"]
[Series]
[asp:Series Name="Series1"]
[/asp:Series]
[/Series]
[ChartAreas]
[asp:ChartArea Name="ChartArea1"]
[/asp:ChartArea]
[/ChartAreas]
[/asp:Chart]
[/td]
[/tr]
[/table]

Step 2 : Modify the code in the code-behind file as shown below.
using System;
using System.Data;

namespace ChartsDemo
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetChartData();
}
}

private void GetChartData()
{
DataSet ds = new DataSet();
Chart1.Series["Series1"].XValueMember = "StudentName";
Chart1.Series["Series1"].YValueMembers = "TotalMarks";
Chart1.DataSource = ds;
Chart1.DataBind();

// Sorting
if (ddlSortDirection.SelectedValue == "ASC")
{
Chart1.Series["Series1"].Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Ascending, ddlSortBy.SelectedValue);
// OR
// Chart1.DataManipulator.Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Ascending, ddlSortBy.SelectedValue, "Series1");
}
else
{
Chart1.Series["Series1"].Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Descending, ddlSortBy.SelectedValue);
// OR
// Chart1.DataManipulator.Sort(System.Web.UI.DataVisualization.Charting.PointSortOrder.Descending, ddlSortBy.SelectedValue, "Series1");
}
}

protected void ddlSortBy_SelectedIndexChanged(object sender, EventArgs e)
{
GetChartData();
}

protected void ddlSortDirection_SelectedIndexChanged(object sender, EventArgs e)
{
GetChartData();
}
}
}

References :
Рекомендации по теме
Комментарии
Автор

Thank you very much.. Great tutorial and this will prove very helpful to me... thank you once again...

divyeshvaghela
Автор

Venkat, Can you please add example to use Highcharts in ASP.net

mysbandhu
Автор

thank you for sharing your knowledge. that is really priceless. could you create a video on multiple y-axis line graph. the y-axis is dynamic (dynamic columns running a query)  not known until run time.

yosefteferi
Автор

Thank you sir for the chart vedeos. Is there a way in asp.net to build dropdown chart.
ie, when click on any datapoint, its detailed chart shold be shawn. Expect your kind reply.

jj-ghfl
Автор

Sir, Thanks a lot....

Sir could you please provide some videos on Design Patterns??

pareshpatil
Автор

Hi, how I apply css style "border-radius" in the chartType "bar" ???

filipesilva
Автор

thanks you sir, it help me a lot... i need one help about this chart control, in one page company logo, company name  and some data like (label controls) with Pie Chart and Bar chart. There will be one button that will download that page in PDF.

jaga
Автор

Hi venkat
Plz make a video tutorial on image upload with SQL parameters  in MVC

rups
Автор

thanx for lot for sharing :) .. can u please share how to connect HighCharts (Highstock) connect to Sql server data ?

namaludayanga
Автор

my asp.net chart control is not working on server what to do to make it work on server? Please help me

milindnagap