Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 982661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:44:00+00:00 2026-05-16T04:44:00+00:00

I am currently trying to implement a model to simplify graphical chart creation. However,

  • 0

I am currently trying to implement a model to simplify graphical chart creation. However, one of the attributes must be an array of attributes. For example:

“Chart_Series” has a “name” which would be a string and a data field which would be separated by dates which is an array of arrays [[Date1, Value1],[Date2,Value2],[Date3,Value3].

The purpose is to create an array of “Chart_Series” so as to call upon something like:

for series in @chart_series
  series.name 
     for data in series.data
      data.[Date, Value]
     end    
end

which would do something along the lines of:

  Name1
      Date1, Value1
      Date2, Value 2,
      Date3, Value 3,
      Date4, Value 4,
  Name2 
      Date1, Value 1,
      Date2, Value 2,
      Date3, Value 3,
      Date4, Value 4,

This is not exactly the code desired.. I am interested in simply generating the model which could do something like this. Any help is appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:44:00+00:00Added an answer on May 16, 2026 at 4:44 am

    I can see two initial approaches, namely define a class to represent your key,value pair or just use a hash to represent each data item. The advantage of a separate class is that you can extend it in the future, if for example you wanted to provide the exact value in a chart where you were rounding to the nearest 100k.

    The following code shows three classes which together will do what you want

    class Chart
    
      attr_accessor :title, :series
    
      def initialize(title = nil, series = [])
        @title, @series = title, series
      end
    
      def show
        puts title
        @series.each do |ser|
          puts "\t#{ser.legend} (#{ser.units})"
          ser.data.each do |item|
            puts "\t\t#{item}"
          end
        end
      end
    
    end
    
    class Series
    
      attr_accessor :legend, :units, :data
    
      def initialize(legend = nil, units = nil, data = [])
        @legend, @units, @data = legend, units, data
      end
    
    end
    
    class DataItem
      attr_accessor :key, :value
    
      def initialize(key, value)
        @key, @value = key, value
      end
    
      def to_s
        "#{key}, #{value}"
      end
    
    end
    

    Running this as follows :-

    c = Chart.new("Sweet sales by Quarter")
    c.series << Series.new("Bon-Bons", "£000", 
      [ DataItem.new("Q1", 220), 
        DataItem.new("Q2", 280), 
        DataItem.new("Q3", 123), 
        DataItem.new("Q4", 200)]
    )
    c.series << Series.new("Humbugs", "£000",  
      [ DataItem.new("Q1", 213), 
        DataItem.new("Q2", 254), 
        DataItem.new("Q3", 189), 
        DataItem.new("Q4", 221)]
    )
    
    c.show
    

    Produces the following output

    Sweet sales by Quarter
        Bon-Bons (£000)
            Q1, 220
            Q2, 280
            Q3, 123
            Q4, 200
        Humbugs (£000)
            Q1, 213
            Q2, 254
            Q3, 189
            Q4, 221
    

    If you wanted to take the Hash approach then you would no longer need the DataItem class and you could instantiate a new Series with code like this

    c = Chart.new("Sweet sales by Quarter")
    c.series << Series.new("Bon-Bons", "£000", 
       [ { "Q1" => 220}, {"Q2" => 280}, {"Q3" => 123}, {"Q4" => 200}]
    )
    

    The show method of Chart would then look like this

      def show
        puts title
        @series.each do |ser|
          puts "\t#{ser.legend} (#{ser.units})"
          ser.data.each do |item|
            item.each_pair {|key, value| puts "\t\t#{key}, #{value}" }
          end
        end
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to implement a simple Add-In for InfoPath 2010 Filler/Editor mode, which
I am currently trying to implement a graph on a website from a raw
I am currently trying to implement Conway's Game of Life in a Code, and
I'm currently trying to implement some kind of search system in a program of
I am currently trying to implement a PNG encoder in C++ based on libpng
I'm currently trying to implement a socket server that enables the clients to send
I'm currently trying to implement a Table View on my iPhone app that grabs
I am currently trying to implement a marker interface in c#. But I haven't
Just a little question for you... I'm currently trying to implement a role structure
Currently I'm trying to implement something in my app where I really don't know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.