Mar 15, 2007

ZedGraph

Another free Chart Library for .Net !

Excellent!

http://sourceforge.net/projects/zedgraph/

http://www.codeproject.com/csharp/zedgraph.asp

Mirror Download


My Sample Code:

Code inside aspx

<%@ Page Language="C#" AutoEventWireup="true" <%@ Register TagPrefix="zgw" Namespace="ZedGraph.Web" Assembly="ZedGraph.Web" %>


Code inside aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
this.ZedGraphWeb1.RenderGraph += new ZedGraph.Web.ZedGraphWebControlEventHandler(this.OnRenderGraph);
}

private void OnRenderGraph(System.Drawing.Graphics g, ZedGraph.MasterPane masterPane)
{
try
{
// STEP 1: Get the data from the database by stored procedure
SqlConnection cn = new SqlConnection(MyConstant.connectionString);
SqlCommand cmd = new SqlCommand("prc_industry_report_details", cn);
SqlDataReader dReader;

cn.Open();
cmd.CommandType = CommandType.StoredProcedure;

// input pass in parameter
cmd.Parameters.Add("@INDUSTRY_CATEGORY", SqlDbType.VarChar, 50).Value = INDUSTRY_CATEGORY_ID.Text;
cmd.Parameters.Add("@FROM_DATE", SqlDbType.VarChar, 20).Value = FROM_DATE.Text.ToString();
cmd.Parameters.Add("@TO_DATE", SqlDbType.VarChar, 20).Value = TO_DATE.Text.ToString();

dReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);


// STEP 2: Create the chart object

// Get the GraphPane so we can work with it
GraphPane myPane = masterPane[0];

myPane.Title.Text = "My Title";
myPane.XAxis.Title.Text = "Spend ($)";
myPane.YAxis.Title.Text = "Date";

//read the ouput data into the grapic
PointPairList list = new PointPairList();
ArrayList labels_list = new ArrayList();
int i = 0;
while (dReader.Read())
{
list.Add((double)i++, double.Parse(dReader["Total Spend"].ToString()));
labels_list.Add(dReader["Month"].ToString() + "/" + dReader["Year"].ToString());
}
string[] labels = (string[])labels_list.ToArray(typeof(string));

BarItem myCurve = myPane.AddBar("Industry Report", list, Color.Blue);
myCurve.Label.IsVisible = false;
myCurve.Bar.Fill = new Fill(Color.Blue, Color.White, Color.Blue);

// Draw the X tics between the labels instead of at the labels
myPane.XAxis.MajorTic.IsBetweenLabels = true;

//string[] labels = { "Africa", "Americas", "Asia", "Europe", "Australia" };
myPane.XAxis.Scale.TextLabels = labels;
myPane.XAxis.Type = AxisType.Text;
myPane.XAxis.Scale.FontSpec.Border.IsVisible = false;
myPane.XAxis.Scale.FontSpec.Angle = 270f;
myPane.YAxis.Scale.FontSpec.Border.IsVisible = false;

// Fill the Axis and Pane backgrounds
//myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F);
//myPane.Fill = new Fill(Color.FromArgb(250, 250, 255));
myPane.Fill = new Fill(Color.White, Color.FromArgb(200, 200, 255), 45.0f);
myPane.Chart.Fill = new Fill(Color.White, Color.LightGoldenrodYellow, 45.0f);

masterPane.AxisChange(g);

dReader.Close();
cn.Close();
}
catch (Exception e)
{ }
}

11 comments:

Anonymous said...

Great Post ! Indeed Helpful !!

Rahul Bagal said...

Thanks for the sample code.
I am trying to use this control in my application. Instead of binary DLLs I want to use source code in my project.

I have included ZedGraph.csproj
& ZedGraph.Web.csproj in my ASP.net 2.0 web application.
Both of these project get compiled but when I add control to web form I get below error

Could not load file or assembly 'ZedGraph, Version=5.1.5.19751, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Have you ever faced this issue ?

Unknown said...

I didn't face this issue before.

Did you copy the dll into the bin folder?

You can find the procedures from the URL:
http://www.codeproject.com/KB/graphics/zedgraph.aspx


Using ZedGraph as a UserControl

ZedGraph is accessible as a control from the control toolbox in Visual Studio .NET. To access ZedGraph, first launch Visual Studio .NET, and create a new Windows Application (Forms) project. Open the form design so that it appears in the current window. View the toolbox using the View/Toolbox menu command. Right-click inside the "General" or "Components" sub-pane of the tool box, and select the "Choose Items..." option. Click "Browse...", and navigate to the zedgraph.dll file. Once this file is added, you should see a ZedGraphControl option in the toolbox.
....
....
...

Unknown said...

I am facing an issue that is the Y Axis values are limited to a max value of 1000, wherein i need to plot data for values which have y co-ordinate as 1,00,000 or above. So when i plot the graph using zedgrph in asp.net, it shows the y scale till 1000 only but the grpah till the Y value of 1,00,000 is plotted. Can u help me out?

Unknown said...

Avichal, sorry, I don't know how to fix it.

Maybe you can download the latest version
http://sourceforge.net/projects/zedgraph/files/zedgraph%20source/5.1.5/zedgraph_source_v515.zip/download

and try to amend the code by yourself

Anonymous said...

But how can i export the graph into pdf and excel. Can you provide a code for that. thanks a lot

Unknown said...

For export HTML to PDF (or other format), please refer to
http://stackoverflow.com/questions/589852/export-from-html-to-pdf-c

ZedGraph seems is not support direct output to PDF....

Anonymous said...

funiest online dating story ireland http://loveepicentre.com/ full house dating

Anonymous said...

dating while separated in georgia http://loveepicentre.com/taketour.php advice dating love teen

Anonymous said...

ebook reader price http://audiobookscollection.co.uk/es/Office-and-SharePoint-2010-User-s-Guide-Integrating-SharePoint-with-Excel-Outlook-Access-and-Word/p179798/ book publishing ebook [url=http://audiobookscollection.co.uk/es/Neural-network-toolbox-for-use-with-MATLAB-User-s-guide/p216667/]2003 free ebook[/url] ebook cover php

Anonymous said...

[url=http://certifiedpharmacy.co.uk/products/hyzaar.htm][img]http://onlinemedistore.com/11.jpg[/img][/url]
leos lakeside pharmacy http://certifiedpharmacy.co.uk/products/parlodel.htm my mexican pharmacy [url=http://certifiedpharmacy.co.uk/products/avodart.htm]cvs pharmacy photo printing[/url]
kellie powell pharmacy http://certifiedpharmacy.co.uk/products/aricept.htm pharmacy school chicago [url=http://certifiedpharmacy.co.uk/products/zantac.htm]zantac[/url]
target pharmacy mn http://certifiedpharmacy.co.uk/products/voltaren.htm pharmacy negligence statute ohio [url=http://certifiedpharmacy.co.uk/products/cleocin-gel.htm]pharmacy technican in mississippi[/url]
cal pharmacy skete shop http://certifiedpharmacy.co.uk/products/albendazole.htm how is communication important in a pharmacy [url=http://certifiedpharmacy.co.uk/products/zaditor.htm]zaditor[/url]