agiliq/django-graphos

Is there a way to plot multiple datasets to a single graph?

Closed this issue · 2 comments

Firstly, loving the simplicity of Graphos.
I do have a question however; Is there a way to plot multiple datasets to a single graph, and if not are there any plans to introduce this feature?

i.e.

queryset1 = model.objects.filter(salesman='adam')
queryset2 = model.objects.filter(salesman='bob')
data_source = [ModelDataSource(queryset1, fields=['monthly_sales']),
                        ModelDataSource(queryset2, fields=['monthly_sales'])]

I cant find any reference in the documentation

@Xeteskian

You can do this with a SimpleDataSource. I assume you want to plot two data serieses, one for adam and other for bob. I assume you want to plot montly sales for them.

SimpleDataSource data can be visualized like this.

months    adam    bob
Jan        500       600
Feb        410       546
March    651       630

Code for this would roughly be:

months = ['months', 'Jan', 'Feb', 'March']
adam_monthly_sales =       model.objects.filter(salesman='adam').order_by('month').values_list('monthly_sales', flat=True)

adam_monthly_sales = ['adam'] + adam_monthly_sales
bob_monthly_sales = model.objects.filter(salesman='bob').order_by('month').values_list('monthly_sales', flat=True)
bob_monthly_sales = ['bob'] + bob_monthly_sales

data = zip(months, adam_monthly_sales, bob_monthly_sales)
data_source = SimpleDataSource(data)

@Xeteskian I assume your problem is resolved with last comment, so closing this.