We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
callback
I am trying to configure line chart options, for formatting y-axes tick values.
class LineChartJSONView(BaseLineOptionsChartView): ... ## I have implemented `get_labels` & `get_data` functions ... def get_options(self): return { "responsive": True, "scales": { "xAxes": [{ "scaleLabel": { "display": True, "labelString": "Daily" } }], "yAxes": [{ "scaleLabel": { "display": True, "labelString": 'Count' }, "ticks": { "beginAtZero": True, ## Need to pass function from `dict` "callback": function (value) { if (value % 1 === 0) { return value; } } } }], }, } line_chart_json = LineChartJSONView.as_view()
I have called line_chart_json in template.
line_chart_json
... <html> <canvas id="myChart" width="500" height="400"></canvas> ... <script type="text/javascript"> $.get('{% url "line_chart_json" %}', function (response) { var ctx = $("#myChart").get(0).getContext("2d"); new Chart(ctx, { type: 'line', data: response.data, options: response.options }); }); </script> </html>
The text was updated successfully, but these errors were encountered:
I don't think we should support writting JavaScript in a Python string and then evaluate it in JS.
I guess one should define the javascript callback in javascript and then add it like that:
$.get('{% url "line_chart_json" %}', function (response) { var ctx = $("#myChart").get(0).getContext("2d"); var options = response.options; options.scales.yAxes[0].ticks.callback = function (value) { if (value % 1 === 0) { return value; } }; new Chart(ctx, { type: 'line', data: response.data, options: options }); });
Sorry, something went wrong.
No branches or pull requests
I am trying to configure line chart options, for formatting y-axes tick values.
I have called
line_chart_json
in template.The text was updated successfully, but these errors were encountered: