Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Xeteskian opened this issue Dec 7, 2016 · 2 comments
Closed

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

Xeteskian opened this issue Dec 7, 2016 · 2 comments

Comments

@Xeteskian
Copy link

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

@akshar-raaj
Copy link
Member

akshar-raaj commented Dec 11, 2016

@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)

@akshar-raaj
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants