lib/high_chart_series.rb
# accommodates multi-dimensional pivot tables
# based on Ruport pivot tables
# also generates your x-axis labels
accommodates multi-dimensional pivot tables
based on Ruport pivot tables
also generates your x-axis labels
accommodates multi - dimensional pivot tables based on Ruport pivot tables also generates your x - axis labels
def pivot_series(series_name_attribute, attribute_of_interest, chart_data, options={})
      series = []
      x_labels = []
      ignore = nil
      if options && options[:ignore]
        ignore = options[:ignore]
      end
      sample_data_hash = chart_data[0].send(attribute_of_interest.to_sym)
      series_builder = {}
      unless sample_data_hash.is_a?(Hash)
        raise HighChartError, "Please use the multi_series method.  This is not the appropriate chart type for you."
      end
      for datum in chart_data
        data_hash = datum.send(attribute_of_interest)
        data_hash.each do |k, v|
          unless k.to_s == ignore || (ignore && ignore.include?(k.to_s))
            series_builder[k] ||= []
            series_builder[k] << v
          end
          unless x_labels.include?(datum.send(series_name_attribute))
            x_labels << datum.send(series_name_attribute)
          end
        end
      end
      series_builder.each do |k, v|
        series << {:name => k, :data => v}
      end
      return x_labels, series
    end
def pivot_series ( series_name_attribute , attribute_of_interest , chart_data , options = { } ) series = [ ] x_labels = [ ] ignore = nil if options && options [ :ignore ] ignore = options [ :ignore ] end sample_data_hash = chart_data [ 0 ] . send ( attribute_of_interest . to_sym ) series_builder = { } unless sample_data_hash . is_a? ( Hash ) raise HighChartError , "Please use the multi_series method.  This is not the appropriate chart type for you." end for datum in chart_data data_hash = datum . send ( attribute_of_interest ) data_hash . each do | k , v | unless k . to_s == ignore || ( ignore && ignore . include? ( k . to_s ) ) series_builder [ k ] ||= [ ] series_builder [ k ] << v end unless x_labels . include? ( datum . send ( series_name_attribute ) ) x_labels << datum . send ( series_name_attribute ) end end end series_builder . each do | k , v | series << { :name => k , :data => v } end return x_labels , series end
accommodates multi-dimensional pivot tables
based on Ruport pivot tables
also generates your x-axis labels
accommodates multi - dimensional pivot tables based on Ruport pivot tables also generates your x - axis labels
series_name_attribute
attribute_of_interest
chart_data
options