简体   繁体   English

Bokeh DataTable 中文本的垂直 alignment

[英]Vertical alignment of text within Bokeh DataTable

I have the following code that produces a datatable in Bokeh:我有以下代码在 Bokeh 中生成数据表:

from bokeh.models import DataTable, TableColumn, HTMLTemplateFormatter

data = {'A': ['A1', 'A2', 'A3', 'A4'],
        'B': ['B1', 'B2', 'B3', 'B4'],
        'C': ['C1', 'C2', 'C3', 'C4'],
        'D': ['D1', 'D2', 'D3', 'D4']}


source = ColumnDataSource(data)

table = DataTable(height=500, 
                  width=500, 
                  source=source, 
                  row_height=50,
                  columns=[TableColumn(field=col, title=col) for col in data.keys()])

# Align text horisontally (need to do it vertically as well)
for col in table.columns:
    col.formatter.text_align = 'center'
    
show(table)

This produces the following table:这将产生下表:

散景数据表

I would like to align the text vertically in the middle of the cells.我想在单元格中间垂直对齐文本。 From what I've seen online I could use HTMLTemplateFormatter to achieve this, but I'm not quite sure how.从我在网上看到的情况来看,我可以使用HTMLTemplateFormatter来实现这一点,但我不太确定如何。

It looks like you can set it in the DataTable by the attribute min_height .看起来您可以通过属性min_heightDataTable中设置它。

table = DataTable(
    ...,
    row_height=50,
    min_height = 45,
)

This looks almost centered.这看起来几乎居中。 The downside is, that the index column is not effectd.缺点是索引列不受影响。

居中文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM