A Dashing widget to show a Google Visualizations Column Chart on a dashboard.
Copy the google_column.coffee
, google_column.html
and google_column.scss
file to into /widgets/google_column
directory.
Add the following to the dashboard layout file:
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
</script>
Then to include the widget on the dashboard, add the following item to your dashboard file:
<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
<div data-id="mychart" data-view="GoogleColumn" data-title="My Chart"></div>
</li>
The following options can be added to the <div>
of the chart object (defaults in parenthesis):
data-title
- (no title) Title of the chartdata-is_stacked
- (false) Set totrue
to enable stacking of the y axis values.data-colors
- (Googles default colors) A comma separated list of colors to use for the chart barsdata-legend_position
- (right) Position of the legend. One of 'bottom', 'left', 'in', 'none', 'right' or 'top'
The following would stack the y axis values, remove the legend and plot a two-valued chart using purple and black bars:
<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
<div data-id="mychart" data-view="GoogleColumn" data-is_stacked="true" data-legend_position="none" data-colors="purple, black" data-title="My Chart"></div>
</li>
To send data to the chart, use send_event to send an item called points
with a two dimensional array.
Make sure the first "row" in the array is an array of headers for the data.
For example:
send_event('mychart', points: [
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
])
Hi Everyone,
i've been strugling with this for almost 2weeks now and i'd hope someone might help me out on how to convert my sql query from mysql db into 2D array for sending into the google charts widgets please?
My actual script is >
SCHEDULER.every '1m', :first_in => 0 do |job|
points = []
Myql connection
db = Mysql2::Client.new(:host => "192.168.46.2", :username => "AT-DBA", :password => "P0werLin", :port => 3306, :database => "lbn_kpi" )
Mysql query
sql = "SELECT <Field 1>, <Field 2> FROM Table"
Field 1 is Integer
Field 2 is Decimal(65,30)
rs = db.query(sql, :as => :array)
subpoints = []
subpoints.push('Week')
subpoints.push('MTV')
points.push(subpoints)
rs.each do |row|
subpoints = []
subpoints.push(row['Field 1'])
subpoints.push(row['Field 2'])
points.push(subpoints)
end
Update the List widget
send_event('mychart01', points: points)
Mysql2.close
I get the error:
'./mysql_chart_01.rb:23:in
[]': no implicit conversion of String into Integer (TypeError) from ./mysql_chart_01.rb:23:in
block infrom ./mysql_chart_01.rb:21:in
each' from ./mysql_chart_01.rb:21:in
'actually i'm not even sure to be able to make it work this way.
If anyone has better suggestion or ruby script for google charts ?
Best regards,