Last active
September 1, 2017 07:57
-
-
Save trAve3113r/261e48614a3699c779337cc083a70c7c to your computer and use it in GitHub Desktop.
A page that displays candlesticks and SR lines with Google Charts via AJAX
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>Google Charts Tutorial</title> | |
| <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> | |
| <script type="text/javascript"> | |
| google.charts.load('current', {packages: ['corechart']}); | |
| </script> | |
| </head> | |
| <body> | |
| <div id="container" style="width: 550px; height: 400px; margin: 0 auto"></div> | |
| {% for ohlcdf in object_list %} | |
| <script language="JavaScript"> | |
| function drawChart() { | |
| // Define the chart to be drawn. | |
| var data = google.visualization.arrayToDataTable([ | |
| [ {{ohlcdf.timestamp|date}}, {{ohlcdf.open}}, {{ohlcdf.high}}, {{ohlcdf.low}}, {{ohlcdf.close}}] | |
| // Treat first row as data as well. | |
| ], true); | |
| // Set chart options | |
| var options = { | |
| legend: "none", | |
| }; | |
| // Instantiate and draw the chart. | |
| var chart = new google.visualization.CandlestickChart(document.getElementById('container')); | |
| // var chart = new google.visualization.ComboChart(document.getElementById('container')); | |
| chart.draw(data, options); | |
| } | |
| google.charts.setOnLoadCallback(drawChart); | |
| </script> | |
| {% empty %} | |
| <div class="stylish"> | |
| Oops! No Ohlc data to display | |
| </div> | |
| {% endfor %} | |
| </div> | |
| </body> | |
| </html> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The ListView
`from django.views.generic import ListView
from django_ajax.mixin import AJAXMixin
class MyListView(AJAXMixin, ListView):
template_name = 'my_template_list.html'
def get_queryset(self):
queryset = OhlcDf.objects.filter(Q(instrument=#)& Q(time_frame=#))
return queryset
`
Further readings:
https://developers.google.com/chart/interactive/docs/gallery/combochart
https://developers.google.com/chart/interactive/docs/roles