[Fixed]-Django chartit causes Mysql date json serialization error


So I managed to solve the problem in stupid way but some say that if it seems stupid but it works it is not stupid.

The solution was to modify simplejson library, more specifically it was ‘simplejson/encoder.py’ file. I’ve changed the ‘default’ method which is normally supposed to be overriden by more complex types from:

def default(self, o):
    raise TypeError(repr(o) + " is not JSON serializable")


def default(self, o):
    if isinstance(o, date):
        return o.strftime('%Y-%m-%d')
    raise TypeError(repr(o) + " is not JSON serializable")

I also had to add ‘from datetime import date’ on the top.
I was trying to do it otherwise but only this solution worked. I hope it will help someone in the future, and I also hope someone suggests better solution.



You got a Not JSON Serializable Object in this case a date comming from the field date in DailyStateArchive, you will need pre-process that value to send it to the view. You could try this:

myData = DailyStateArchive.objects.filter(company_name='06MAGNA').values()

for data in myData:
    data['date'] = data['date'].strftime('%Y-%m-%d')

ds = DataPool(
    [{'options': {
        'source': myData },
      'terms': [


chart = Chart(
        datasource = ds, 
        series_options = 
              'type': 'line',
              'stacking': False},
              'date' : [
        chart_options = 
          {'title': {
               'text': 'My Plot'},
           'xAxis': {
                'title': {
                   'text': 'Date'}}})

Leave a comment