如何设置条形图的起点
How to set the start point of bar chart
我正在使用 SFML 库和 Visual-C++ 创建条形图。我想设置条形图的起始点,所以我尝试使用move和setOrigin函数,但都不成功
sf::RectangleShape rec1(sf::Vector2f(stage1x*1000, stage1y*1000));
sf::RectangleShape rec2(sf::Vector2f(stage2x*1000, stage2y*1000));
sf::RectangleShape rec3(sf::Vector2f(stage3x*1000, stage3y*1000));
rec1.setOrigin(0, 0);
rec2.setOrigin(0, 0);
rec3.setOrigin(0, 0);
rec1.move(200, 700); // This moves the Rectangle over 200 pixels and down 700 pixels
rec2.move(300, 700); // This moves the Rectangle over 300 pixels and down 700 pixels
rec3.move(400, 700); // This moves the Rectangle over 400 pixels and down 700 pixels
rec1.setFillColor(sf::Color(100, 250, 50));
rec2.setFillColor(sf::Color(10, 20, 100));
rec3.setFillColor(sf::Color(500, 600, 700));
为此有很多不同的方法。例如,您可以将 window 的 sf::View
的高度设置为负值,这实际上会垂直翻转所有内容(坐标 运行 从下到上)。
setOrigin()
在 SFML 的可绘制对象上只会移动它们的本地原点,即确定哪个点与 setPosition()̀
中给定的位置对齐。默认情况下,原点设置为 (0, 0)
,因此您的代码不会更改任何内容。
而不是使用 move()
,我会直接调用 setPosition()
(这是设置绝对位置而不是相对位置)。如果您希望条形向上,请如上所述翻转视图,或者简单地从 Y 位置减去条形的高度。
我正在使用 SFML 库和 Visual-C++ 创建条形图。我想设置条形图的起始点,所以我尝试使用move和setOrigin函数,但都不成功
sf::RectangleShape rec1(sf::Vector2f(stage1x*1000, stage1y*1000));
sf::RectangleShape rec2(sf::Vector2f(stage2x*1000, stage2y*1000));
sf::RectangleShape rec3(sf::Vector2f(stage3x*1000, stage3y*1000));
rec1.setOrigin(0, 0);
rec2.setOrigin(0, 0);
rec3.setOrigin(0, 0);
rec1.move(200, 700); // This moves the Rectangle over 200 pixels and down 700 pixels
rec2.move(300, 700); // This moves the Rectangle over 300 pixels and down 700 pixels
rec3.move(400, 700); // This moves the Rectangle over 400 pixels and down 700 pixels
rec1.setFillColor(sf::Color(100, 250, 50));
rec2.setFillColor(sf::Color(10, 20, 100));
rec3.setFillColor(sf::Color(500, 600, 700));
为此有很多不同的方法。例如,您可以将 window 的 sf::View
的高度设置为负值,这实际上会垂直翻转所有内容(坐标 运行 从下到上)。
setOrigin()
在 SFML 的可绘制对象上只会移动它们的本地原点,即确定哪个点与 setPosition()̀
中给定的位置对齐。默认情况下,原点设置为 (0, 0)
,因此您的代码不会更改任何内容。
而不是使用 move()
,我会直接调用 setPosition()
(这是设置绝对位置而不是相对位置)。如果您希望条形向上,请如上所述翻转视图,或者简单地从 Y 位置减去条形的高度。