admin管理员组

文章数量:1410737

I am developing with the BokehJS library and need some help since the documentation for the JS side of the library is pretty thin.

In python you can change the text alignment via the following mand,

p = figure(title='Title',plot_width=500, plot_height=200, tools='')
p.title.text_align = 'center'

In JS there is no parable attribute.

var plt = Bokeh.Plotting;
var p = plt.figure({ title: "Title",height: 300,width: 300,tools: ''});
p.title.<???>

I believe the anchor function is responsible for setting the alignment but I need help.

I am developing with the BokehJS library and need some help since the documentation for the JS side of the library is pretty thin.

In python you can change the text alignment via the following mand,

p = figure(title='Title',plot_width=500, plot_height=200, tools='')
p.title.text_align = 'center'

In JS there is no parable attribute.

var plt = Bokeh.Plotting;
var p = plt.figure({ title: "Title",height: 300,width: 300,tools: ''});
p.title.<???>

I believe the anchor function is responsible for setting the alignment but I need help.

Share Improve this question asked Jun 27, 2017 at 15:49 DavidDavid 1172 silver badges14 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

There is a strict 1-1 correspondence maintained between the Python Bokeh models, and the corresponding BokehJS models (this is maintained under test). So the Python Reference Guide is not a terrible reference for BokehJS as well.

However, in this particular case, it's not text_align that want. Instead you should use:

p.title.align = 'center'

The uninteresting reason is that text_align has a specific meaning to the HTML canvas, that does not really correspond well to aligning titles.


As an aside, BokehJS used to be purely a hidden implementation detail, which is why the docs for it are thin. We are definitely interested in developing it better as a standalone JS library, including improving the documentation, but that takes people-time, which is currently spread very thin. If you'd be interested in helping improve BokehJS please reach out on GitHub or the Discourse.

Ok, I figured out the solution through navigating the attributes in the chrome developer tools.

var plt = Bokeh.Plotting;
var p = plt.figure({ title: "Title",height: 300,width: 300,tools: ''});
p.attributes["above"][0]['align']='center';

The code above centers the title text as I desired. In the case above, the plot attribute in the "above" position is the Title.

本文标签: javascriptBokehJS Title Text AlignmentStack Overflow