Top |
GlgLineGraph * | glg_line_graph_new () |
void | glg_line_graph_redraw () |
GLGElementID | glg_line_graph_chart_get_elements () |
void | glg_line_graph_chart_set_elements () |
gboolean | glg_line_graph_chart_set_text () |
gboolean | glg_line_graph_chart_set_color () |
void | glg_line_graph_chart_set_ranges () |
void | glg_line_graph_chart_set_x_ranges () |
void | glg_line_graph_chart_set_y_ranges () |
gint | glg_line_graph_data_series_add () |
gboolean | glg_line_graph_data_series_add_value () |
gint | chart-set-elements | Write |
gchar * | graph-chart-background | Write |
gchar * | graph-scale-foreground | Write |
gchar * | graph-title-foreground | Write |
gchar * | graph-window-background | Write |
gint | range-scale-major-x | Write |
gint | range-scale-major-y | Write |
gint | range-scale-minor-x | Write |
gint | range-scale-minor-y | Write |
gint | range-tick-major-x | Write |
gint | range-tick-major-y | Write |
gint | range-tick-minor-x | Write |
gint | range-tick-minor-y | Write |
gint | series-line-width | Read / Write |
gchar * | text-title-main | Write |
gchar * | text-title-xaxis | Write |
gchar * | text-title-yaxis | Write |
A Gtk+3/GLib2/Cairo GUI application which demonstrates the use of GTK+ and cairo for producing xy line graphs. This widget once created allows you to add one or more data series, then add values to those series for plotting. The X point is assumed based on arrival order. However, the Y value or position is based on the current scale and the y value itself. If the charts x scale maximum is 40, or 40 points, the 41+ value is appended to the 40th position after pos 0 is dropped - effectively rolling the x points from right to left in the chart view.
FEATURES
Packaged as a gtk widget for ease of use and easy inclusion into new or existing programs.
The GlgLinegraph widget has a gobject property for every control option except creating a
new data series glg_line_graph_series_add()
, and adding a value to that series with
glg_line_graph_series_add_value()
.
One signal is available 'point-selected' which outputs the Y value most likely under the mouse ptr. For correlation purposes the position of the mouse and the position of the Y point is given in case two or more points are returned.
The scale or range of the chart is dependant on the Y-values. For value greater than 1, the range/scale should be set to whole numbers say 0 to 100. For values less than 1, use a range/scale of 0 to 1 .
The following api's will create a version of this line graph:
Example 1. Using a GlgLineGraph with gobject methods.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
#include <gtk/gtk.h> #include <glg_cairo.h> ... GlgLineGraph *glg = NULL; gint i_series_0 = 0, i_series_1 = 0; ... glg = glg_line_graph_new( "range-tick-minor-x", 1, "range-tick-major-x", 2, "range-scale-minor-x", 0, "range-scale-major-x", 40, "range-tick-minor-y", 5, "range-tick-major-y", 10, "range-scale-minor-y", 0, "range-scale-major-y", 100, "chart-set-elements", GLG_TOOLTIP | GLG_GRID_LABELS_X | GLG_GRID_LABELS_Y | GLG_TITLE_T | GLG_TITLE_X | GLG_TITLE_Y | GLG_GRID_LINES | GLG_GRID_MINOR_X | GLG_GRID_MAJOR_X | GLG_GRID_MINOR_Y | GLG_GRID_MAJOR_Y, "series-line-width", 3, "graph-title-foreground", "blue", "graph-scale-foreground", "red", "graph-chart-background", "light blue", "graph-window-background", "white", "text-title-main", "This Top Title Line ", "text-title-yaxis", "This is the Y axis title line.", "text-title-xaxis", "This is the X axis title line.", NULL); gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(glg)); gtk_widget_show_all (window); i_series_0 = glg_line_graph_data_series_add (glg, "Volts", "red"); i_series_1 = glg_line_graph_data_series_add (glg, "Battery", "blue"); glg_line_graph_data_series_add_value (glg, i_series_0, 66.0); glg_line_graph_data_series_add_value (glg, i_series_0, 73.0); glg_line_graph_data_series_add_value (glg, i_series_1, 56.8); glg_line_graph_data_series_add_value (glg, i_series_1, 83.6); glg_line_graph_redraw ( graph ); |
Or the following standard api method will also work.
Example 2. Using a GlgLineGraph with standard APIs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#include <gtk/gtk.h> #include <glg_cairo.h> ... GlgLineGraph *glg = NULL; gint i_series_0 = 0, i_series_1 = 0; ... glg = glg_line_graph_new(NULL); glg_line_graph_chart_set_x_ranges (glg, 1, 2,0, 40); glg_line_graph_chart_set_y_ranges (glg, 5,10,0,100); glg_line_graph_chart_set_elements (glg, GLG_TOOLTIP | GLG_GRID_LABELS_X | GLG_GRID_LABELS_Y | GLG_TITLE_T | GLG_TITLE_X | GLG_TITLE_Y | GLG_GRID_LINES | GLG_GRID_MINOR_X | GLG_GRID_MAJOR_X | GLG_GRID_MINOR_Y | GLG_GRID_MAJOR_Y ); glg_line_graph_chart_set_text (glg, GLG_TITLE_T, "This Top Title Line " ); glg_line_graph_chart_set_text (glg, GLG_TITLE_Y, "This is the y label." ); glg_line_graph_chart_set_text (glg, GLG_TITLE_X, "This is the x label" ); glg_line_graph_chart_set_color (glg, GLG_TITLE, "blue"); glg_line_graph_chart_set_color (glg, GLG_SCALE, "read"); glg_line_graph_chart_set_color (glg, GLG_CHART, "light blue"); glg_line_graph_chart_set_color (glg, GLG_WINDOW, "white"); gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(glg)); gtk_widget_show_all (window); i_series_0 = glg_line_graph_data_series_add (glg, "Volts", "red"); i_series_1 = glg_line_graph_data_series_add (glg, "Battery", "blue"); glg_line_graph_data_series_add_value (glg, i_series_0, 66.0); glg_line_graph_data_series_add_value (glg, i_series_0, 73.0); glg_line_graph_data_series_add_value (glg, i_series_1, 56.8); glg_line_graph_data_series_add_value (glg, i_series_1, 83.6); glg_line_graph_redraw ( glg ); |
A 'lgcairo.c' demonstration proram is included to illustrate how to quickly use the widget.
GlgLineGraph * glg_line_graph_new (const gchar *first_property_name
,...
);
Creates a new line graph widget
optionally accepts 'property-name, property-values',...,NULL pairs
void
glg_line_graph_redraw (GlgLineGraph *graph
);
Updates the current graph showing new changes.
GLGElementID
glg_line_graph_chart_get_elements (GlgLineGraph *graph
);
Retrieves the current draw setting for the graph. AND it with the desired value to test if what your after is present.
void glg_line_graph_chart_set_elements (GlgLineGraph *graph
,GLGElementID element
);
Controls whether the grids, labels, tooltip, and titles will appear on the chart.
All graphs are created with the following defaults;
GLG_TOOLTIP
|
GLG_GRID_LABELS_X
| GLG_GRID_LABELS_Y
| GLG_TITLE_T
| GLG_TITLE_X
| GLG_TITLE_Y
|
GLG_GRID_LINES
| GLG_GRID_MINOR_X
| GLG_GRID_MAJOR_X
| GLG_GRID_MINOR_Y
| GLG_GRID_MAJOR_Y
graph |
pointer to a GlglineGraph widget |
|
element |
An or'ed list of GLGElementID indicating what graph elements should be drawn to the screen. |
gboolean glg_line_graph_chart_set_text (GlgLineGraph *graph
,GLGElementID element
,const gchar *pch_text
);
Copy (without freeing) pch_text into place to be used as the graph title. PangoMarkup is also supported.
GLG_TITLE_X - Bottom x axis title GLG_TITLE_Y - Left vertical y axis title GLG_TITLE_T - Top and considered main title on x axis
graph |
pointer to a GlgLineGraph widget |
|
element |
GLGElementID of the Title |
|
pch_text |
gchar* string to set in title. |
gboolean glg_line_graph_chart_set_color (GlgLineGraph *graph
,GLGElementID element
,const gchar *pch_color
);
Copy (without freeing) pch_color into place to be used as the graph element color. GLG_SCALE - x/y integer legends color {default black} GLG_TITLE - Main graph title. {default light blue} GLG_WINDOW - Graph window background color, and grid foreground. {default white} GLG_CHART - Graph plot area background. {default light blue}
graph |
pointer to a GlgLineGraph widget |
|
element |
GLGElementID of the Window Element |
|
pch_color |
gchar* string with name of color. |
void glg_line_graph_chart_set_ranges (GlgLineGraph *graph
,gint x_tick_minor
,gint x_tick_major
,gint x_scale_min
,gint x_scale_max
,gint y_tick_minor
,gint y_tick_major
,gint y_scale_min
,gint y_scale_max
);
Sets the X and Y ticks and scales for the graph grid area.
graph |
pointer to a GlgLineGraph widget |
|
x_tick_minor |
number of minor divisions for x scale |
|
x_tick_major |
number of major divisions for x scale |
|
x_scale_min |
minimum x scale value or starting point |
|
x_scale_max |
maximum x scale value or ending point |
|
y_tick_minor |
number of minor divisions for y scale |
|
y_tick_major |
number of major divisions for y scale |
|
y_scale_min |
minimum y scale value or starting point |
|
y_scale_max |
maximum y scale value or ending point |
void glg_line_graph_chart_set_x_ranges (GlgLineGraph *graph
,gint x_tick_minor
,gint x_tick_major
,gint x_scale_min
,gint x_scale_max
);
Sets the X ticks and scales for the graph grid area.
graph |
pointer to a GlgLineGraph widget |
|
x_tick_minor |
number of minor divisions for x scale |
|
x_tick_major |
number of major divisions for x scale |
|
x_scale_min |
minimum x scale value or starting point |
|
x_scale_max |
maximum x scale value or ending point |
void glg_line_graph_chart_set_y_ranges (GlgLineGraph *graph
,gint y_tick_minor
,gint y_tick_major
,gint y_scale_min
,gint y_scale_max
);
Sets the Y ticks and scales for the graph grid area.
graph |
pointer to a GlgLineGraph widget |
|
y_tick_minor |
number of minor divisions for y scale |
|
y_tick_major |
number of major divisions for y scale |
|
y_scale_min |
minimum y scale value or starting point |
|
y_scale_max |
maximum y scale value or ending point |
gint glg_line_graph_data_series_add (GlgLineGraph *graph
,const gchar *pch_legend_text
,const gchar *pch_color_text
);
Allocates space for another data series of y-values and returns the series number of this dataset added which you must keep track of to add values.
gboolean glg_line_graph_data_series_add_value (GlgLineGraph *graph
,gint i_series_number
,gdouble y_value
);
Add a single y value to the requested data series. auto indexes the value if x-scale max is reached (appends to the end) The X value is implied to be the current count of Y-values added.
graph |
pointer to a GlgLineGraph widget |
|
i_series_number |
The data series to add value to. |
|
y_value |
The value to add. Current range is 0.0 to y-max-scale |
Communication params for interface APIs
Enables display of the bottom chart title |
||
Disables display of the bottom chart title |
||
Enables display of the left/vertical chart title |
||
Disables display of the left/vertical chart title |
||
Enables display of the top chart title |
||
Disables display of the top chart title |
||
chart color key -- used to change chart scale/labels color |
||
chart color key -- used to change top title color |
||
chart color key -- used to change window color |
||
chart color key -- used to change chart color |
||
“chart-set-elements”
property “chart-set-elements” gint
Enable showing these elements of the chart body.
Flags: Write
Allowed values: [0,65536]
Default value: 128
“graph-chart-background”
property “graph-chart-background” gchar *
Chart inside fill color.
Flags: Write
Default value: "light blue"
“graph-scale-foreground”
property “graph-scale-foreground” gchar *
X and Y chart scale foreground font color.
Flags: Write
Default value: "black"
“graph-title-foreground”
property “graph-title-foreground” gchar *
Main title foreground color.
Flags: Write
Default value: "blue"
“graph-window-background”
property “graph-window-background” gchar *
Window background fill color.
Flags: Write
Default value: "white"
“range-scale-major-x”
property “range-scale-major-x” gint
x major scale range.
Flags: Write
Allowed values: [1,1000]
Default value: 100
“range-scale-major-y”
property “range-scale-major-y” gint
Y major scale range.
Flags: Write
Allowed values: [1,1000]
Default value: 100
“range-scale-minor-x”
property “range-scale-minor-x” gint
x minor scale range.
Flags: Write
Allowed values: [0,100]
Default value: 0
“range-scale-minor-y”
property “range-scale-minor-y” gint
Y minor scale range.
Flags: Write
Allowed values: [0,100]
Default value: 0
“range-tick-major-x”
property “range-tick-major-x” gint
x major ticks on scale.
Flags: Write
Allowed values: [1,1000]
Default value: 10
“range-tick-major-y”
property “range-tick-major-y” gint
Y major ticks on scale.
Flags: Write
Allowed values: [1,1000]
Default value: 10
“range-tick-minor-x”
property “range-tick-minor-x” gint
x minor ticks on scale.
Flags: Write
Allowed values: [1,100]
Default value: 5
“range-tick-minor-y”
property “range-tick-minor-y” gint
Y minor ticks on scale.
Flags: Write
Allowed values: [1,100]
Default value: 5
“series-line-width”
property “series-line-width” gint
Width of line drawn for data series.
Flags: Read / Write
Allowed values: [1,10]
Default value: 2
“text-title-main”
property “text-title-main” gchar *
Title at top of graph on the X axis.
Flags: Write
Default value: "<big><b>Top Title</b></big>"
“text-title-xaxis”
property “text-title-xaxis” gchar *
Title at bottom of graph on the X axis.
Flags: Write
Default value: "<i>X Axis Title</i>"
“point-selected”
signalvoid user_function (GlgLineGraph *widget, gdouble x_value, gdouble y_value, gdouble point_y_pos, gdouble mouse_y_pos, gpointer user_data)
The ::point-selected signal is emitted after the toggle-on mouse1 click, and sends values closest to the mouse pointer.
widget |
the line graph widget that received the signal |
|
x_value |
x value on the chart |
|
y_value |
y value on the chart |
|
point_y_pos |
pixel position of y value on chart |
|
mouse_y_pos |
pixel position of the mouse ptr on chart |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run First