Code Monkey home page Code Monkey logo

Comments (5)

PresidentNick avatar PresidentNick commented on August 16, 2024

I need help with this too @areski . Is the issue that it assigns the same ID to each chart so the second one overwrites the first one?

from django-nvd3.

alex-pardo avatar alex-pardo commented on August 16, 2024

Same here @areski !

from django-nvd3.

Etiennepi avatar Etiennepi commented on August 16, 2024

To achieve this, you can simply define your data dict (the one you give to render_to_respone)

like this:

data = {
        'charttype1': charttypea,
        'chartdata1': chartdataa,
        'chartcontainer1': chartcontainera,
        'extra1': {
            'x_is_date': False,
            'x_axis_format': '',
            'tag_script_js': True,
            'jquery_on_ready': False,
        },
        'charttype2': charttype,
        'chartdata2': chartdata,
        'chartcontainer2': chartcontainer,
        'extra2': {
            'x_is_date': True,
            'x_axis_format': '%d %b %Y %H',
            'tag_script_js': True,
            'jquery_on_ready': False,
        }
    }

And then, in your template:

{% load nvd3_tags %}
<head>
    {# Jquery CDN : Needed when using jquery_on_ready=True #}
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    {% include_chart_jscss %}
    {% load_chart charttype1 chartdata1 chartcontainer1 extra1 %}
    {% load_chart charttype2 chartdata2 chartcontainer2 extra2 %}
</head>
<body>
    {% include_container chartcontainer1 %}
    <br>
    {% include_container chartcontainer2 %}
</body>

from django-nvd3.

cultivater avatar cultivater commented on August 16, 2024

To achieve this, you can simply define your data dict (the one you give to render_to_respone)

like this:

data = {
        'charttype1': charttypea,
        'chartdata1': chartdataa,
        'chartcontainer1': chartcontainera,
        'extra1': {
            'x_is_date': False,
            'x_axis_format': '',
            'tag_script_js': True,
            'jquery_on_ready': False,
        },
        'charttype2': charttype,
        'chartdata2': chartdata,
        'chartcontainer2': chartcontainer,
        'extra2': {
            'x_is_date': True,
            'x_axis_format': '%d %b %Y %H',
            'tag_script_js': True,
            'jquery_on_ready': False,
        }
    }

And then, in your template:

{% load nvd3_tags %}
<head>
    {# Jquery CDN : Needed when using jquery_on_ready=True #}
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    {% include_chart_jscss %}
    {% load_chart charttype1 chartdata1 chartcontainer1 extra1 %}
    {% load_chart charttype2 chartdata2 chartcontainer2 extra2 %}
</head>
<body>
    {% include_container chartcontainer1 %}
    <br>
    {% include_container chartcontainer2 %}
</body>

Hey @Etiennepi , I used your solution for pie chart, but it doesn't work.

from django-nvd3.

pcmaniac23 avatar pcmaniac23 commented on August 16, 2024

I got it working. Try the following code:

In views.py:

    # ... code above omitted....
    chartcontainer1 = 'piechart_container1'  # container name
    chartcontainer2 = 'piechart_container2'  # container name

    data = {
        'charttype1': charttype,
        'chartdata1': chartdata,
        'chartcontainer1': chartcontainer1,
        'extra1': {
            'x_is_date': False,
            'x_axis_format': '',
            'tag_script_js': True,
            'jquery_on_ready': False,
        },
        'charttype2': charttype,
        'chartdata2': chartdata,
        'chartcontainer2': chartcontainer2,
        'extra2': {
            'x_is_date': False,
            'x_axis_format': '',
            'tag_script_js': True,
            'jquery_on_ready': False,
        }
    }

In template (such as piechart.html):

{% load nvd3_tags %}
<head>
    {% include_chart_jscss %}
    {% load_chart charttype1 chartdata1 chartcontainer1 extra1 %}
    {% load_chart charttype2 chartdata2 chartcontainer2 extra2 %}
</head>
<body>
        <h1>Fruits vs Calories</h1>
        {% include_container chartcontainer1 %}
        <br>
        {% include_container chartcontainer2 %}
</body>

Here's a sample screenshot (two pie-charts based on the same dataset):
image

from django-nvd3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.