Bar Graph Widget Documentation
Introduction
Bar Graph widgets are interactive elements within a Graphical User Interface (GUI) that enables users to display specific numerical data on a touchscreen display. When implemented, Bar Graph widgets will display inputted data categories such as quarterly numbers or varying masses of objects. They play a crucial role in providing an interactive user experience as they can be integrated with other widgets on the Microchip Graphics Suite (MGS) Harmony Composer to create a customizable and specialized user experience.
This Bar Graph widget page covers the following topics:
- Creating and customizing Bar Graph widgets using Microchip Graphics Suite (MGS) Harmony Composer
- Bar Graph widget properties
- Handling Bar Graph widget properties and events through application code
- Bar Graph widget example project
- Application Program Interfaces (APIs) specific to Bar Graph widgets
Designing Bar Graph Widget Using MGS Harmony Composer
Follow these steps to add a Bar Graph widget to your design:
Select and drag the BarGraphWidget from the Tool Box to your screen designer workspace as shown in Figure 1.
To customize the bar graph, select it on the screen designer and modify its properties using the Object Editor.
You can add data entries to your bar graph using the Configure Data property. Let us suppose you want to create a bar graph as shown in Figure 2:
The bar graph shown in Figure 2 has four data categories along the X -axis. For each category, there are three data series.
To configure bar graph data, click the Press button next to the Configure Data property as shown in Figure 3.
Then from the Configure Graph Data window as shown in Figure 4, follow these steps:
In the table highlighted in green in Figure 4, double-click on the required data and enter the desired data.
To set the stacked property on the bar graph, select the option from the Object Editor as shown in Figure 5:
Managing Bar Graph Widget Schemes
Schemes control the look and feel of a widget.
To learn how to set the scheme for a bar graph, click on the button next to the Scheme property editor from the Object Editor.
This launches the Bar Graph Scheme Helper window containing tips on how different sections of the scheme color table manipulate various elements of the widget.
The following is an example color scheme and the resulting bar graph appearance. Note that if your bar graph has more than one Data Series, it is helpful to assign each series with a unique color scheme to easily distinguish between them.
The information from the button scheme helper and the example color scheme used is summarized in the following table.
Bar Graph Widget Properties
You can set the following properties of the bar graph using the Object Editor:
Name | This will be used to reference the bar graph by the application (example- Screen0_Bar GraphWidget_0). | ||||||||||||||||||||
Numerical Graph |
| ||||||||||||||||||||
Value Axis
| This will be used to control the dimensions of the bar graph with the max, min, and tick values.
| ||||||||||||||||||||
Category Axis Show Category Ticks | If checked, the category labels will be displayed.
| ||||||||||||||||||||
Configure Date | Press button to launch the Graph Configuration Dialog. | ||||||||||||||||||||
Bar Graph - Stacked | When it is checked, the second data series will be stacked on top of the first. If unchecked, each data series will be displayed as a separate bar. Refer to Designing Bar Graph Widget Using MGS Harmony Composer Step 2. |
Figure 10,11,12 show the detailed information for the Bar Graph Value Axis.
Managing Bar Graph Widget Through Programming
Once the graphical design is completed using MGS Harmony Composer, MCC generates the required code for all the widgets based on the properties set in the Object Editor. To learn more about the process flow between designing a UI and developing application code, refer to the "Designing an Application with Microchip Graphics Suite (MGS)" page.
Let us suppose that a new Bar Graph widget is created with the following properties in MGS Harmony Composer:
For the Bar Graph widget with the properties shown in the figure above, MCC will automatically generate the following lines of code in src\config\default\gfx\legato\generated\screen\le_gen_screen_Screen0.c
- A new Bar Graph widget is created by the variable name Screen0_BarGraphWidget_0
Screen0_Bar GraphWidget_0 = leBar GraphWidget_New();
- Its position is set to pixel location 384x86
Screen0_Bar GraphWidget_0 ->fn->setPosition(Screen0_BarGraphWidget_0, 384, 86);
- The Bar Graph size is set to have a width of 350 pixels and a height of 327 pixels
Screen0_Bar GraphWidget_0 ->fn->setSize(Screen0_BarGraphWidget_0, 350, 327);
- If the scheme is altered, the following code is implemented:
Screen0_Bar GraphWidget_0 ->setScheme(Screen0_BarGraphWidget_0, &Scheme);
- Sets the minimum value on the Y-axis
Screen0_Bar GraphWidget_0 ->fn->setMinValue(Screen0_BarGraphWidget_0, 0);
- Sets the maximum value on the Y-axis
Screen0_Bar GraphWidget_0 ->fn->setMaxValue(Screen0_BarGraphWidget_0, 100);
- Sets the tick interval on the Y-axis
Screen0_Bar GraphWidget_0 ->fn->setValueAxisTickInterval(Screen0_BarGraphWidget, BAR_GRAPH_AXIS_0, 10);
- Its graph area value is set to none so that the background of the bar graph isn't filled with any color
Screen0_Bar GraphWidget_0 ->fn->setFillGraphArea(Screen0_BarGraphWidget_0, LE_FALSE);
- The Bar Graph is set to have a line border. However, you could have no border or a bevel border
Screen0_Bar GraphWidget_0 ->fn->setBorderType(Screen0_BarGraphWidget_0, LE_WIDGET_BORDER_LINE);
- Finally, the Bar Graph is added to the screen
root0 ->fn->addChild(root0, (leWidget*)Screen0_BarGraphWidget_0);
Application Code
The default code generated by MCC sets the initial state of the widget. The property or behavior of the widgets can be changed by using the APIs discussed above, in the application code. Additional application code discussion related to the Bar Graph widget is presented below.
Here is an example of how other MGS Widgets affect Bar Graph properties (in app.c):
/* When the checkbox widget is in a checked state, the Screen0_BarGraphWidget_0 bargraph
* widget changes its max value to 20, tick length to 5, sets the value axis ticks property
to visible, and changes the data in the Widget based off data obtained from an array */
void event_Screen0_CheckBoxWidget_0_OnChecked(leCheckBoxWidget* btn)
{
Screen0_BarGraphWidget_0->fn->setMaxValue(Screen0_BarGraphWidget_0, BAR_GRAPH_AXIS_0, 20);
Screen0_BarGraphWidget_0->fn->setTickLength(Screen0_BarGraphWidget_0, 5);
Screen0_BarGraphWidget_0->fn->setValueAxisTicksVisible(Screen0_BarGraphWidget_0, BAR_GRAPH_AXIS_0, true);
Screen0_BarGraphWidget_0->fn->setDataInSeries(Screen0_BarGraphWidget_0, 0, 0, averageWeightOz[0] / 16);
Screen0_BarGraphWidget_0->fn->setDataInSeries(Screen0_BarGraphWidget_0, 0, 1, averageWeightOz[1] / 16);
Screen0_BarGraphWidget_0->fn->setDataInSeries(Screen0_BarGraphWidget_0, 0, 2, averageWeightOz[2] / 16);
}
Bar Graph Widget Example Project
Refer to the Bar Graph widget example project in GitHub.
In this example, we show:
- How to create a Bar Graph Widget
- How to alter the data through other widget interactions
- How to alter the scaling of the Bar Graph Widget
MGS Simulator Output
The callback functions for handling the Checkbox events and Bar Graph updates are defined in the app.c file. In this example, dynamic strings were used for Bar Graph category labels.
As a best practice, changes to the widget are done in the main loop based on the variables that are changed in the timer callback, not in the callback directly.
The code that changes the Bar Graph widget can be found in the app.c file.
- Upon checking CheckBoxWidget_0 or CheckBoxWidget_1, the unit of the input data will be changed, and the bar graph will be updated accordingly.
const float averageWeightOz[] = {297.0, 142.8, 16.15};
bool convertionZero = false;
bool convertionOne = false;
void event_Screen0_CheckBoxWidget_0_OnChecked(leCheckBoxWidget* btn)
{
convertionZero = true;
if(convertionOne)
{
Screen0_CheckBoxWidget_1->fn->setChecked(Screen0_CheckBoxWidget_1, LE_FALSE);
}
Screen0_BarGraphWidget_0->fn->setMaxValue(Screen0_BarGraphWidget_0, BAR_GRAPH_AXIS_0, 20);
Screen0_BarGraphWidget_0->fn->setTickLength(Screen0_BarGraphWidget_0, 5);
Screen0_BarGraphWidget_0->fn->setValueAxisTicksVisible(Screen0_BarGraphWidget_0, BAR_GRAPH_AXIS_0, true);
Screen0_BarGraphWidget_0->fn->setDataInSeries(Screen0_BarGraphWidget_0, 0, 0, averageWeightOz[0] / 16);
Screen0_BarGraphWidget_0->fn->setDataInSeries(Screen0_BarGraphWidget_0, 0, 1, averageWeightOz[1] / 16);
Screen0_BarGraphWidget_0->fn->setDataInSeries(Screen0_BarGraphWidget_0, 0, 2, averageWeightOz[2] / 16);
}
- If both the checkboxes are unchecked, the bar graph reverts to default data.
{
convertionZero = false;
if( !(convertionZero) && !(convertionOne))
{
Screen0_BarGraphWidget_0->fn->setMaxValue(Screen0_BarGraphWidget_0, BAR_GRAPH_AXIS_0, 100);
Screen0_BarGraphWidget_0->fn->setValueAxisTicksVisible(Screen0_BarGraphWidget_0, BAR_GRAPH_AXIS_0, true);
Screen0_BarGraphWidget_0->fn->setValueAxisTicksInterval(Screen0_BarGraphWidget_0, BAR_GRAPH_AXIS_0, 10);
Screen0_BarGraphWidget_0->fn->setDataInSeries(Screen0_BarGraphWidget_0, 0, 0, initialFruit[0]);
Screen0_BarGraphWidget_0->fn->setDataInSeries(Screen0_BarGraphWidget_0, 0, 1, initialFruit[1]);
Screen0_BarGraphWidget_0->fn->setDataInSeries(Screen0_BarGraphWidget_0, 0, 2, initialFruit[2]);
}
}
Bar Graph Widget APIs Description
This section describes the APIs specific to the Bar Graph widget. For a description of APIs common to all widgets, refer to the "Widget APIs Description" section.
getTickLength()
- Gets the tick length
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
- Returns the tick length value
setTickLength()
- Sets the tick length
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
uint32_t | len | Tick length value |
- Returns LE_SUCCESS or LE_FAILURE
getMinValue()
- Gets the minimum value from the Value Axis
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
- Returns the minimum value
setMinValue()
- Sets the minimum value
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
int32_t | min | The new value set as minimum |
- Returns LE_SUCCESS or LE_FAILURE
getMaxValue()
- Gets the maximum value from the Value Axis
Parameters
leBarhWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
- Returns the maximum value
setMaxValue()
- Sets the maximum value
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
int32_t | max | The new maximum value |
- Returns LE_SUCCESS or LE_FAILURE
getValueAxisLabelsVisible()
- Gets the visible Value Axis label setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked Returns the setting value |
- Returns LE_TRUE if set, otherwise LE_FALSE
setValueAxisLabelsVisible()
- Sets the visibility of the Value Axis labels
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
leBool | vis | The new label visibility |
- Returns LE_SUCCESS or LE_FAILURE
getValueAxisTicksVisible()
- Gets the visible value ticks setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
- Returns the setting value
setValueAxisTicksVisible()
- Sets the visibility of the value axis ticks
Parameters
leBarGraphWidget* | _this | BarGraph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
leBool | vis | The new visibility status |
- Returns LE_SUCCESS or LE_FAILURE
getValueAxisTickInterval()
- Gets the value axis tick interval setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
- Returns the tick interval value
setValueAxisTickInterval()
- Sets the interval of the value axis ticks
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
uint32_t | itv | The new interval value |
- Returns LE_SUCCESS or LE_FAILURE
getValueAxisTicksPosition()
- Gets the value axis ticks position
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value Axis to be checked |
- Returns the value axis ticks position
setValueAxisTicksPosition()
- Sets the value axis ticks position
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
leBarGraphTickPosition | position | Sets the position to BAR_GRAPH_TICK_IN, BAR_GRAPH_TICK_OUT or BAR_GRAPH_TICK_CENTER |
- Returns LE_SUCCESS or LE_FAILURE
getValueAxisSubticksVisible()
- Gets the visible value subtick setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
- Returns the setting value
setValueAxisSubticksVisible()
- Sets the visibility of the value axis subticks
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
leBool | vis | The new visibility setting |
- Returns LE_SUCCESS or LE_FAILURE
getValueAxisSubtickInterval()
- Gets the value axis subtick interval setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
- Returns the subticks interval value
setValueAxisSubtickInterval()
- Sets the inverval of the value axis subticks
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
uint32_t | itv | The new interval value |
- Returns LE_SUCCESS or LE_FAILURE
getCategoryAxisTicksVisible()
- Gets the category axis ticks visible setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
- Returns the setting value
setCategoryAxisTicksVisible()
- Sets the category axis ticks visible setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBool | vis | The new visibility setting |
- Returns LE_SUCCESS or LE_FAILURE
getCategoryAxisTicksPosition()
- Gets the category axis ticks position
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
- Returns the category axis ticks position
setCategoryAxisTicksPosition()
- Sets the category axis ticks position
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphTickPosition | position | Sets the position to BAR_GRAPH_TICK_IN, BAR_GRAPH_TICK_OUT or BAR_GRAPH_TICK_CENTER |
- Returns LE_SUCCESS or LE_FAILURE
getCategoryAxisLabelsVisible()
- Gets the category axis labels visible setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
- Returns the setting
setCategoryAxisLabelsVisible()
- Sets the category axis labels visible setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBool | visible | Sets the labels visibility setting |
- Returns LE_SUCCESS or LE_FAILURE
addSeries()
- Adds a data series to the graph
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
- Returns the series ID
getSeriesScheme()
- Gets the scheme for a data series
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
int32_t | seriesID | ID of the series that should be checked |
- Returns scheme pointer
setSeriesScheme()
- Sets the data series scheme
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
int32_t | seriesID | ID of the series that should be modified |
const leScheme* | schm | Pointer to the scheme that should be used |
- Returns LE_SUCCESS or LE_FAILURE
addDataToSeries()
- Adds data to an existing series
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
int32_t | seriesID | ID of the series that should be used |
int32_t | value | Value that will be added in the series |
- Returns the ID of the new value
setDataInSeries()
- Sets a new value to an already existing data series
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
int32_t | seriesID | ID of the series that should be used |
int32_t | index | Index of the value that should be modified |
int32_t | value | New value that will be used |
- Returns LE_SUCCESS or LE_FAILURE
clearData()
Clears all graph data.
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
- Returns LE_SUCCESS or LE_FAILURE
getTicksLabelFont()
- Gets the Ticks font property
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
- Returns the property
setTicksLabelFont()
- Sets the series point type setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
const leFont* | font | The font that should be used |
- Returns LE_SUCCESS or LE_FAILURE
getGridLinesVisible()
- Gets the visible grid lines setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked. |
- Returns the setting value
setGridLinesVisible()
- Sets the visibility of the grid lines
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBarGraphValueAxis | axis | Value axis to be checked |
leBool | vis | The new visibility setting |
- Returns LE_SUCCESS or LE_FAILURE
addCategory()
- Adds a data category
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
- Returns the category ID
getCategoryString()
- Gets the string currently assigned to a category
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
int32_t | id | ID of the category that should be checked |
- Returns string pointer
setCategoryString()
- Sets the category axis ticks visible setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
int32_t | id | ID of the category that should be modified |
const leString* | str | Pointer to the string that should be shown on the category label |
- Returns LE_SUCCESS or LE_FAILURE
getStacked()
- Gets the stacked setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
- Returns the setting value
setStacked()
- Sets the stacked status
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBool | stk | The stacked status |
- Returns LE_SUCCESS or LE_FAILURE
getFillGraphArea()
- Gets the graph fill setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
Returns the setting value.
setFillGraphArea()
- Sets the graph fill setting
Parameters
leBarGraphWidget* | _this | Bar Graph widget pointer to operate on |
leBool | fill | The new fill setting |
- Returns LE_SUCCESS or LE_FAILURE