[master] 19ae897 - Added chart-simple example

GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] 19ae897 - Added chart-simple example "Greg Ercolano" 19:47 Mar 18 top right image
 
commit 19ae897553eb38e432a52359b25f0d2c65e7753f
Author:     Greg Ercolano <erco@seriss.com>
AuthorDate: Thu Mar 18 19:41:27 2021 -0700
Commit:     Greg Ercolano <erco@seriss.com>
CommitDate: Thu Mar 18 19:41:27 2021 -0700

    Added chart-simple example

 examples/CMakeLists.txt   |  1 +
 examples/Makefile         |  1 +
 examples/chart-simple.cxx | 64 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+)

diff --git examples/CMakeLists.txt examples/CMakeLists.txt
index e047220..a81a569 100644
--- examples/CMakeLists.txt
+++ examples/CMakeLists.txt
@@ -30,6 +30,7 @@ file (MAKE_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})
 ############################################################
 
 set (SIMPLE_SOURCES
+  chart-simple
   browser-simple
   draggable-group
   howto-add_fd-and-popen
diff --git examples/Makefile examples/Makefile
index 50e7774..a4ffc12 100644
--- examples/Makefile
+++ examples/Makefile
@@ -6,6 +6,7 @@ SHELL = /bin/sh
 
 # Executables
 ALL = browser-simple$(EXEEXT) \
+      chart-simple$(EXEEXT) \
       clipboard$(EXEEXT) \
       draggable-group$(EXEEXT) \
       howto-add_fd-and-popen$(EXEEXT) \
diff --git examples/chart-simple.cxx examples/chart-simple.cxx
new file mode 100644
index 0000000..3f05b36
--- /dev/null
+++ examples/chart-simple.cxx
@@ -0,0 +1,64 @@
+//
+// Demonstrate how to use Fl_Chart in fltk
+//
+//     Demonstrates rudimentary features of Fl_Chart.
+//     Origin: http://seriss.com/people/erco/fltk/#Fl_Chart
+//
+// Copyright 2008 by Greg Ercolano.
+// Copyright 1998-2020 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file.  If this
+// file is missing or damaged, see the license at:
+//
+//     https://www.fltk.org/COPYING.php
+//
+// Please see the following page on how to report bugs and issues:
+//
+//     https://www.fltk.org/bugs.php
+//
+#include <FL/Fl.H>
+#include <FL/Fl_Window.H>
+#include <FL/Fl_Chart.H>
+#include <FL/Fl_Choice.H>
+#include <math.h>
+
+// Globals
+Fl_Window *G_win = 0;
+Fl_Chart  *G_chart = 0;
+Fl_Choice *G_choice = 0;
+
+// Fl_Choice callback for changing chart type()
+static void chart_type_cb(Fl_Widget *w, void*) {
+    const Fl_Menu_Item *item = G_choice->mvalue();  // item picked
+    G_chart->type( item->argument() );              // apply change
+    G_chart->redraw();
+    // printf("Choice: '%s', argument=%ld\n", G_choice->text(), item->argument());
+}
+
+// main
+int main() {
+    G_win = new Fl_Window(1000, 510, "Chart Simple");
+    // Fl_Chart with a sin() wave of data
+    G_chart = new Fl_Chart(20, 20, G_win->w()-40, G_win->h()-80, "Chart");
+    G_chart->bounds(-125.0, 125.0);
+    for ( double t=0; t<15; t+=0.5 ) {
+        double val = sin(t) * 125.0;
+        static char val_str[20];
+        sprintf(val_str, "%.0lf", val);
+        G_chart->add(val, val_str, (val<0)?FL_RED:FL_GREEN);
+    }
+    // Let user change chart type
+    G_choice = new Fl_Choice(140,470,200,25,"Chart Type: ");
+    G_choice->add("FL_BAR_CHART",        0, chart_type_cb, (void*)FL_BAR_CHART );
+    G_choice->add("FL_HORBAR_CHART",     0, chart_type_cb, (void*)FL_HORBAR_CHART);
+    G_choice->add("FL_LINE_CHART",       0, chart_type_cb, (void*)FL_LINE_CHART);
+    G_choice->add("FL_FILL_CHART",       0, chart_type_cb, (void*)FL_FILL_CHART);
+    G_choice->add("FL_SPIKE_CHART",      0, chart_type_cb, (void*)FL_SPIKE_CHART);
+    G_choice->add("FL_PIE_CHART",        0, chart_type_cb, (void*)FL_PIE_CHART);
+    G_choice->add("FL_SPECIALPIE_CHART", 0, chart_type_cb, (void*)FL_SPECIALPIE_CHART);
+    G_choice->value(0);
+    G_win->resizable(G_win);
+    G_win->show();
+    return(Fl::run());
+}
Direct Link to Message ]
 
bottom left image   bottom right image
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2021 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.