【问题标题】:How to create a chart in a cell of the Bootstrap-vue tables?如何在 Bootstrap-vue 表的单元格中创建图表?
【发布时间】:2020-11-22 05:39:36
【问题描述】:

我正在尝试使用 Bootstrap-vue 表。我正在尝试添加一个列“图表”,我可以在其中显示图表中的数据。比如:

我对“图形”类型的图表(图中未显示)感兴趣。是否可以使用 Bootstrap-vue 表来完成?

【问题讨论】:

    标签: vue.js vuejs2 bootstrap-vue


    【解决方案1】:

    插槽:单元格 下面是来自 bootstrap-vue.org 的代码: 在模板内,您可以放置​​图表元素。并使用“数据”来获取您想要的信息。就像 data.item 是该行的全部内容

    <template>
      <div>
        <b-table small :fields="fields" :items="items" responsive="sm">
          <!-- A virtual column -->
          <template v-slot:cell(index)="data">
            {{ data.index + 1 }}
          </template>
    
          <!-- A custom formatted column -->
          <template v-slot:cell(name)="data">
            <b class="text-info">{{ data.value.last.toUpperCase() }}</b>, <b>{{ data.value.first }}</b>
          </template>
    
          <!-- A virtual composite column -->
          <template v-slot:cell(nameage)="data">
            {{ data.item.name.first }} is {{ data.item.age }} years old
          </template>
    
          <!-- Optional default data cell scoped slot -->
          <template v-slot:cell()="data">
            <i>{{ data.value }}</i>
          </template>
        </b-table>
      </div>
    </template>
    
    <script>
      export default {
        data() {
          return {
            fields: [
              // A virtual column that doesn't exist in items
              'index',
              // A column that needs custom formatting
              { key: 'name', label: 'Full Name' },
              // A regular column
              'age',
              // A regular column
              'sex',
              // A virtual column made up from two fields
              { key: 'nameage', label: 'First name and age' }
            ],
            items: [
              { name: { first: 'John', last: 'Doe' }, sex: 'Male', age: 42 },
              { name: { first: 'Jane', last: 'Doe' }, sex: 'Female', age: 36 },
              { name: { first: 'Rubin', last: 'Kincade' }, sex: 'Male', age: 73 },
              { name: { first: 'Shirley', last: 'Partridge' }, sex: 'Female', age: 62 }
            ]
          }
        }
      }
    </script>
    
    

    这是文档 https://bootstrap-vue.org/docs/components/table#tables 转到自定义数据呈现

    【讨论】:

    • 嗨!感谢您的回复,但该示例并未在单元格中创建图表。我阅读了文档,但找不到说明如何操作的示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-15
    相关资源
    最近更新 更多