.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!



Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

How to draw a Line chart using MSChart

Posted By:Suthish Nair       Posted Date: August 29, 2010    Points: 25    Category: C#    URL: http://www.dotnetspark.com  

This article shows how to draw a Line chart using MSChart.
 


This article shows how to draw a Line chart using MSChart.

Also, setting Line width, Shadow, etc.. 

<asp:Chart ID="Chart1" runat="server" Width="800px" Height="300px">asp:Chart>


Now the code part.

String connString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString();
String sSQL = "select no_units, convert(varchar, date1, 107) date1 from dbo.customer order by sno";
DataTable result = new DataTable();
using (SqlConnection conn = new SqlConnection(connString))
{
    using (SqlCommand cmd = new SqlCommand())
    {
        conn.Open();
        cmd.CommandText = sSQL;
        cmd.Connection = conn;
        SqlDataReader dr;
        dr = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
        result.Load(dr);
        dr = null;
    }
}
Chart1.ChartAreas.Add("chtArea");
Chart1.Legends.Add("chtArea");
Chart1.Series.Add("Units");
Chart1.Series["Units"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Line;
Chart1.Series["Units"].Points.DataBindXY(result.DefaultView, "date1", result.DefaultView, "no_units");
Chart1.Series["Units"].IsVisibleInLegend = true;
Chart1.Series["Units"].IsValueShownAsLabel = true;
Chart1.Series["Units"].ToolTip = "Data Point Y Value: #VALY{G}";

// Setting Line Width
Chart1.Series["Units"].BorderWidth = 3;

// Setting Line Shadow
Chart1.Series["Units"].ShadowOffset = 5;
Chart1.ChartAreas[0].AxisX.Title = "Dates";
Chart1.ChartAreas[0].AxisX.TitleFont = new System.Drawing.Font("Verdana", 10, System.Drawing.FontStyle.Bold);
Chart1.ChartAreas[0].AxisY.Title = "No of Units";
Chart1.ChartAreas[0].AxisY.TitleFont = new System.Drawing.Font("Verdana", 10, System.Drawing.FontStyle.Bold);
Chart1.ChartAreas[0].BorderDashStyle = ChartDashStyle.Solid;
Chart1.ChartAreas[0].BorderWidth = 1;
Chart1.BorderSkin.SkinStyle = BorderSkinStyle.Emboss;
Chart1.BorderlineColor = System.Drawing.Color.FromArgb(26, 59, 105);
Chart1.BorderlineWidth = 2;
Chart1.BackColor = Color.AliceBlue;
result = null;


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend