A port of the npm package asciichart by Igor Kroitor.
Just used to plot ascii line charts, no dependencies.
This is a header only library, you can copy all files in include directory to your project.
The width of the chart equals to the length of data series. The height and range will be determined automatically. Users can specify:
- height: height of chart.
- offset: axis offset from the left (min 2).
- colors: colors used in chart.
- min: min value.
- max: max value.
- symbols: symbols used in chart.
- TODO type: type of chart, LINE, CIRCLE.
std::vector<double> series; // range from -15 to +15
for (int i = 0; i < 200; i += 2)
{
series.push_back(15 * std::cos(i * (kPI * 8) / 120));
}
Asciichart asciichart(std::vector<std::vector<double>>{series});
std::cout << '\n'
<< asciichart.height(10).Plot() // rescale to -3 ~ +3 lines
<< '\n';
std::vector<double> series;
for (int i = 0; i < 200; i += 2)
{
series.push_back(15 * std::cos(i * (kPI * 8) / 120));
}
std::vector<double> series2;
for (int i = 0; i < 200; i += 2)
{
series2.push_back(15 * std::sin(i * ((kPI * 4) / 100)));
}
Asciichart asciichart(std::vector<std::vector<double>>{series, series2});
std::cout << '\n'
<< asciichart.height(6).Plot()
<< '\n';
void example_legend2() {
using namespace ascii;
std::vector<double> series;
std::vector<double> series2;
for (int i = 0; i < 100; i += 2) {
series.push_back(15 * std::cos(i * (kPI * 8) / 120));
series2.push_back(15 * std::sin(i * ((kPI * 4) / 100)));
}
Asciichart asciichart({{"A", series}, {"B", series2}});
std::cout << asciichart.show_legend(true).height(6).Plot();
}
std::vector<double> series;
std::vector<double> series2;
int height = 6;
for (int i = 0; i < 100; i += 2) {
series.push_back(15 * std::cos(i * (kPI * 8) / 120));
series2.push_back(15 * std::sin(i * ((kPI * 4) / 100)));
Asciichart asciichart(std::vector<std::vector<double>>{series, series2});
if (i != 0) {
for (int j = 0; j <= height; j++) {
std::cout << "\033[A\033[2K";
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
std::cout << asciichart.height(height).Plot();
}