I'm using this very straightforward code (practically the same as the bar chart examples here, however I am noticing that the Axes are inverted. The data that should be on the Val axis is shown on the Cat axis.
This is also true for the example linked above, and I can't seem to find a way to put them in the correct order.
Below is an image of the problem. The code used to generate it is:
sheet.add_chart(Axlsx::Bar3DChart,:title => "Chart", :show_legend => false, :start_at => "A1", :end_at => "P30", :bar_dir => :col) do |chart|
chart.add_series :data => sheet["B1:B25"], :labels => sheet["A1:A25"]
chart.valAxis.gridlines = false
chart.catAxis.gridlines = false
end
I fixed it. You can find my fork of axlsx here: https://github.com/HansCz/axlsx.
A pull request will be sent to https://github.com/randym/axlsx
Related
How do pass color parameter to google maps api using google-maps-for-rails? I would like to set color of each marker inside controller based on a value, so some would be red, some yellow and some green. I believe it is the icon property, in Symbol, looking at:
https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions
Also, I would like to have a number from 1-99 inside the marker, is it possible? So far I have this.
#json = Device.all.to_gmaps4rails do |device, marker|
end
I have been struggling with this for days, any help would be appreciated.
You should simply leverage the google's chart api.
Example, the following is a marker with:
letter A
red color: FF0000
black text: 000000
http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|FF0000|000000
So you should customize your needs:
#json = Device.all.to_gmaps4rails do |device, marker|
marker.picture({
:picture => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|FF0000|000000", # up to you to pass the proper parameters in the url, I guess with a method from device
:width => 32,
:height => 32
})
end
I implemented the above solution to no avail, but now figured out why this wasn't working. Perhaps this was an update to the gem, but "url" is the right key for the URL of the picture, not "picture". Here was my code in my controller:
#devices_hash= Gmaps4rails.build_markers(#devices) do |device, marker|
...
marker.picture({
:url => "http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=A|007FFF|000000",
:width => 32,
:height => 32
})
end
Hope this helps some people struggling with the same thing.
Since Gmaps4rails updated to 1.5 the clustering option has been set to false by default.
The documentation says that :do_clustering its the way to show clusters on flooding markers.
In code i´ve got:
<%= gmaps(:markers => {:data => #json}, :map_options => {:do_clustering => true}) %>
Edit: And of course it is supported
But clusters still not showing. Any thoughts?
Just realized:
You're passing do_clustering as a map option whereas it's a marker option.
I need to create an excel sheet with a field status. It is a drop down with values 'High', 'Medium', and 'Low'. I need to show different colors when they select different values. I have implemented the drop down using writeexcel gem. Here is my code:
worksheet.data_validation(count, 5,
{
:validate => 'list',
:source => ['High', 'Medium', 'Low'],
})
The drop down is working fine. But I want to specify a color for each selection. I can color the cell based on the selection of the dropdown, but what I need is different colors for different selections of the drop down. Any other gem having this implementation is also fine.
The write_xlsx gem is an updated version of writeexcel that supports the newer Excel 2007+ XLSX format. It is by the same author and has the same interface but has additional features.
One of these new features is Conditional Formating.
You can use it to apply conditional formats to the same cell as the drop-down validation like this:
worksheet.conditional_formatting(count, 5,
{
:type => 'cell',
:format => format1,
:criteria => '=',
:value => '"High"'
}
)
worksheet.conditional_formatting(count, 5,
{
:type => 'cell',
:format => format2,
:criteria => '=',
:value => '"Medium"'
}
)
...
You will need to define the formats using the standard interface.
Note, write_xlsx is a port of the Perl module Excel::Writer::XLSX. That module contains additional documentation on the use of conditional formats. You should be able to convert the examples to Ruby easily enough.
See also my answer to your previous question.
Needing some guidance about how to properly graph data that is very small and stored as BigDecimal.
If anyone has had experience using BigDecimals in any graphing scenario I believe your input on how you placed these into a usable sequence would be invaluable.
Presently I'm using lazy_high_charts and it really seems that this is going to work out exceptionally well, however I've run into a hitch where I've not dealt with data on the minute BigDecimal scale hitherto.
Given my queries, I'll be pulling out about a 1,000 data points for a few different series of data ranging in accuracy from about 0.100E-9 to about 0.100E-1.
What would be the best way to prep these data series for presentation in such a graph that has a scientific application and therefore precision is important? I'm not sure if I could or should continue in BigDecimal or something else?
I'm presently querying the database with a line similar to:
series_a = dataset.order("date").select('data_set.data1').limit(1000).all.zip
I'd appreciate some guidance of going from this result (again, the output is an array of BigDecimals) to the appropriate format for what will go into the chart series.
An contextual example of the code I'm using to build the chart in my controller is:
#h = LazyHighCharts::HighChart.new('graph') do |f|
series_a = dataset.order("date").select('data_set.data1').limit(1000).all.zip
series_b = dataset.order("date").select('data_set.data3').limit(1000).all.zip
f.series(:name => 'Data 1', :data => series_a)
f.series(:name => 'Data 2', :data => series_b)
f.chart({:defaultSeriesType => "line" })
f.yAxis [
{:title => { :text => "Left Y Label", :margin => 10} },
{:title => { :text => "Right Y Label"}, :opposite => true }
]
f.xAxis(:title => { :text => "X Label"} )
f.title(:text => "Graph Title")
f.legend(:align => 'right', :verticalAlign => 'top', :y => 75, :x => -50, :layout => 'vertical')
end
I think I'm a bit further along in my understanding of this having decided to convert the BigDecimals to strings as per "How to access fields by attribute name from ActiveRecord row results?" However it appears ultimately this fails and gives erratic results as the series functions :data field expects, I think, numeric input. I am thinking that this ultimately emits json to highcharts, however I'm still stuck for the moment in my attempt to pass these values on in correctly.
When you do this:
series_a = dataset.order("date").select('data_set.data1').limit(1000).all.zip
you'll end up with an array of arrays as we already discussed elsewhere. If you get rid of the zip, you should end up with an array of objects in series_a. I'd guess that chart would be happier with an array of numbers so:
series_a = dataset.order("date").
select('data_set.data1').
limit(1000).
all.
map(&:data1)
or, if data1 is a BigDecimal (due to using a fixed precision type in the database) then maybe you'd want this:
series_a = dataset.order("date").
select('data_set.data1').
limit(1000).
all.
map { |o| o.data1.to_f }
to get an array of floating point values that the chart should know what to do with.
I'm not familiar with Highcharts so there is some guesswork here.
This gem is awesome for displaying a dynamic map. I am a beginner programmer, and I cannot seem to get a custom marker to display on the map.
I have the following in my model:
def gmaps4rails_marker_picture
{
"picture" => 'images/logo_avatar.png',
"width" => '16',
"height" => '16'
}
end
I have tried many combinations of the info provided in the github README, but to no avail. My map works perfectly until the above code gets plugged into the model....then all the markers go away. Is the sidebar code required in order to display a custom marker?
Here is one version of what I have in the controller:
#markers = Property.where(:id => propertyids).to_gmaps4rails
and the view:
<%= gmaps4rails(#markers) %>
I have tried passing in the image as an option, but could not get it to work.
Any help would be much appreciated!
At the controller level, do:
#json = Property.where(:id => propertyids).to_gmaps4rails do |property, marker|
marker.picture({
"picture" => path_to_image('/images/logo_avatar.png'),
"width" => '16',
"height" => '16'
})
end
It lets you use the assets tag helper.
Hey tbone I think I was having a similar issue and found the solution,
all I did was change it to this
marker.picture({
'picture' => view_context.image_path("green-dot.png"),
'width' => 32,
'height' => 32
})
the following code works for me, try it..
#json = Property.where(:id => propertyids).to_gmaps4rails do |property, marker|
marker.picture({
"picture" => 'assets/logo_avatar.png',
"width" => '16',
"height" => '16'
})
end