I'm using the Lazy HighCharts gem in my rails application and I have an array set up for my categories on my xAxis. I want to show just the first and last array, having the first appear on the left hand side and the last appear on the far right. Is this possible?
dates = [10,11,12,13,14,15,16]
#graph = LazyHighCharts::HighChart.new('graph') do |f|
f.xAxis(:categories => dates)
f.series(:type => 'spline', :name => 'Average', :data => [1,2,3,4,5,6,7], :color => '#b20838', marker: {enabled: false})
f.legend({:align => 'right', :y => 10, :verticalAlign => 'top', :floating => "true", :borderWidth => 0})
end
So instead of showing all dates on x-axis :
I would like the first and last array to show.
Try to use :tickPositions => [0, lengthOfCategories-1] for xAxis.
If you can find out the first and last values of the labels and store them in variables before itself, then you can do some thing like this http://jsfiddle.net/E7GBd/ using
formatter: function(){}
Hope this will help you.
Related
I am using Fusionchart Multi-series column 3d + line with dual y axis,
I put my data in an array like this
mttr.push({
:label => Date::MONTHNAMES[month],
:value => (monthly_failure[month] / total_circuit)
})
and the dataset field like this
:dataset => [
{
:seriesname => 'Downtime',
:color => 'AFD8F8',
:showvalues => '0',
:data => downtime
},
{
:seriesname => 'MTTR',
:color => 'F6BD0F',
:showvalues => '0',
:data => mttr
},
{
:seriesname => 'SLA',
:color => '8BBA00',
:showvalues => '0',
:parentyaxis => 'S',
:renderas => 'Line',
:data => sla
}
]
I have tried my code and there is no problem with the data, but the graph still blank. is it becacuse i am not using the "categories" field ?
For implementing multi series charts you need to have categories objects as they are used to specify x axis labels for multi series charts.
Also note that FusionCharts have dedicated Ruby on Rails wrapper.
You can check the documentation from here http://www.fusioncharts.com/dev/using-with-server-side-languages/ruby-on-rails/introduction.html
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
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
I'm using the Gmaps4Rails gem and cannot figure out how to adjust the default zoom settings. In my view I have the following code:
<%= gmaps({
"map_options" => {"auto_adjust" => false, "auto_zoom" => false, "zoom" => 15 },
"markers" => {"data" => #json }
})
%>
I know this has been asked and answered many times, but maybe I'm just not seeing something...any advice? Am i missing something completely obvious? I apologize for reposting this question.
Thanks, Kevin
EDIT
I failed to properly comment out the default instance of gmaps and it overrode my customized settings. Thanks for all the help #apneadiving!
You're simply missing that seeing the whole map means providing a very small number, not a big one!
<%= gmaps({
"map_options" => {"auto_adjust" => false, "zoom" => 0 },
"markers" => {"data" => #json }
})
%>
I'm on gmaps4rails 1.3.2 and these are the best settings I could find:
<%= gmaps({
"map_options" => {"auto_zoom" => false, "zoom" => 10 },
"markers" => {"data" => #json }
})
%>
I did not set auto_adjust to false, because the map would not be centered on the marker anymore.
The 10 value for the zoom is nice to display approximatively a 50km-wide map.
what helped me in this case was this:
Gmaps4Rails.callback = function() {
setTimeout("Gmaps4Rails.map.setZoom(13);", 100);
};