Adding more details per guidance...
Here's my model:
class Orders(models.Model):
Order_ID = models.CharField(max_length=50, primary_key=True, auto_created=True)
Order_Desc = models.CharField(max_length=255)
Order_Type = models.CharField(max_length=50)
Order_Received_Date = models.DateTimeField()
Order_Priority= models.CharField(max_length=10)
def __str__(self):
return (self.Order_ID)
In my views, i have the following query:
selected_year=request.GET.get('year', datetime.datetime.now().year-1)
Orders_By_Year = Orders.objects.annotate(extract_year=Cast('Order_Received_Date',CharField())).annotate(year=Substr('extract_year', Length('extract_year')-3, 4))
Orders = Orders_By_Year.filter(year=selected_year).values('Order_Type','Order_Priority').annotate(order_total=Count('Order_Priority')).order_by('Order_Type', 'Order_Priority')
This generated the following queryset based on the selected year:
<QuerySet [
{'Order_Type': 'Phone', 'Order_Priority': 'NA', 'Order_total': 2},
{'Order_Type': 'Web', 'Order_Priority': 'High', 'Order_total': 3},
{'Order_Type': 'Web', 'Order_Priority': 'Med', 'Order_total': 9}]>
I want to create a stacked bar chart using Bokeh that shows the total number of orders for each order type; each bar will also show the breakdown order priority (see image).
I'm getting an error because the axis categorical factors (Order Type in this case) is not unique. can someone help me with this?