This gem provides a simple way to use TradingView Chart Library for Ruby on Rails application.
Add this line to your application's Gemfile:
gem 'tv_chart_rails', :git => 'git@github.com:bobstar6/tv_chart_rails.git'
And then execute:
$ bundle install
Or install it yourself as:
$ gem install tv_chart_rails
-
First of all, ensure your app include jquery.
-
Add
<%= javascript_include_tag 'trading_view_chart' %>
to the template where need to insert tradingview chart. -
Use
showTradingViewChart()
to initialize a chart.<script type="text/javascript"> showTradingViewChart(); </script>
You can find default params in
tv_chart/vendor/javascripts/trading_view_chart.js
. Initialize your chart by sending hash params toshowTradingViewChart()
. It will overwrite the default params. -
Put this line to your html page where you want to insert chart.
<div id="tv_chart_container"></div>
You can change the id with hash params.
eg.
showTradingViewChart({ container_id: 'my_own_chart' })
then add this line
<div id="my_own_chart"></div>
-
If you want to use your own datafeed.js, you can replace it at
tv_chart/vendor/javascritps/charting_library/datafeed/datafeed.js
-
when develop your own datafeed, do not use the word 'config' as a method name for route like 'demo_feed.tradingview.com/config', change the word or remap route.
-
if your use the default datafeed.js, you should know this datafeed will use Json.parse to parse the response from ajax request.