Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jerr-it/sfgraphing
C++ Plot Library for SFML
https://github.com/jerr-it/sfgraphing
cpp graph hacktoberfest plot plots plotting sfml
Last synced: about 2 months ago
JSON representation
C++ Plot Library for SFML
- Host: GitHub
- URL: https://github.com/jerr-it/sfgraphing
- Owner: jerr-it
- License: mit
- Created: 2020-03-27T21:42:24.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-10-31T19:13:56.000Z (about 2 years ago)
- Last Synced: 2024-06-12T19:00:06.992Z (7 months ago)
- Topics: cpp, graph, hacktoberfest, plot, plots, plotting, sfml
- Language: C++
- Homepage:
- Size: 637 KB
- Stars: 21
- Watchers: 3
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
SFGraphing
A C++ Plot Library to be used in combination with SFML
Newest Version
Entirely rewritten for better readability.
Added Piecharts!
You can now set Position and Dimension of PlotsHow to use
Documentation at: https://jerr-it.github.io/SFGraphing/
The file main.cpp provides more details on how to use this library
By default a sample program will be created.
How to compile this example
```
cmake .
make graphing
./graphing
```
Depending on your OS and installation, you might need to adjust the SFML path in SFPlot/CMakeLists.txt to fit your installation of SFML.
Include header in your main file
```c++
#include "SFGraphing/SFPlot.h"
#include "SFGraphing/SFPieChart.h"
```Important: You need a font, otherwise text wont display!
```c++
sf::Font font;
font.loadFromFile("YourFontHere.ttf");
```Plot
Create a dataset
```c++
std::vector xAxis = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::vector yAxis = {1, 2, 3, 4, 5, 6, 5, 6, 7, 8};PlotDataSet set(xAxis, yAxis, sf::Color::Green, "Green Data", PlottingType::LINE);
```
Available plotting types are POINTS, LINE and BARSCreate your plot and add your dataset
```c++
//Position, dimension, margin, font
SFPlot plot(sf::Vector2f(800, 0), sf::Vector2f(800, 800), 50, &font, "X Axis", "Y Axis");
plot.AddDataSet(&set);
```Initialize the plott
```c++
//x-minimum, x-maximum, y-minimum, y-maximum, x-step-size, y-step-size, Color of axes
plot.SetupAxes(0, 10, 0, 10, 1, 1, sf::Color::White);
plot.GenerateVertices();
```
In case you want SFPlot to determine the axes scaling and numbering automatically, call without parameters:
```c++
plot.SetupAxes();
plot.GenerateVertices();
```
Display data (int your window loop)
```c++
window.clear();
window.draw(plot);
window.display();
```
Want to update data in real time?
```c++
window.clear();
plot.ClearVertices();set.SetDataValue(0, set.GetDataValue(0) + sf::Vector2f(0, 0.001));
plot.SetupAxes();
plot.GenerateVertices();window.draw(plot);
window.display();
```Pie Chart
Create dataset
```c++
std::vector values = {100, 230, 150, 100};
std::vector colors = {sf::Color::Blue, sf::Color::Red, sf::Color::Magenta, sf::Color::Cyan};
std::vector labels = {"A", "B", "C", "D"};
//Representations: ABSOLUTE, RELATIVE
PieChartDataSet pSet(values, labels, Representation::RELATIVE, colors);
```
Create PieChart
```c++
//Dataset, Position, Radius, Font
SFPieChart pChart(&pSet, sf::Vector2f(250, 400), 200, &font);
```
Initialize
```c++
pChart.GenerateVertices();
```
Display
```c++
window.clear();
window.draw(pChart);
window.display();
```
Update data in real time?
```c++
window.clear();
pChart.ClearVertices();pSet.SetValue(0, pSet.GetValue(0) + 0.003);
pChart.GenerateVertices();
window.draw(pChart);
window.display();
```