chartit / django-chartit

A Django app to plot charts and pivot charts directly from the models. Uses HighCharts and jQuery JavaScript libraries to render the charts on the webpage.
http://django-chartit.mrsenko.com/
Other
492 stars 164 forks source link

highcharts formatter #59

Open flavio-pm opened 6 years ago

flavio-pm commented 6 years ago

Hello! I'm sorry if this isn't the place to ask, but I wanted to know if chartit supports passing formatter javascript functions to the chart, and if so, how to do so.

I have a two-level donut chart that retrieves data from the database, where each data object carries two distinct numeric values. I'm charting them together on the donut's outer layer with their total in the inner layer, but there's a lot of 0 values clustering at the top of the outer chart (which may, by the way, mean I'm not doing the drilldown right.) Since each zero value may be paired with a non zero value in their data objects, I can't straight up exclude them from the queryset. Google says to use a formatter function in HighCharts that checks the value and returns it only if it's greater than 0:

dataLabels: { formatter:function() { if(this.y != 0) { return this.y; } } }

Problem is, attempting to pass such a function as is conflicts with Python interpretation, and passing it as a string seems to erase the whole chart.

So, yeah, is there a way to pass functions as of now? And if not, can you guys help me figure out what to do?