Class: Pyk::Highcharts

Inherits:
Object
  • Object
show all
Defined in:
lib/pyk/highcharts.rb

Class Method Summary collapse

Class Method Details

.areaspline_by_date(data, render_to_name, background_color, start_date, end_date, show_in_legend = false, data_labels = false) ⇒ Object

Pyk::Highcharts.areaspline_by_date(data, render_to_name, background_color, start_date, end_date)



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pyk/highcharts.rb', line 54

def self.areaspline_by_date(data, render_to_name, background_color, start_date, end_date, show_in_legend=false, data_labels=false)
  categories = []
  (start_date..end_date).each do |d|
    categories << d
  end
  return LazyHighCharts::HighChart.new('graph') do |f|
    f.chart({ backgroundColor: background_color, renderTo: render_to_name, :defaultSeriesType=>"areaspline"} )
    data.each do |d2|
      f.series(:name=>d2[0],:data=> d2[1], borderWidth: 0)
    end      
    f.xAxis({categories: categories, gridLineWidth: 0, :labels=>{:rotation=>-45 , :align => 'right'}, type: :datetime})
    f.legend({layout: "horizontal", :borderWidth => 0})
    f.yAxis({gridLineWidth: 0, title: nil, :min => 0})
    f.title({ :text=> nil})
    f.plot_options({:area=>{pointInterval: 1.day, marker: {enabled: false, symbol: 'circle',radius: 2,states: {hover: {enabled: true}}}, dataLabels: {enabled: data_labels}, showInLegend: show_in_legend}})
  end
end

.bar(data, categories, render_to_name, background_color, show_in_legend = false, data_labels = false) ⇒ Object

Pyk::Highcharts.bar(data, categories, render_to_name, background_color)



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/pyk/highcharts.rb', line 15

def self.bar(data, categories, render_to_name, background_color, show_in_legend=false, data_labels=false)
  LazyHighCharts::HighChart.new('column') do |f|
    f.chart({ backgroundColor: background_color, renderTo: render_to_name, defaultSeriesType: "bar"} )
    data.each do |d|
      f.series(:name=>d[0],:data=> d[1], borderWidth: 0)
    end
    f.xAxis({categories: categories, gridLineWidth: 0, :labels=>{:align => 'right'}, type: :string})
    f.yAxis({gridLineWidth: 0, title: nil, :min => 0})
    f.title({ :text=> nil})
    f.plot_options({:bar=>{:stacking=>"normal", dataLabels: {enabled: data_labels}, showInLegend: show_in_legend}})
  end
end

.column(data, categories, render_to_name, background_color, show_in_legend = false, data_labels = false) ⇒ Object

Pyk::Highcharts.column(data, categories, render_to_name, background_color)



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pyk/highcharts.rb', line 29

def self.column(data, categories, render_to_name, background_color, show_in_legend=false, data_labels=false)
  LazyHighCharts::HighChart.new('column') do |f|
    f.chart({ backgroundColor: background_color, renderTo: render_to_name, :defaultSeriesType=>"column"} )
    data.each do |d|
      f.series(:name=>d[0],:data=> d[1], borderWidth: 0)
    end
    f.xAxis({categories: categories, gridLineWidth: 0, :labels=>{:align => 'center'}, type: :string})
    f.yAxis({gridLineWidth: 0, title: nil, :min => 0})
    f.title({ :text=> nil})
    f.plot_options({:column=>{:stacking=>"normal", dataLabels: {enabled: data_labels}, showInLegend: show_in_legend}})     
  end
end

.donut(data, series_name, render_to_name, background_color, chart_title, show_in_legend = false, data_labels = false) ⇒ Object

Pyk::Highcharts.donut(data, series_name, render_to_name, background_color)



43
44
45
46
47
48
49
50
51
# File 'lib/pyk/highcharts.rb', line 43

def self.donut(data, series_name, render_to_name, background_color, chart_title, show_in_legend=false, data_labels=false)
  LazyHighCharts::HighChart.new('pie') do |f|
    f.chart({:defaultSeriesType=>"pie" , :margin=> [0, 0, 0, 0], backgroundColor: background_color, renderTo: render_to_name})
    f.title({verticalAlign: 'middle',floating: true,text: chart_title})
    f.series({:type=> 'pie', :name=> series_name, :data=> data, borderWidth: 0, innerSize: '67%', size: '100%'})
    f.legend(:layout=> 'vertical',:style=> {:left=> '0', :bottom=> '0',:right=> '0',:top=> '0'}) 
    f.plot_options(series: {pointPadding: 0,groupPadding: 0}, :pie=>{:allowPointSelect=>true, :cursor=>"pointer" , showInLegend: show_in_legend, :dataLabels=>{:enabled=>data_labels}})
  end
end

.pie(data, series_name, render_to_name, background_color, show_in_legend = false, data_labels = false) ⇒ Object

Pyk::Highcharts.pie(data, series_name, render_to_name, background_color)



4
5
6
7
8
9
10
11
12
# File 'lib/pyk/highcharts.rb', line 4

def self.pie(data, series_name, render_to_name, background_color, show_in_legend=false, data_labels=false)
  LazyHighCharts::HighChart.new('pie') do |f|
    f.chart({:defaultSeriesType=>"pie" , :margin=> [0, 0, 0, 0], backgroundColor: background_color, renderTo: render_to_name})
    f.series({:type=> 'pie', :name=> series_name, :data=> data, borderWidth: 0})
    f.options[:title][:text] = nil
    f.legend(:layout=> 'vertical',:style=> {:left=> '0', :bottom=> '0',:right=> '0',:top=> '0'}) 
    f.plot_options(series: {pointPadding: 0,groupPadding: 0}, :pie=>{:allowPointSelect=>true, :cursor=>"pointer" , showInLegend: show_in_legend, :dataLabels=>{:enabled=>data_labels}})
  end
end

.stacked_bar_with_pie(data, categories, pie_data, render_to_name, background_color, show_in_legend = false, data_labels = false) ⇒ Object

Pyk::Highcharts.stacked_bar_with_pie(data, categories, pie_data, render_to_name, background_color)



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/pyk/highcharts.rb', line 73

def self.stacked_bar_with_pie(data, categories, pie_data, render_to_name, background_color, show_in_legend=false, data_labels=false)
  LazyHighCharts::HighChart.new('column') do |f|
    f.chart({ backgroundColor: background_color, renderTo: render_to_name, :defaultSeriesType=>"column"} )
    if pie_data.first.present?
      pie_data.each do |pie|
        f.series(:type=> 'pie',:name=> nil, :data=> [{:name=> pie[0], :y=> pie[1], :color=> pie[2]}], :center=> [pie[3], 5], :size=> 20, :showInLegend=> false, enableMouseTracking: false)
      end
    end
    data.each do |d|
      f.series(:type=> 'column',:name=> d[0],:data=> d[1], borderWidth: 0, stack: d[2], color: d[3])
    end
    f.xAxis({categories: categories, gridLineWidth: 0, :labels=>{:rotation=>0 , :align => 'right'}, type: :date})
    f.legend({layout: "horizontal", :borderWidth => 0, enabled: show_in_legend})
    f.yAxis({gridLineWidth: 0, title: nil, :min => 0})
    f.title({ :text=> nil})
    f.plot_options({:column=>{:stacking => "normal"}, dataLabels: {enabled: data_labels}, showInLegend: show_in_legend})
  end
end