Horrizontal bar chart

i currently have a vertical bar chart and am trying to convert it to a horizontal one for a exercise in a book. I just can't figure out how to make the bars change to the other direction. Any help would be appreciated. Below is the code for the chart.. as well as some extra code for the program.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#pragma endregion

		Pen^ blackPen;
		Graphics^ g1;
		Graphics^ g2;
		Brush^ blackBrush;
		Brush^ redBrush;
		System::Drawing::Font^ arial6Font;


private: System::Void btnSort_Click(System::Object^  sender, System::EventArgs^  e) {

			 int data[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
			 int n = 20;
			 int i, j;
			 int smallIndex;

			 //DrawArray(data, n); //draw unsorted array in panel1

			 
			 //insert selection sort code
			 for (i = 0; i < n-1; i++)
			 {
				 //find the smallest unsorted value
				 //set location of smallIndex to 1
				 smallIndex = i;
				 //compare all elements from data[i+1] to data [n-1]
				 for (j = i+1; j < n; j++)
					 if (data[j] > data[smallIndex]) smallIndex = j;
				 //swap the value in data[smallindex] with data[i]
				 Swap(data[i], data[smallIndex]);
			 }
			
			 DrawArray(data, n); // draw sorted array in panel2
			 
		}


this code draws the chart itself:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
private: void DrawArray(int arr[], int n){

			 int x = 40;
			 int y = 0;
			 int height = 12;
			 int width = 1;
			 Graphics^ g;


			 panel1->Refresh();
			 g = g1;

			 for (int i = 0; i < 20; i++)
			 {

					 y += height;
					 width = arr[i];
					 
					 g->DrawString(arr[i].ToString(), arial6Font, blackBrush,x-30,y);					
						 
						 Rectangle bar(x, y, width, height);
						 g->DrawRectangle(blackPen,bar);
						 //g->FillRectangle(redBrush, bar);

			 }
		 }



i did some modifying and did make it more horizontal and made it look better, however it needs to be rotated and haven't figured out how to do so.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
private: void DrawArray(int arr[], int n){

			 int x = 0;
			 int y = 100;
			 int height = 1;
			 int width = 13;
			 Graphics^ g;


			 panel1->Refresh();
			 g = g1;

			for (int i = 0; i < n; i++)
			 {

					 x += width+1;

					 height = arr[i];
					 
					 g->DrawString(arr[i].ToString(), arial6Font, blackBrush,x,y-13);					
						 
						 Rectangle bar(x, y, width, height);
						 g->DrawRectangle(blackPen,bar);
						 g->FillRectangle(redBrush, bar);

			 }
		 }
Topic archived. No new replies allowed.