Comments (9)
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"}}
from django-chartit.
+1 on this.
from django-chartit.
It just worked as well for me, many thanks @atodorov and @alabarga
from django-chartit.
Thanks guys!
from django-chartit.
still works in 2016!
from django-chartit.
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 %} <p>Home</p> <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 %} <p>Home</p> <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 %}
from django-chartit.
@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.- Usually
chart_list|load_charts
is put in the<head>
section of the HTML, right after theload chartit
template tag. From your description I get the feeling these two are somewhere in the<body>
- Checkout the templates in
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.
from django-chartit.
Hi, Please help me with line charts. I have posted a question in stack, please suggest.
from django-chartit.
@SandeepKumar2016 answered on SO. Sorry for the delay.
from django-chartit.
Related Issues (20)
- 'Options' object has no attribute 'get_all_field_names' HOT 1
- Support for RawQuerySet HOT 3
- 'Graph' object has no attribute 'META' HOT 2
- Change series label on line charts HOT 2
- setting legend order HOT 2
- How to do drilldowns? HOT 2
- Generate Charts from Views? HOT 4
- chartit.shutupandship.com HOT 2
- Publish demo site automatically from Travis CI
- time series data HOT 1
- Uncaught ReferenceError: $ is not defined at chartloader.js:3 HOT 6
- Line chart is not rendering a graph. It's showing {% load chartit %} in browser. HOT 1
- 'NoneType' object is not subscriptable HOT 8
- highcharts formatter
- __proxy__ found error if translated field supplied as "legend_by"
- can this be used by Jinja2 engine? how
- Themes
- column chart data is being sorted by y-axis values HOT 1
- can't import six HOT 1
- django.utils.six
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-chartit.