i'm using the MORRIS JS to plot a chart line in my Ruby On Rails Project
I retreive Data from my Database : MYSQL and want to plot it in Morris JS CHART
I return an Array of data from Database. My Problem: is that the MORRIS JS , just plot the first row of my array , i don't know dose not plot all the data retreived from MYSQL DATABASE.
Please, i need help
So this my Code
My controller
require 'json'
@get_data = CttGueHydro2Aae.where("Date_YMDHMS >= '2017-05-10 16:10:12'")
#@get_data = CttGueHydro2Aae.all
@chart_data = Array.new
obj = {}
obj["time"] = " "
obj["value"] = " "
@get_data.each do |data|
obj["time"] = data.Date_YMDHMS
obj["value"] = data.AAE_8062
@chart_data.push(obj)
end
#Json Conversion
@chart_data = @chart_data.to_json
end
View>Index.html.erb
<div id="myfirstchart" style="height: 250px;"></div>
<script type="text/javascript">
new Morris.Line({
// ID of the element in which to draw the chart.
element: 'myfirstchart',
// Chart data records -- each entry in this array corresponds to a point on
// the chart.
data: <%= @chart_data.html_safe %>,
// The name of the data record attribute that contains x-values.
xkey: 'time',
// A list of names of data record attributes that contain y-values.
ykeys: ['value'],
// Labels for the ykeys -- will be displayed when you hover over the
// chart.
labels: ['Value']
});
</script>
So, when i run the Server from command line : rails s Just the Morris plot the first value of my array
PLOT IN MY BROWSER from the DEBEGUER of MY BROWSER i get this :
Inspector of my code in the browser
All
Aucun commentaire:
Enregistrer un commentaire