Bar Chart Demo

Bar Chart Demo

Source: bar_chart_demo.f90

Demonstrates grouped bar charts (vertical and horizontal) via both the stateful API and figure_t.

  • bar_chart_demo.f90 - Source demonstrating grouped and horizontal bars
  • Generated outputs in output/example/fortran/bar_chart_demo/

  • Grouped bars: Compare multiple series per category

  • Horizontal bars: Present ranked metrics across categories
  • OO workflow: Call bar_impl with an explicit figure_t instance to avoid globals
  • Multiple formats: Save PNG, PDF, and ASCII outputs for each scenario

Running the demo generates: - stateful_grouped.(png|pdf|txt) - Vertical grouped comparison - stateful_horizontal.(png|pdf|txt) - Horizontal completion chart - oo_grouped.(png|pdf|txt) - Object API grouped budget comparison

Perfect for showcasing categorical comparisons and verifying bar chart support in fortplot.

Files

  • bar_chart_demo.f90 - Source code
  • Generated media in output/example/fortran/bar_chart_demo/

Running

make example ARGS="bar_chart_demo"

Output

Categorical Labels

categorical_labels.png

ASCII output:

                      Categorical Bar Chart - Fruit Sales
+--------------------------------------------------------------------------------+
| 60                                                                             |
| 50                                                                             |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |0                                                                             |
| |                                                                              |
| |                                                                              |
| |0                                                                             |
| |                                              ------------                    |
| |                 ------------                 ------------                    |
| |                 ------------                 ------------  -------------     |
| |0 -------------  ------------                 ------------  -------------     |
| |  -------------  ------------  -------------  ------------  -------------     |
| |  -------------  ------------  -------------  ------------  -------------     |
| |0 -------------  ------------  -------------  ------------  -------------     |
| |  -------------  ------------  -------------  ------------  -------------     |
| |  -------------  ------------  -------------  ------------  -------------     |
| |  -------------  ------------  -------------  ------------  -------------     |
| |  ------------- ------------- --------------- ------------- -------------   - |
| 0       Apples         Oranges        Bananas        Grapes         Mangoes    |
+--------------------------------------------------------------------------------+
                                   Fruit Type
Units Sold

Download ASCII

Download PDF

Oo Grouped

oo_grouped.png

ASCII output:

                     Object API - grouped budget comparison
+--------------------------------------------------------------------------------+
| 4.8                                                                            |
| 4.0                                                                            |
| |                                                                              |
| |                                                                # Baseline    |
| |                                                                # Projected   |
| |                                                                              |
| |                                                                              |
| |.2                                                                            |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |.4                                                                            |
| |                                                                #+++#+++#     |
| |                                                      ----------#+++++++#     |
| |.6         #+++#++++#       --------- #+++#+++#       ----------#+++++++#     |
| |           #++++++++#       --------- #+++++++#       ----------#+++++++#     |
| |  ---------#++++++++#       --------- #+++++++#       ----------#+++++++#     |
| |  ---------#++++++++#       --------- #+++++++#       ----------#+++++++#     |
| |.8---------#++++++++#       --------- #+++++++#       ----------#+++++++#     |
| |  ---------#++++++++#       --------- #+++++++#       ----------#+++++++#     |
| |  ---------#++++++++#       --------- #+++++++#       ----------#+++++++#     |
| |  ---------#++++++++#       --------- #+++++++#       ----------#+++++++#     |
| |  ---------#+++#++-+#   -   ----------#+++#-++#   -   ----------#+++#-++#  -  |
| 0.0        Team 1                     Team 2                     Team 3        |
+--------------------------------------------------------------------------------+
                                      Team
Quarterly budget (M)

Download ASCII

Download PDF

Stacked Bars

stacked_bars.png

ASCII output:

                    Stacked Bar Chart - Department Expenses
+--------------------------------------------------------------------------------+
| 36                                                                             |
| |                                                                              |
| |                                                                              |
| |                                                            # Manufacturing   |
| |                                                            # Sales           |
| |0                                                           # R&D             |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |4                                                                             |
| |                                                                              |
| |                                                                              |
| |8                                                        #===#===#==#===#     |
| |                    #===#===#==#===#   #===#==#===#===#  #==============#     |
| |                    #==============#   #==============#  #==============#     |
| |  #===#==#===#===#  #+++#+++#++#+++#   #+++#++#+++#+++#  #+++#+++#++#+++#     |
| |2 #==============#  #++++++++++++++#   #++++++++++++++#  #++++++++++++++#     |
| |  #+++#++#+++#+++#  #++++++++++++++#   #++++++++++++++#  #---#---#--#---#     |
| |  #++++++++++++++#  #---#---#--#---#   #---#--#---#---#  ----------------     |
| |  #---#--#---#---#  ----------------   ----------------  ----------------     |
| |  ----------------  ----------------   ----------------  ----------------     |
| |  ----------------  ----------------   ----------------  ----------------     |
| |  ----------------  ----------------   ----------------  ----------------     |
| |  ----------------  ----------------   ----------------  ----------------   - |
| 0  0.6        1.2        1.8        2.4        3.0         3.6        4.2      |
+--------------------------------------------------------------------------------+
                                    Quarter
Expenses (million )

Download ASCII

Download PDF

Stateful Grouped

stateful_grouped.png

ASCII output:

                        Stateful API - grouped bar chart
+--------------------------------------------------------------------------------+
| 7                                                                              |
| |                                                                              |
| |                                                                              |
| |                                                                # Product A   |
| |                                                                # Product B   |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| |                                                         ---------            |
| |                                       --------          ---------            |
| |                    ---------          -------#+++#+++#  --------#+++#++#     |
| |                    ---------          -------#+++++++#  --------#++++++#     |
| |  --------          --------#++#+++#   -------#+++++++#  --------#++++++#     |
| |  --------          --------#++++++#   -------#+++++++#  --------#++++++#     |
| |  -------#+++#+++#  --------#++++++#   -------#+++++++#  --------#++++++#     |
| |  -------#+++++++#  --------#++++++#   -------#+++++++#  --------#++++++#     |
| |  -------#+++++++#  --------#++++++#   -------#+++++++#  --------#++++++#     |
| |  -------#+++++++#  --------#++++++#   -------#+++++++#  --------#++++++#     |
| |  -------#+++#+++#  --------#++#+++#   -------#+++#+++#  --------#+++#++#     |
| |   -    -   -    -   -    -   -    -   -    -   -    -   -    -  #-    -    - |
| 0         Q1                 Q2                Q3                 Q4           |
+--------------------------------------------------------------------------------+
                                    Quarter
Revenue (million )

Download ASCII

Download PDF

Stateful Horizontal

stateful_horizontal.png

ASCII output:

                      Stateful API - horizontal bar chart
+--------------------------------------------------------------------------------+
|                                                                                |
| |                                                                              |
| 4.0                                                                            |
| |                                                 # Certification completion   |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| 3.5                                                                            |
| |.0                                                                            |
| |                                                                              |
| |                                                                              |
| |                                                                              |
| 2.5                                                                            |
| |.0-----------------------------------------------------------------------     |
| |  -----------------------------------------------------------------------     |
| |  -----------------------------------------------------------------------     |
| |  ------------------------------------------------------------------          |
| 1.5------------------------------------------------------------------          |
| |  ----------------------------------------------------                        |
| |  ----------------------------------------------------                        |
| |  ----------------------------------------------------                        |
| |----------------------------------------------------------------------------- |
| 1.00          15          30          45          60          75         90    |
+--------------------------------------------------------------------------------+
                                 Completion (%)
Training module

Download ASCII

Download PDF