ruby调用echart的柱状饼状图

阅读更多
 sql = "select GROUP_CONCAT( DATE_FORMAT(format_date,'%d')  ,'@', chemical_count ) as group_chemical_count, 
 GROUP_CONCAT( DATE_FORMAT(format_date,'%d')  ,'@', vendor_num ) as group_vendor_num, 
 a.format_date_month
from
(select 
chemical_num as chemical_count , 
vendor_num as vendor_num,
DATE_FORMAT(data_statistics.created_at,'%Y-%m-%d') as format_date , 
DATE_FORMAT(data_statistics.created_at,'%Y-%m') as format_date_month
from data_statistics
where created_at >= '#{@start_time}' and created_at < '#{@end_time}'
group by format_date) as a
group by a.format_date_month"

@reports = Inquiry.find_by_sql(sql) 
@product_charts = {} 
@company_charts = {} 
@report_month = []
@reports.each do |report|
month = report["format_date_month"] + "-01"
    search_day = DateTime.parse(month).to_date
    end_date = search_day.at_end_of_month.strftime("%d").to_i
         _product_charts_data = []
         _company_charts_data = []
    (1..end_date).each do |_|
      _product_charts_data << (report["group_chemical_count"].match(/#{_.to_s.rjust(2,"0") }@\d+/) ? report["group_chemical_count"].match(/#{_.to_s.rjust(2,"0")}@\d+/)[0].split("@")[1].to_i : 0 )
      _company_charts_data << (report["group_vendor_num"].match(/#{_.to_s.rjust(2,"0") }@\d+/) ? report["group_vendor_num"].match(/#{_.to_s.rjust(2,"0")}@\d+/)[0].split("@")[1].to_i : 0 )
    end
    @report_month << report['format_date_month'].delete('-')
    @product_charts[(report['format_date_month'].delete('-'))] = _product_charts_data
    @company_charts[(report['format_date_month'].delete('-'))] = _company_charts_data
end
@chart_data_x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]
@chart_data_tab = @report_month
@chart_list = ['new vendor','new product']
@charts1 = @company_charts.to_json
@charts2 = @product_charts.to_json


<%= javascript_include_tag 'echarts.min' %>

  • ruby调用echart的柱状饼状图_第1张图片
  • 大小: 61.1 KB
  • 查看图片附件

你可能感兴趣的:(echart)