Charts backend
Backendbauer is a backend server with REST API for generating json data for frontend js charts. It is written in Go and used by Mopinion.
Only two files are needed to get Backendbauer working:
For testing you can also use server/backendbauer.js
Server.go is the source code. In config.json you can set MySQL databases with custom tables and fields. All settings are based on the url from which the API call is made, the referer.
Go to server folder$ cd server
build server$ sudo go build -o server server.go
sudo chmod 755 server
make symbolic link$ sudo ln -s [backendbauer dir]/server/server /usr/sbin/backendbauer
copy service file to /etc/init.d$ sudo cp backendbauer /etc/init.d/
sudo chmod 755 /etc/init.d/backendbauer
To start and stopsudo service backendbauer start
sudo service backendbauer stop
ornohup [backendbauer dir]/server/server &
To test the example execute the sql/my_database.sql
file on your local MySQL server.
Set the proper username and password in config.json
sudo service backendbauer start
Go tohttp://localhost:8888/chart
Endpoint:https://[username]:[password]@[host name]:[port]/data
The API has a number of variables in order to get the right data in json format.
YYYY-MM-DD
formatYYYY-MM-DD
format0/1/2
|[field]:[value]
translates to AND [field] = "[value]"
|[field]![value]
translates to AND [field] <> "[value]"
AND
=> |
OR
=> /
=
=> :
>=
=> >:
<=
=> <:
<>
=> !
"
=> ^
LIKE
=> ~
%
=> *
NOT LIKE
=> !~
filter=|(field1:1/field2!^wrong^)/field3!~^*bad*^
AND (field1 = 1 OR field2 <> "wrong") OR field3 NOT LIKE "%bad%"
line
or pie
, etc. The response will send the type back. This can be used in some cases.0/1
sometimes the ajax js code differs when a request is a series or a chart. The response returns this value.true
and a callback function is specified, the response will add the callback function (needed for jsonp crossdomain/port calls)jsonp=true
the response will be included in a js callback (needed for jsonp crossdomain/port calls)asc
or desc
if given the query will be ordered ascending or descending respectively on the x variable[number]
for example 10
limits the result to 10 rowstrue
the response will include the categories in the data [['category1','data1']['category2']['data2']]
instead of ['data1','data2','data3']
. Easier to add series after a chart already existshttp://franz:jawohl@localhost:8888/data?x=1&y=1&from_date=2013-04-01&to_date=2013-04-30&avg=1&filter=my_table.rating!12|my_table.rating!11&chart_type=area&series=0&jsonp=false&order=&limit=0&role=0&callback=Backendbauer.place&combined=true
The server responds in json format, with the following fields:
name
variable from the request{
"categories": [
"2012-10-01"
"2012-10-02"
"2012-10-03"
"2012-10-04"
"2012-10-05"
],
"data": [
["2012-10-01",6]
["2012-10-02",5.3]
["2012-10-03",5.8]
["2012-10-04",5.6]
["2012-10-05",4.8]
],
"x_field_name":"Date",
"x_labels":true,
"y_field_name":"Rating over time average"
}
Apache 2.0 License (see LICENSE.txt). You can contact me by email floris (at) mopinionlabs.com