lemunk
lemunk

Reputation: 2636

using a chart with values from textboxes

I'm trying to make a pie chart that uses values from a user from text box's. I'm using c# windows forms chart control.

The problem is where to assign the text box's as values.

I've attempted to make one using the properties wizard but I cant see where to assign the values for it to process, the data source seem to only allow objects and connections to Dbos.
I'm hoping this is a really simple process I'm overlooking.

Yes I've checked MSDN but not a lot of info on the specifics I require. Yes I've checked google but again there is either no info or info on building my own from scratch (which I have done, but looks really bad)

this is some code ive tried

         double[] yValues = { 10, 8, 7, 12};
        string[] xNames = { "Greater than 200", "Between 200-100", "Between 100-50", "Below 50" };

        chart1.Series[0].Points.DataBindXY(xNames, yValues);
        chart1.Series[1].Points.DataBindXY(xNames, yValues);
        chart1.Series[2].Points.DataBindXY(xNames, yValues);
        chart1.Series[3].Points.DataBindXY(xNames, yValues);

it errors at series[2], saying the index was out of range. Im guessing it something to do with how the chart is currently set up

::UPDATED:: Ok so i was right i didnt assign enough series to the chart (silly me). Ive managed to get it up and running.....unfortunatly the image display looks like.....a letter(wierd). Its a box with a cross in the middle all equal aswell. I would at least think its would display proportional to the values i sent. so is this a set up OR is there something im doing wrong in my code?

Upvotes: 0

Views: 6844

Answers (3)

CouncilScribe
CouncilScribe

Reputation: 711

I would suggest something like this. Where you would plug your y values directly from your textboxes.

   double[] yValues = { 10, 27.5, 7, 12, 45.5};
    string[] xNames = { “Mike”, “John”, “William”, “George”, “Alex” };
   myChart.Series[0].Points.DataBindXY(xNames, yValues);

Upvotes: 3

Moonlight
Moonlight

Reputation: 708

maybe an idea to take a look at zedgraph: http://www.codeproject.com/KB/graphics/zedgraph.aspx

this chart class can make pie-charts among other things

Upvotes: 0

Andrey Marchuk
Andrey Marchuk

Reputation: 13483

Here's example code with explanations:

http://forum.codecall.net/csharp-tutorials/7917-tutorial-vs2008-c-pie-chart.html#post43094

I think it's doing exactly what you want to do

Upvotes: 0

Related Questions