Developed by: CZ.NIC
Latest version: OGRA Git repository
First step in using OGRA is to include it into your page by inserting the following code to the head of your HTML:
<script type="text/javascript" src="https://gitlab.labs.nic.cz/labs/ogra/raw/master/ogra.js"></script>
OGRA will automatically import all required third party javascript libraries (e.g.: Google Charts, High Charts, jQuery...) in case it is required for your chart.
For drawing charts you need to have data in format compatible with OGRA. OGRA uses the Google Charts DataTable format, so if you already have data in this format, you do not need to change anything. Even when you use a graphic library not compatible with DataTable format, you do not have to convert your data - OGRA will do it for you automatically.
For easy generation of data in DataTable format on the server side, we would recommend to use gviz_api.py
Example of data in DataTable format:
<script type="text/javascript"> var data = {"cols":[{"label":"Year", "type":"string"},{"label":"Sales", "type":"number"}, {"label":"Expenses", "type":"number"}], "rows":[{"c":[{"v":"2004"},{"v":1000},{"v":400}]}, {"c":[{"v":"2005"},{"v":1170},{"v":460}]}, {"c":[{"v":"2006"},{"v":660},{"v":1120}]}, {"c":[{"v":"2007"},{"v":1030},{"v":540}]}]}; </script>
This data will be used in the example below…
For drawing a chart you need to call the Ogra.graph method.
1. Initialization of OGRA:<script type="text/javascript" src="https://gitlab.labs.nic.cz/labs/ogra/raw/master/ogra.js"></script>2. Create element for future chart:
<div id="elem_id" style="width: 500px; height: 300px;"></div>3. Create chart:
<script type="text/javascript"> Ogra.graph("elem_id", data, "column", "google", {title: "My chart"}); </script>
Ogra.graph(element_id, data, chart_type, used_library, options);
List of supported additional parameters.
Take a look at an example of a chart with various options.
For the full list of possible options please visit Google Chart API reference.
Type of chart: | Google Chart "google" | Highcharts JS "high" | DyGraphs "dygraphs" | Flot "flot" |
Line | YES | YES | YES | YES |
Column | YES | YES | NO | YES |
Bar | YES | YES | NO | NO |
Pie | YES | YES | NO | YES |
Table | YES | NO | NO | NO |
Area | NO | YES | NO | NO |
To use OGRA in offline mode, you have to download all required third party libraries import them before initializing OGRA. OGRA is checking the namespaces of required libraries during its initialization. If required names are not defined, OGRA will try to download all required libraries from preset URLs.
You can also overrite these preset URLs. Take a look at an example.
In case of failure during creation of chart, the error message will be displayed on the position of planned chart. Error message contains short problem description.
Take a look at an example with error message.