It almost worked. Here is the actual code:
var plt = Bokeh.Plotting;
var bar_data = [
['City', '2010 Population', '2000 Population'],
['NYC', 8175000, 8008000],
['LA', 3792000, 3694000],
['Chicago', 2695000, 2896000],
['Houston', 2099000, 1953000],
['Philadelphia', 1526000, 1517000],
];
var p1 = Bokeh.Charts.bar(bar_data, {
axis_number_format: "0.[00]a",
orientation: "vertical",
stacked: true
});
var LegendItem = Bokeh.Models('LegendItem');
var Legend = Bokeh.Models('Legend');
var item1 = new LegendItem({label:'label1', renderers:[p1], index:0});
var item2 = new LegendItem({label:'label2', renderers:[p1], index:1});
var legend = new Legend({items:[item1, item2]})
p1.add_layout(legend)
plt.show(p1);
It shows only the ‘label1’ on the top_right corner, without any colors on the legend. The ‘label2’ was not shown. I got this error:
bokeh-2.1.0.min.js:304 Uncaught (in promise) TypeError: Cannot read property ‘draw_legend’ of undefined
at g._draw_legend_items (bokeh-2.1.0.min.js:304)
at g.render (bokeh-2.1.0.min.js:304)
at P._paint_levels (bokeh-2.1.0.min.js:472)
at P.paint (bokeh-2.1.0.min.js:472)
at P.after_layout (bokeh-2.1.0.min.js:472)
at P.compute_layout (bokeh-2.1.0.min.js:421)
at P.build (bokeh-2.1.0.min.js:421)
at P.renderTo (bokeh-2.1.0.min.js:421)
at r (bokeh-2.1.0.min.js:548)
at async Object.t.add_document_standalone (bokeh-2.1.0.min.js:548)