11

Using a chart with values ​​from text boxes

 2 years ago
source link: https://www.codesd.com/item/using-a-chart-with-values-from-text-boxes.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Using a chart with values ​​from text boxes

advertisements

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.

  • Is it done in code? if so what do I call?
  • Is it done in the control properties? if so what do I do?
  • Is it a bit of both? is so, well same as both above.

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?


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);


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK