areski / django-nvd3

Django wrapper for nvd3 - It's time for beautiful charts
Other
417 stars 124 forks source link

'str' object does not support item assignment #39

Closed realmhamdy closed 10 years ago

realmhamdy commented 10 years ago

Hi there, I'm trying to use this example http://django-nvd3.readthedocs.org/en/latest/classes-doc/discrete-bar-chart.html and it's raising the TypeError mentioned above. The line triggering the exception in the template is this : {% load_chart charttype chartdata chartcontainer extra %} Which maps to this code: kw_extra['x_is_date'] = False

Logging kw_extra to a file reveals that it's a space and a new line.

Here's the relevant view code, it's very similar to your example referenced above:

  def get_context_data(self, **kwargs):
    context = super(ResultsView, self).get_context_data(**kwargs)
    # obtain the voting statistics for each answer
    question_id = self.kwargs.get("pk")
    page_question = Question.objects.get(pk=question_id)
    choices = page_question.choice_set.all()
    x_data = [choice.choice_text for choice in choices]
    y_data = [choice.votes for choice in choices]
    extra_serie1 = {"tooltip": {"y_start": "", "y_end": " cal"}}
    chartdata = {
        'x': x_data, 'name1': '', 'y1': y_data, 'extra1': extra_serie1,
    }
    charttype = "discreteBarChart"
    data = {
        'charttype': charttype,
        'chartdata': chartdata,
    }
    context.update(data)
    return context```
areski commented 10 years ago

Could you look at the example that is provide here: https://github.com/areski/django-nvd3/blob/develop/demoproject/demoproject/views.py#L369

realmhamdy commented 10 years ago

Thanks @areski . I added the extra dictionary and now it works.

data = {
        'charttype': charttype,
        'chartdata': chartdata,
        "chartcontainer":chartcontainer,
        'extra': {
            'x_is_date': False,
            'x_axis_format': '',
            'tag_script_js': True,
            'jquery_on_ready': True,
        },
    }

So I suggest that you update the example url above so nobody bumps into this again. For now, Cheers!