Skip to content

a simple function to plot numeric data to console for C++

License

Notifications You must be signed in to change notification settings

mkh-welsch/ascii_chart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

ascii_chart

a simple function to plot numeric data to the console

#include <vector>
#include <deque>

#include "ascii_chart.hpp"

int main()
{
    

    std::vector<double> shittyCoins = {8125.17, 7708.33, 7564.55, 7646.64, 7753.41, 7693.49, 7358.39, 7674.39, 7281.93, 7903.8, 7323.2, 7170.57, 7249.56, 7206.6, 6707.28, 6598.78, 6386.62, 6509.2, 6781.98, 6489.95, 6389.41, 6419.53, 5619.26, 5538.32, 5496.59, 5723.65, 5616.4, 5393.2, 5533.34, 5540.32, 6047.44, 5738.6, 5537.4, 5628.48, 5552.7, 5766.58, 6460.53, 6292.35, 6548.82, 6848.4, 6907.96, 7221.28, 7076.17, 7222.92, 7336.39, 6974.21, 6682.95, 6422.98, 6762.51, 6717.97, 6635.58, 7386.57, 7400.51, 7733.22, 7139.3, 7526.17, 7568.4, 7993.24, 8636.84, 9331.27, 9309.29, 9282.56, 8957.7, 8896.55, 8473.94, 8681.35, 8377.27, 7803.7, 7887.15, 8269.69, 7986.66, 8517.62, 9099.61, 9005.61, 8384.27, 8931.29, 8204.1, 8061.17, 7608.88, 6911.79, 7234.79, 6587.95, 6993.13, 7094.29, 6746.55, 6160.39, 6224.76, 5577.17, 6595.92, 7399.89, 7104.31, 7267.86, 8201.88, 8117.27, 9045.72, 9445.22, 9191.48, 8938.8, 9014.58, 9179.26};

    ascii_chart::plot(shittyCoins);
 /*   
    9445.22 ┤                                                          ┌──┐                                ┌┐
    9191.97 ┤                                                          │  │         ┌─┐                   ┌┘└┐
    8938.72 ┤                                                          │  └─┐       │ │┌┐                 │  └
    8685.47 ┤                                                         ┌┘    │┌┐    ┌┘ │││                 │
    8432.21 ┤                                                         │     └┘└┐ ┌┐│  └┘│                 │
    8178.96 ┼┐                                                       ┌┘        │ │└┘    └─┐             ┌─┘
    7925.71 ┤│  ┌┐   ┌┐                                          ┌┐  │         └─┘        │             │
    7672.46 ┤└──┘└┐┌┐││                                          ││┌─┘                    └┐            │
    7419.21 ┤     └┘└┘└┐┌┐                           ┌┐┌─┐     ┌─┘││                       │┌┐       ┌┐┌┘
    7165.96 ┤          └┘└┐                          │└┘ └┐    │  └┘                       │││┌─┐    │└┘
    6912.71 ┤             │   ┌┐                   ┌─┘    │ ┌─┐│                           └┘││ └┐   │
    6659.46 ┤             └─┐┌┘└┐               ┌┐┌┘      └┐│ └┘                             └┘  │  ┌┘
    6406.20 ┤               └┘  └─┐             │└┘        └┘                                    │┌┐│
    6152.95 ┤                     │       ┌┐    │                                                └┘││
    5899.70 ┤                     │  ┌┐   │└┐  ┌┘                                                  ││
    5646.45 ┤                     └──┘└┐┌─┘ └──┘                                                   └┘
    5393.20 ┤                          └┘
*/

    int width = 120;
    int heigth = 10;
    std::deque<double> dataSignal(width);
    for (int i = 0; i < dataSignal.size(); i++)
        dataSignal[i] = double(heigth) * std::sin(double(i) * ((3.1424 * 4) / double(dataSignal.size())));

    ascii_chart::plot(dataSignal,heigth,width);
/*
  10.00 ┤          ┌────────┐                                                  ┌────────┐
   8.00 ┤       ┌──┘        └──┐                                            ┌──┘        └──┐
   6.00 ┤    ┌──┘              └─┐                                       ┌──┘              └─┐
   4.00 ┤  ┌─┘                   └──┐                                  ┌─┘                   └──┐
   2.00 ┤┌─┘                        └─┐                              ┌─┘                        └─┐
   0.00 ┼┘                            └┐                            ┌┘                            └┐   
  -2.00 ┤                              └─┐                        ┌─┘                              └─┐
  -4.00 ┤                                └─┐                   ┌──┘                                  └─┐                   ┌──
  -6.00 ┤                                  └──┐              ┌─┘                                       └──┐              ┌─┘
  -8.00 ┤                                     └──┐        ┌──┘                                            └──┐        ┌──┘
 -10.00 ┤                                        └────────┘                                                  └────────┘

*/
    

    return 0;
}

About

a simple function to plot numeric data to console for C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages