Class: Apexcharts::CartesianChart
  
  
  
  
  
    - Inherits:
 
    - 
      Object
      
        
          - Object
 
          
            - Apexcharts::CartesianChart
 
          
        
        show all
      
     
  
  
  
  
  
  
  
      - Includes:
 
      - Annotations
 
  
  
  
  
  
  
    - Defined in:
 
    - lib/apexcharts/charts/cartesian.rb
 
  
  
 
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #annotation, #point_annotation, #x_annotation, #y_annotation
  
  
  
  
  
  
  
  
  
  camelize, camelize_keys, deep_merge
  Constructor Details
  
    
  
  
    #initialize(bindings, data, options = {}, &block)  ⇒ CartesianChart 
  
  
  
  
    
Returns a new instance of CartesianChart.
   
 
  
  
    
      
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 
     | 
    
      # File 'lib/apexcharts/charts/cartesian.rb', line 7
def initialize bindings, data, options={}, &block
  @bindings = bindings
  options = {**options, **more_options}
  build_instance_variables if @bindings
  instance_eval &block if block_given?
  options[:annotations] = @annotations if @annotations
  @series = sanitize_data(data)
  @options = Utils::Hash.camelize_keys(
               Utils::Hash.deep_merge(
                 build_options(@series[:series][0][:data][0][:x], options),
                 {**@series, chart: {type: chart_type}}.compact
               )
             )
  get_selection_range if brush?
end
     | 
  
 
  
 
  Dynamic Method Handling
  
    This class handles dynamic methods through the method_missing method
    
  
  
    
  
  
    #method_missing(method, *args, &block)  ⇒ Object 
  
  
  
  
    
      
54
55
56
57
58
59
60 
     | 
    
      # File 'lib/apexcharts/charts/cartesian.rb', line 54
def method_missing method, *args, &block
  if @bindings
    @bindings.send method, *args, &block
  else
    super
  end
end
     | 
  
 
  
 
  
    Instance Method Details
    
      
  
  
    #chart_type  ⇒ Object 
  
  
  
  
    
      
26
27 
     | 
    
      # File 'lib/apexcharts/charts/cartesian.rb', line 26
def chart_type
end 
     | 
  
 
    
      
  
  
    #mixed_series  ⇒ Object 
  
  
  
  
    
      
33
34
35
36 
     | 
    
      # File 'lib/apexcharts/charts/cartesian.rb', line 33
def mixed_series
  @series[:series].each{|d| d.merge!(type: chart_type) }
  @series[:series]
end
     | 
  
 
    
      
  
  
    #more_options  ⇒ Object 
  
  
  
  
    
      
29
30
31 
     | 
    
      # File 'lib/apexcharts/charts/cartesian.rb', line 29
def more_options
  {}
end
     | 
  
 
    
      
  
  
    #render  ⇒ Object 
  
  
  
  
    
      
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 
     | 
    
      # File 'lib/apexcharts/charts/cartesian.rb', line 38
def render
  attributes = @options.delete(:div) { {} }
  variable = attributes.delete(:var) { "chart#{attributes[:id]&.[](/\d+/)}" }
  element_id = attributes.delete(:id)
  css_class = attributes.delete(:class)
  height = "#{@options[:chart][:height].to_i}px"
  style = "height: #{height}; #{attributes.delete(:style)}"
  html =<<~HTML
    <div id="#{element_id}" class="#{css_class}" style="#{style}"></div>
    <script type="text/javascript">
      var #{variable} = new ApexCharts(document.querySelector("##{element_id}"), #{@options.to_json});
      #{variable}.render();
    </script>
  HTML
end
     |