0

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?

XcodeX
  • 79
  • 10
  • I´ve tried to change the Nvd3 code but it won´t work. Could be because of the dot instead of a comma? – XcodeX May 04 '15 at 08:25
  • Can you please post an example? Use http://jsfiddle.net – RenatoUtsch May 04 '15 at 16:32
  • Oh, and decimal format in computers uses dot, not a comma. – RenatoUtsch May 04 '15 at 16:33
  • Yes, an example would help people help you. Off the top of my head: if you're using a time axis, it's possible that the random behavior you're describing is due to the data-points not being sorted by time. – Lucas May 06 '15 at 01:20
  • I am trying to figure out how to show the example becuase with other problems I´ve faced before I couldn´t use jsfiddle due to the limitations of external js files.º – XcodeX May 12 '15 at 11:52
  • Maybe my develpment server works: https://pvpc-xprogrammerx.c9.io/consumo/ the axis are Y value (with decimal) and X name of the column. – XcodeX May 12 '15 at 12:04

1 Answers1

0

I´ve uploaded some pics with my the errors.

With the int format it works correctly:

http://imagizer.imageshack.us/a/img661/9545/0iFCaV.png

http://imageshack.com/a/img537/5459/EJ4y5j.png

But with the float format it can do it fine:

http://imageshack.com/a/img911/1020/fgeU1L.png

But sometimes this happens:

http://imageshack.com/a/img673/2812/at0wZm.png

XcodeX
  • 79
  • 10