I am trying to create a vertical bar chart, served by django, where I can change the chart contents based on a select box. The chart uses categorical data on the x-axis.
I am having a problem where the bokeh chart won’t even load on the page if I include x_range in the call to figure().
For example, the following code works:
This code is in the initial view that builds the page and returns the html with INLINE bokeh resources:
source = AjaxDataSource(
data_url=reverse("approval_count_data-approval"),
method="GET",
polling_interval=10000,
)
p = figure(
title="Approver Distribution",
x_axis_label="Approvers",
y_axis_label="Approval Count",
)
p.vbar(x='Approver', top='Approval Count', width=0.5, bottom=0, color='firebrick', source=source)
This code is in the view called by ajax:
return JsonResponse({"Approver": [1, 2], "Approval Count": [3, 4]})
Adding x_range=[1, 2] also works:
source = AjaxDataSource(
data_url=reverse("approval_count_data-approval"),
method="GET",
polling_interval=10000,
)
p = figure(
title="Approver Distribution",
x_axis_label="Approvers",
y_axis_label="Approval Count",
x_range=[1, 2]
)
p.vbar(x='Approver', top='Approval Count', width=0.5, bottom=0, color='firebrick', source=source)
However, changing x_range to a list of strings causes the plot to fail to load:
source = AjaxDataSource(
data_url=reverse("approval_count_data-approval"),
method="GET",
polling_interval=10000,
)
p = figure(
title="Approver Distribution",
x_axis_label="Approvers",
y_axis_label="Approval Count",
x_range=["Eric", "Keith"]
)
p.vbar(x='Approver', top='Approval Count', width=0.5, bottom=0, color='firebrick', source=source)
The corresponding change to the ajax view is:
return JsonResponse({"Approver": ["Eric", "Keith"], "Approval Count": [3, 4]})
I appreciate any thoughts on what I might be doing wrong when trying to do this with categorical data.
Thanks in advance.