score:2
Accepted answer
In ruby you can save different type of the element in the single array like following
arr = [1, 1.0, "This is a String", {abc: pqr}, [6]]
#arr[0].class = Fixnum
#arr[1].class = Float
#arr[2].class = String
#arr[3].class = Hash
#arr[4].class = Array
So if you want to save array of array like following
[["value1", 1.0], ["value2", 2.0]]
Use following
array = []
@products.each do |p|
array << [p.title, p.price]
end
OR just
array = @products.collect{|p| [p.title, p.price]}
Edited to show the access the 2D Array
arr = [["value1", 1.0], ["value2", 2.0]]
#arr[0] = ["value1", 1.0]
#arr[0][0] = "value1"
#arr[0][1] = 1.0
#arr[1] = ["value2", 2.0]
#arr[1][0] = "value2"
#arr[1][1] = 2.0
Source: stackoverflow.com
Related Query
- Ruby 2D array of different types
- Ruby on Rails: Passing string array to highchart function
- Multiple different chart types stacked, column type with y value as color
- Highchart Drill Down do not work for different chart types on same page
- Drilldown different chart types leave artifacts when drilling up?
- Ruby on Rails: How to generate an array from records to display in Highcharts?
- Highcharts same types of data with different series
- Strange character in the Highstock source code
- Why does my Highchart look different when I transfer my code from Jsfiddle to my server?
- How can I prepare a Group Stacked Bar Chart in Highcharts using multiple and different types of data?
- How to format Ruby array to be used as data in Highcharts
- How to have multiple highcharts with different series data in vuejs without repeating code
- How to get different chart types in same plot
- FusionCharts Failed to draw different chart on same data source
- Converted PHP code that built an array to JS and now highcharts doesn't work - what did I do wrong?
- link 2 different types of highcharts data
- A different suffix from an array for each line on Highcharts
- Building different types of Highcharts Programmatically.
- Selecting different types of charts
- Create array from string - with complex types for highchart
- On common x-axis how to draw a chart with different unit of dataset array (multi line chart)
- Why am I seeing two different point types in Highcharts?
- How to relate the y-axis of different types of graphs?
- set different colors for each column in highcharts
- Can I use two different formatters for highchart tooltips?
- Highcharts graph X-axis label for different date ranges
- A different suffix for each line on Highstock/Highcharts
- Optimize JavaScript DrillDown code
- Highcharts series data array
- Highcharts shared tooltip requires different valueSuffix and varying decimals
More Query from same tag
- Line chart, show data label inside chart when data is less than min
- Highchart xAxis "6 Hours Ago" ,"5 Hours ago" and so on. while my chart is updating
- highchart stacked bar plotting data doesn't work by javascript
- JavaFX StackedBarChart automatically reuse the same color on different series: how to avoid it?
- How do I display category names instead of point.y in Highcharts scatterplot?
- Can I use Iron-ajax to load data to polymer/highcharts element
- How to have data labels on top of the graph?
- "Uncaught SyntaxError: Unexpected token = " ... JavaScript/HighCharts?
- Backgroud Bell Curve and show tooltips in Highchart charts
- Highcharts - Column chart with empty columns for date in x-axis
- Pie chart options in ZingChart
- Make Highcharts column chart bars as wide as mandated by a linear xaxis
- highcharter both nominal and percentage values
- Set Duration for tooltip in highchart
- Highstock v3.0 how to disable tooltip timeout/delay
- Change the text of the back button on Highcharts Treemap?
- Set the with of xAxis label to 50% on a Highcharts BarChart
- Highcharts not showing all labels for rows
- how can I make highstock flags stay put
- Set tickInterval in format HH:mm am/pm of a HIChart's Line chart using Swift 5.0
- Making Highcharts scatter circle shadow
- Highcharts - Large Tree Map: Show values below points name
- How to convert Number 23.0 to Number 23.00?
- Highcharts error bars not linking with the datapoints.
- Unable to change row height in Bootstrap 4
- Highcharts markers to appear only on x axis ticks
- Plotbands to highcharts based on category
- Integrate social media network sharing buttons to Highcharts.
- Draw multiple series upon mouse hover in Highstock
- Wicked-Charts: This website contains interactive content