Hello

I'm trying to draw a line graph on a form but I'm now very much stuck. I'm trying to read in the data from a txt file into an array and then plot the graph using the points collected from the file.

This is the contents of the file i'm reading from:

[HRData]
97	117	0	-117	0	50
97	117	0	-117	0	50
97	183	0	-117	0	50
94	183	55	-117	34	50
95	210	56	-117	84	4931
95	207	59	-117	113	5438
95	196	57	-117	125	5944
97	248	56	-117	125	5944
98	255	64	-117	141	5432
100	252	64	-117	141	5432
101	248	79	-117	147	5444
102	237	82	-117	146	6456
104	235	82	-117	142	6457
105	247	84	-117	134	6458
106	261	87	-117	146	7220
106	268	87	-117	146	7220
107	281	91	-117	152	7475
108	292	95	-117	161	7733
109	297	98	-117	173	8245
110	301	101	-117	179	7733
111	299	103	-117	186	6966
112	297	106	-117	193	6445
113	294	105	-117	200	6706
115	293	104	-117	190	6703
116	294	103	-117	191	5685

And this is the code I have so far:

private void filedataarray()
        {

            string path = "test.txt";
            //string path = (Chosen_File);
            using (StreamReader sr = new StreamReader(path))
                while (sr.ReadLine() != null)
                {
                    string[] line = sr.ReadLine().Split("\t".ToCharArray());
                    for (int i = 0; i < line.Length; i++)
                    {
                        ar1.Add(line[i]);
                        ar2.Add(line[i + 1]);
                        ar3.Add(line[i + 2]);
                        ar4.Add(line[i + 3]);
                        ar5.Add(line[i + 4]);
                        ar6.Add(line[i + 5]);

                        Convert.ToInt32(ar1[i]);
                        Convert.ToInt32(ar2[i]);
                        Convert.ToInt32(ar3[i]);
                        Convert.ToInt32(ar4[i]);
                        Convert.ToInt32(ar5[i]);
                        Convert.ToInt32(ar6[i]);

                        break;
                    }
                }

            pictureBox1.Refresh();
        }


        int x = 20;
        int ystart = 150;


        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            Pen mypen = new Pen(Color.Black);
            for (int i = 0; i < linecount; i++)
            {
                x = x + 5;
                e.Graphics.DrawLine(mypen, x, ystart, x + 5, ar1[i]);
            }
        }

I've been working on this for a while and I'm getting no further. I dont know what parts I need to change and I dont even know if I've gone about this the right way.

I'm not the best programmer in the world as you can probably tell so if anyone can point me in the right direction or help me in any way it would be much appreciated.

Thank you.

what are ar1, ar2, etc?
also,the convert to int32 is not doing anything.

also, what type of graph are you trying to create? just a plot of the values?if that is what you are trying to do then in the for loop, make "i" the x values of the graph and the start point will be the endpoint of the previous line.

hope it helps

Sorry, missed some code off.

The ar1, ar2 and so on are array lists

ArrayList ar1 = new ArrayList();

I need to get the convert int32 to convert the arraylist to int to plot the graph.
I'm trying to plot line graphs, seperate ones for each colmun of data in the txt file.

You could use the modulo operator (%) to extract a particular column.
Like i % 6 would give you columns from 0 to 5.
Also consider using a list of Point structures to store your coordinates.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.