Closed alabarga closed 10 years ago
+1 on this.
Hi @alabarga, I think this is not a bug in the sence that loading multiple charts is possible. We're just not doing it right.
I read through the code and figured it out. See the comments in templatetags/chartit.py
.
First argument to load_charts is a Chart list(or object), the second is comma separated list of HTML IDs where the charts need to be rendered.
Here's my code, which works:
return render(request, 'index.html',
{
'charts' : [chart_1, chart_2],
}
)
{{ charts|load_charts:"chart_1,chart_2" }}
<div id="chart_1">Chart will be rendered here</div>
<div id="chart_2">Chart will be rendered here</div>
I also think I know the reason this is designed in such a way. Looking at the result it is two script tags - one to load the HighCharts javascript file and the second to define an array of all chart objects to display in the page.
This said, if we wanted to use the syntax with two calls then we should have something like:
{% load_highchart_js_files %}
{{ linechart|load_chart:"container1"}}
{{ barchart|load_chart:"container2"}}
It just worked as well for me, many thanks @atodorov and @alabarga
Thanks guys!
still works in 2016!
It is not working quite like documented here anymore. The first graph shows up fine, but the second does not appear with the below code. `{% load chartit %} {{chart_list|load_charts:"cht_1,cht_2"}} {% block main %}
Home
<body>
<div id="cht_1">{{chart_list|load_charts:"cht_1"}}</div>
<div id="cht_2">{{chart_list|load_charts:"cht_2"}}</div>
</body>
{% endblock %}`
If I remove the "{{chart_list|load_charts:"cht_1"}}" from the actual html tags, it does not work at all. I found the below does work: `{% load chartit %} {{chart_list|load_charts:"cht_1,cht_2"}} {% block main %}
Home
<body>
<div id="cht_1">{{chart_list|load_charts:"cht_1,cht_2"}}</div>
<div id="cht_2">{{chart_list|load_charts:"cht_1,cht_2"}}</div>
</body>
{% endblock %}`
@smaislin186 your HTML doesn't look right and honestly I have no idea why it works or doesn't work in the two cases you describe. Here are a few notes for you though:
chart_list|load_charts
should be called only once in the entire HTML page. it's job is to render the javascript charts into the container IDs given as parameters. chart_list|load_charts
is put in the <head>
section of the HTML, right after the load chartit
template tag. From your description I get the feeling these two are somewhere in the <body>
demoproject/
to see how it is done.and finally: this piece of code hasn't been changed in years, only documentation was updated recently. Maybe the documentation isn't 100% clear but I don't think it is broken. If this still doesn't work for you please post a link to your entire HTML template.
Hi, Please help me with line charts. I have posted a question in stack, please suggest.
@SandeepKumar2016 answered on SO. Sorry for the delay.
Hi,
as I cannot find a mailing list or support email, how can you get multiple charts in different containers? I mean, how can you use the local_charts filter for multiple charts? is it possible at all?
{{ linechart|load_charts:"container"}}
using two calls
{{ linechart|load_charts:"container1"}} {{ barchart|load_charts:"container2"}}
did not work
regards,
Albertos