Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 2nd, 2005, 04:20 PM
Authorized User
 
Join Date: Apr 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DudeBori82 Send a message via MSN to DudeBori82
Default Help on Pie Chart

I am new to C# and ASP.NET and would like to make a pie chart from 4 double variables. Every article I can find is too advanced for me, is there any book, person, or article that can explain how to build a pie chart in ASP.NET/C# in lower level terms? (For slower people like me to understand.) (If anyone is familiar with C1WebChart, that would even be better.)

Actions are a direct result of your desires. Desire for good things.
__________________
Troubleshooting life: 1 bug at a time.
 
Old May 2nd, 2005, 04:35 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Do you want to build the chart engine yourself, or do you just want to create a chart using an existing component?

If the latter, check out this site and this article.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 2nd, 2005, 04:38 PM
Authorized User
 
Join Date: Apr 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DudeBori82 Send a message via MSN to DudeBori82
Default

I don't want to reinvent the wheel. I have C1WebChart component, but i can't find anything (not even examples) on how to do it from a low level. I would prefer to use an existing component.

Actions are a direct result of your desires. Desire for good things.
 
Old May 2nd, 2005, 04:47 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

What "low level" are you referring to? The site I pointed you to has the component, a bunch of examples and a help file.

Are you looking for something else?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old May 2nd, 2005, 04:59 PM
Authorized User
 
Join Date: Apr 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DudeBori82 Send a message via MSN to DudeBori82
Default

Hey, this looks like it. I'll check it out.

Actions are a direct result of your desires. Desire for good things.
 
Old May 2nd, 2005, 05:21 PM
Authorized User
 
Join Date: Apr 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DudeBori82 Send a message via MSN to DudeBori82
Default

Code:
            DataSet dsChartData = new DataSet();
            dsChartData.Tables.Add("Chart Data");
            dsChartData.Tables[0].Columns.Add("Incomplete");
            dsChartData.Tables[0].Columns.Add("Pass");
            dsChartData.Tables[0].Columns.Add("Pass (Effective)");
            dsChartData.Tables[0].Columns.Add("Fail");
            dsChartData.Tables[0].Rows.Add(dsChartData.Tables[0].NewRow());
            dsChartData.Tables[0].Rows[0]["Statuses"] = dIncompletePercentage;
            dsChartData.Tables[0].Rows[1]["Statuses"] = dPassPercentage;
            dsChartData.Tables[0].Rows[2]["Statuses"] = dPassEffectivePercentage;
            dsChartData.Tables[0].Rows[3]["Statuses"] = dFailPercentage;

            PieChart pcWebChart = new PieChart();

            pcWebChart.DataSource = dsChartData;

            pcWebChart.DataXValueField = "X Value";
            pcWebChart.DataYValueField = "Y Value";
            pcWebChart.DataBind();

            pcWebChart.DataLabels.Visible = true;

            wcPieChart.Charts.Add(pcWebChart);
            wcPieChart.RedrawChart();


I tried to recreate it in C#, but it didn't work. It gives me a invalid DataSource type when i try to access the page. - I don't actually get that data from a database, it's calculated. Can someone help me figure this out with C#?
 
Old May 3rd, 2005, 03:01 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Is this the code form the control I pointed you to, or is C1WebChart a different control?

The WebChart I linked to accepts any IEnumerable object as its datasource, so you can't point it to a DataSet directly. You'll need to do something like this:

pcWebChart.DataSource = dsChartData.Tables[0].DefaultView;

The DefaultView of the Table object is an IEnumerable, so that should work.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Big Exit by P J Harvey (Track 1 from the album: Stories From The City, Stories From The Sea) What's This?
 
Old May 3rd, 2005, 03:07 PM
Authorized User
 
Join Date: Apr 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DudeBori82 Send a message via MSN to DudeBori82
Default

I just used chart.data.Add(Chartpoint("String", FloatValue));
and it worked fine. They give a great startup help for C# on the website of the WebChart download.
Thanks for your help!!
Here is the final working code:
Code:
float fIncompletePercentage = (float)dIncompletePercentage;
            float fPassPercentage = (float)dPassPercentage;
            float fPassEffectivePercentage = (float)dPassEffectivePercentage;
            float fFailPercentage = (float)dFailPercentage;

            PieChart chart = new PieChart();
            chart.Data.Add( new ChartPoint("Incomplete", fIncompletePercentage) );
            chart.Data.Add( new ChartPoint("Pass", fPassPercentage) );
            chart.Data.Add( new ChartPoint("Pass (Effective)", fPassEffectivePercentage) );
            chart.Data.Add( new ChartPoint("Fail", fFailPercentage) );

            chart.DataXValueField = "Status";
            chart.DataYValueField = "Percent";
            chart.DataLabels.ShowValue = true;

            wcWebChart.Charts.Add(chart); 
            wcWebChart.RedrawChart();


The only thing now, is to figure out how do configure the color for each status (not use the default colors)...
 
Old May 3rd, 2005, 03:14 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

You're welcome.

Yeah, the site comes with a lot of useful examples. Did you download the zip file with examples? It shows a lot of other cool tricks you can do with it....

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Demo-stratie by Osdorp Posse (Track 12 from the album: Geendagsvlieg) What's This?
 
Old May 3rd, 2005, 04:24 PM
Authorized User
 
Join Date: Apr 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to DudeBori82 Send a message via MSN to DudeBori82
Default

found it!
Code:
chart.Colors = new Color[]{ Color.LightGray, Color.LightGreen, Color.Blue, Color.Red};
Actions are a direct result of your desires. Desire for good things.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to create 3d pie chart Sunilmesu Pro Visual Basic 2005 1 April 30th, 2008 10:52 AM
3d pie chart Sunilmesu Pro Visual Basic 2005 0 April 30th, 2008 04:32 AM
Pie Chart jomet Pro JSP 2 March 10th, 2008 10:42 PM
Pie-Chart crmpicco Javascript How-To 2 February 10th, 2005 06:34 AM
Pie Chart lryckman Access 0 April 26th, 2004 11:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.