FCF 2.0 development in progress...
> > > > > >
[News] [C++ Libraries API] [C++ Downloads] [Donate to the project] [Contacts]

toBarChart() method from fcf::NTest::HistogramBasic class

std::string toBarChart() const
std::string toBarChart(size_t a_width, size_t a_height = 10) const
std::string toBarChart(TItem a_min, TItem a_max, size_t a_width, size_t a_height) const
[STATIC] std::string toBarChart(const std::vector<TCounter>& a_vector, TItem a_min, TItem a_max, size_t a_width, size_t a_height)

Class: fcf::NTest::HistogramBasic

Package: fcfTest

File: test.hpp

Available from version: 1.2.5

Generates an ASCII bar chart representing the histogram distribution.

The toBarChart method creates a visual ASCII bar chart of the histogram. This is particularly useful for quickly identifying the shape of the distribution (e.g., normal, skewed, or bimodal) directly in the console output.

Arguments

TItem a_min
- The minimum boundary for the chart.

TItem a_max
- The maximum boundary for the chart.

size_t a_width
- The width of the chart in characters.

size_t a_height
- The height of the chart in characters.
Result
std::string
- A string containing the ASCII bar chart.

Example: Generating an ASCII Bar Chart

Demonstrating how to generate a visual bar chart of the histogram.

#define FCF_TEST_IMPLEMENTATION #include <fcfTest/test.hpp> #include <iostream> FCF_TEST_DEFINE("HistogramDemo", "Chart", "GenerateChart") { fcf::NTest::HistogramBasic<int> hist(10, 0, 100); hist.append(10, 2); hist.append(20, 5); hist.append(30, 8); hist.append(40, 3); hist.append(50, 1); // 1. Generate chart with default height (4) std::string chart = hist.toBarChart(20, 4); fcf::NTest::log() << chart << std::endl; FCF_TEST(true); } int main(int a_argc, char* a_argv[]) { bool error = false; fcf::NTest::cmdRun(a_argc, a_argv, fcf::NTest::CRM_RUN, &error); return error ? 1 : 0; }

Output:

rm-red>/g" Performing the test: "HistogramDemo" -> "Chart" -> "GenerateChart" ... > || > ||| > ||||| > ||||||||| > ════════════════════ > OX (value): [0 : 100]; Step: 5.00 > OY (count): [0 : 4]; Step: 1.00 > [SUCCESS] Test completed successfully (0.000`071`342 sec) [SUCCESS] All tests were completed. Tests: 1 passed, 0 failed, 0 skipped, 1 total Duration: 0.000`071`342 sec