I am building up a web using Django in the server an Nvd3 as the chart drawer.
For retrieving the data I have a special method in the "models" which get´s the data from the attribute searched and returns an int. This is the way I have been using:
datum = int(getattr(self, field, None))
Because all the data were rounded I decided to use a format so the graph would be more exact:
datm = '{0:.2f}'.format(getattr(self, field, None))
The given result is as follows:
[{'value': '10.58', 'label': 'carg_cap'}, {'value': '0.00', 'label': 'coef_perf'}, {'value': '126.12', 'label': 'feu'}, {'value': '0.00', 'label': 'per_hor'}, {'value': '1.00', 'label': 'per_tar'}, {'value': '60.52', 'label': 'pmh'}, {'value': '8.83', 'label': 'sah'}, {'value': '1.00', 'label': 'tar'}]
After retrieving the data, I transform it into JSON and return it with:
return JsonResponse(data,safe=False)
The problem I am facing is if I use the "int" way the chart works perfectly but if I use the decimal way it starts to act randonmly:
The scales sometimes don´t work. For example, if one of the datum is 134,76 and other 65,4, the maximum scale would be 66 and both bars in the barchart would be shown as full-filled (until the top of the graph) but as they show their value, 134,76 will be as high a 65,4.
I´ve tried to change the behavoir but it didn´t work. Is nvd3 incompatible with this decimal format?