In this assignment, we are going to display a chart in a form
and do some tricks with it: adding values from different sources,
changing the chart type, etc.
What to do
Your form should include at least the following:
You may also want some labels.
When the form is loaded, we should have a bar chart with 3 bars.
If the "Choose a file" button is clicked, you should call
up an OpenFileDialog. Set the OpenFileDialog's InitialDirectory
property to "." before you use the ShowDialog method. We will
have several files of numbers available. The user can choose
one. Read the file called and store its contents in an array
or List of doubles. If the user selects "Choose a file" again,
do all this again but first empty the previous list of values.
If one of the radio buttons is selected, the ChartType property of
the series should be changed accordingly. Reset the radio button
involved, as in
If the Clear button is clicked, the DataPointCollection of
the Series in the chart should be cleared, as in:
If the "Value from File" button is clicked, a number from the
array of doubles is added as a Point. If the end of the array
is reached, do nothing.
If the "Value at Random" button is clicked, generate a
double value between 0.0 and 30.0 and add it as a Point.
You will need the Random class and its Next method.
If the "Value from User" button is clicked, read whatever
is in the textbox, convert it to a double and add it as a
Point. After that, clear the textbox. (If the value
in the textbox is not in the right format, you need to
put up a MessageBox prompting the user to supply a double.
You should handle this occurrence without the entire program
crashing. (You may want to use the TryParse method.) (We
are not trying to set a trap for you here.)
If the Exit button is clicked, the form should be closed.
Notes
Try to make your form look presentable. You can make the
form and the chart larger or smaller. Line up the
radio buttons neatly. Line up the other buttons neatly.
If you don't like the names of the buttons, you can use other names,
but the names should clearly indicate the purposes of the buttons.
Notice that the names of chart types are found in the
SeriesChartType enumeration.
Decide on a color scheme and a font.
We are only working with one series in one chart.
Make a copy of the input files listed on the web page and put them
somewhere you can find them with the OpenFileDialog.
RB.Checked = false;
MyChart.Series["MySeries"].Point.Clear();