Skip to content
New issue

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

zip object is not JSON serializable when generating graph #36

Closed
timothyleung opened this issue May 6, 2016 · 4 comments
Closed

zip object is not JSON serializable when generating graph #36

timothyleung opened this issue May 6, 2016 · 4 comments
Assignees
Labels

Comments

@timothyleung
Copy link

By following the tutorial, I have the following set up

# view 
def salesboard(request):
    # render the graph here
    data =  [
            ['Year', 'Sales', 'Expenses'],
            [2004, 1000, 400],
            [2005, 1170, 460],
            [2006, 660, 1120],
            [2007, 1030, 540]
        ]
    chart = flot.LineChart(SimpleDataSource(data=data), html_id="Line Chart")
    return render_to_response('scoreboard.html', {'chart':chart})

Template
{{ chart.as_html }}

Error

Error during template rendering

In template C:\Users\TIMLEU~1\Desktop\SYSTEM~1\sp-venv\lib\site-packages\graphos\templates\graphos\flot.html, error at line 4
<zip object at 0x00000052AAC8D448> is not JSON serializable
1   <div id="{{ chart.html_id }}" style="width:{{ chart.width }}px;height:{{ chart.height }}px;"></div>
2   <script type="text/javascript">
3   $(function () {
4       data{{ chart.html_id }} = {{ chart.get_series_objects_json|safe }}
5       $plot{{ chart.html_id }} = $.plot(
6           $("#{{ chart.html_id }}"),
7           data{{ chart.html_id }},
8           {{ chart.get_options_json|safe }}
9       );
10  });
11  </script>
@e78908b943c8
Copy link

I'm having the same issue with python3.4
I did some digging and found that get_serieses in BaseFlowChart is storing the result of zip which then gets json serialized.
image
The problem is that the zip method in python 2 returns a list of tuples whereas in python 3 a zip object is returned.
The zip should be converted to a list as such.
image

@timothyleung
Copy link
Author

Yup Thats what I did to fix it as well! Feel like we should create a pull request for this

@AuxProc
Copy link

AuxProc commented May 17, 2016

Pull request #32 takes care of this.

I've included this pull request in my fork at https://github.com/ModusVivendi/django-graphos and also on pip at django-graphos-3.

@akshar-raaj akshar-raaj self-assigned this Jul 19, 2016
@akshar-raaj
Copy link
Member

@timothyleung @e78908b943c8 @ModusVivendi @sheepeatingtaz PR #32 has been merged and updated code has been uploaded to Pypi. With recent "pip install django-graphos" this issue should be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants