Skip to content

Latest commit

 

History

History
137 lines (114 loc) · 3.29 KB

README.md

File metadata and controls

137 lines (114 loc) · 3.29 KB

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 Plots

How 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

#include "SFGraphing/SFPlot.h"
#include "SFGraphing/SFPieChart.h"

Important: You need a font, otherwise text wont display!

sf::Font font;
font.loadFromFile("YourFontHere.ttf");

Plot

Create a dataset

std::vector<float> xAxis = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
std::vector<float> 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 BARS

Create your plot and add your dataset

//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

//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:

plot.SetupAxes();
plot.GenerateVertices();

Display data (int your window loop)

window.clear();
window.draw(plot);
window.display();

Want to update data in real time?

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

std::vector<float> values = {100, 230, 150, 100};
std::vector<sf::Color> colors = {sf::Color::Blue, sf::Color::Red, sf::Color::Magenta, sf::Color::Cyan};
std::vector<std::string> labels = {"A", "B", "C", "D"};
//Representations: ABSOLUTE, RELATIVE
PieChartDataSet pSet(values, labels, Representation::RELATIVE, colors);

Create PieChart

//Dataset, Position, Radius, Font
SFPieChart pChart(&pSet, sf::Vector2f(250, 400), 200, &font);

Initialize

pChart.GenerateVertices();

Display

window.clear();
window.draw(pChart);
window.display();

Update data in real time?

window.clear();
pChart.ClearVertices();

pSet.SetValue(0, pSet.GetValue(0) + 0.003);

pChart.GenerateVertices();
window.draw(pChart);
window.display();