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

Can't use model properties in chartit #35

Closed luflow closed 7 years ago

luflow commented 8 years ago

Hi everyone!

I tried to use chartit with a property in my model but then I get a "Field XYZ does not exist. Valid lookups are ..."

The main problem I wanted to solve was to format the date from the database for the x-Axis in a specific manner. Maybe there is another solution for this which I cant figure out at the moment? I already tried to use js options of chartit to reformat the date like documented here http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/xaxis/datetimelabelformats/ but it seems as these options are only working on js date data and not with strings from the database...

atodorov commented 8 years ago

@krautnerds - formatting datetime fields should be possible on the DB level using extra(), please see the latest commits for examples.

Otherwise the possibility to chart using model properties is sounds great but it is not easy to implement at the moment. chartit relies heavily on QuerySet (in fact it uses QuerySet.values() to fetch the data) and this operates on the DB level. It may be possible to rewrite the model manager to allow for this but I'm not sure how well will that work.

Sh4kE commented 8 years ago

In my case this would also be needed, because I want to compare two distinct querysets and show the computed diff. Or is there also another possibility to do this kind of tasks?

ajurna commented 8 years ago

My problem stems from it using raw data from the DB so all my times are in utc with no good way to convert them to local time.

atodorov commented 8 years ago

@Sh4kE - can you elaborate more on your use case ? How do you imagine you will compare query sets with chartit ? Without any more info I think you can compute the diff between the two query sets and create a new one from it. Then pass the new QS to chartit for plotting on a chart.

atodorov commented 8 years ago

@ajurna datetime conversions should be now possible by using extra() or annotate() fields, see changelog and the examples in demo project. Let me know if that works for you ? Maybe we only need to update the docs to make this more visible.

ajurna commented 8 years ago

timezone and strftime conversions are two very separate things... doing both makes it look messy and makes it depend on a DB type which doesn't really suit me.

atodorov commented 7 years ago

@krautnerds @Sh4kE @ajurna - hey guys I know I've been late to respond to this but I think I have finally managed to fix it. Following my changes related to #44 (removal of .values()) chartit now operates on objects instead of dictionaries and it was very easy to call a model property instead of a field.

Can you check out my fork + topic branch and tell me how that works for you? Note that the changes are only for DataPool, not PivotDataPool, which I'm planning to phase out.