SVG File Bar Graph

Hey guys.

I am having a bit of an issue. I am writing a program to be output into an .svg file and it should look like a regular bar graph when I am through. I have it working almost 100% except for one issue. My bars on my bar graph are outputting downwards instead of upwards. I know that because the axis of the program starts in the upper left hand corner however I have tried to turn the integers to negative integers and it does not work. I am not sure how else to do so, so if you could help me out that would be greatly appreciated!

The code I currently have is this:

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
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
	int number1(0);
	int number2(0);
	int number3(0);
	int number4(0);
	
	ofstream fout;
	
	fout.open("rectline.svg");

	if (fout.fail())
	{
		cout << "File rectline.svg is not able to be opened.";
		return 1;
	}

	cout << "Please input your four numbers separated by spaces: " << endl;
	cin >> number1 >> number2 >> number3 >> number4;

	fout << "<?xml version=\"1.0\" standalone=\"no\"?>"<< endl;
	fout << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"" << endl;
	fout << "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">" << endl;
	fout << "<svg width=\"500\" height=\"500\"" << endl; 
	fout << "xmlns=\"http://www.w3.org/2000/svg\">" << endl;

	fout << "<rect x=\"" << 0 <<"\" y=\"" << 300 << "\" width=\"" << 25 << "\" height=\"" << number1 << "\" style=\"fill:blue;\"/>" << endl;
	fout << "<rect x=\"" << 25 << "\" y=\"" << 300 << "\" width=\"" << 130 << "\" height=\"" << number2 << "\" style=\"fill:rgb(0,255,0);\"/>" << endl;
	fout << "<rect x=\"" << 155 <<"\" y=\"" << 300 << "\" width=\"" << 25 << "\" height=\"" << number3 << "\" style=\"fill:blue;\"/>" << endl;
	fout << "<rect x=\"" << 180 << "\" y=\"" << 300 << "\" width=\"" << 130 << "\" height=\"" << number4 << "\" style=\"fill:rgb(0,255,0);\"/>" << endl;

	fout << "<line x1=\"" << 0 << "\" y1=\"" << 0 << "\" x2=\"" << 0 << "\" y2=\"" << 300 << "\" style=\"stroke:purple;stroke-width:2\"/>" << endl;
	fout << "<line x1=\"" << 0 << "\" y1=\"" << 300 << "\" x2=\"" << 300 << "\" y2=\"" << 300 << "\" style=\"stroke:purple;stroke-width:2\"/>" << endl;

	fout << "</svg>" << endl;

	fout.close();

	return 0;
}
Topic archived. No new replies allowed.