我用Obsidian来记笔记,这是一个应用程序,允许以标记格式写笔记,并使用社区的插件(如Chromestore 扩展).所以我安装了两个插件Dataview(允许嵌入dataviewjs个代码块)和Obsidian Chart(支持集成Dataview来绘制图表).这两个插件放在一起,所以我可以像这样使用Chart.js:

test:: First Test
mark:: 6

```dataviewjs
const data = dv.current()

const chartData = {
    type: 'bar',
    data: {
        labels: [data.test],
        datasets: [{
            label: 'Grades',
            data: [data.mark],
            backgroundColor: [
                'rgba(255, 99, 132, 0.2)'
            ],
            borderColor: [
                'rgba(255, 99, 132, 1)'
            ],
            borderWidth: 1
        }]
    }
}

window.renderChart(chartData, this.container);```

上面的代码块将呈现following chart.回到主要问题,我现在创建一个睡眠信息数据表,如下所示:

|   | Mon | Tue | Wed | Thu | Fri | Sat | Sun |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| Bedtime | 09.30 | 22 | 22.30 | 21.45 | 23 | 22 | 21 |
| Wake up | 05.45 | 06.30 | 22 | 5.30 | 5.45 | 5 | 7 |
| Sleep duration | 5 | 7 | 7.5 | 8 | 6.5 | 7 | 5 |
  • 我的问题是:above title:v

THANKS IN ADVANCE!!!

我正在try 访问行的数据单元格:Bedtime, Wakeup and Sleep持续时间,以便在类似this的图表中表示它们.就这样!

推荐答案

嗯,我不是黑岩专家,也不是插件专家,但如果你查看"黑岩图表"的文档,你会发现基本的表格-图表连接是有效的(100).只需将表命名为^tableName.并使用以下命令创建图表:

type: bar
id: ^tableName
layout: rows
width: 80%
beginAtZero: true

This would generate this chart:
Screenshot chart creation-plugin

但我认为对于你想要的特定图表,将需要一些编码,因为据我所见,该插件确实支持所有的chartjs功能.

也就是说,如果我必须解决这个问题,我会使用dataviewjs来创建装入表格并构建图表的Java脚本.

Here a short documented Demo, explaining how to approach this:
(This is just a partial demo, and should be optimized)

```dataviewjs

// Generate the labels, from the html table
let labels = [].map.call(document.body.querySelectorAll('table.table-editor thead th'), 
    (x) => x.innerText).filter( x=> x.replace(/\n|\t|\s/gi, '') != '');

// Get the table, from the html table
let htmlTable = document.body.querySelector('table tbody')
let rows = [].map.call(htmlTable.querySelectorAll('tr'), x => x)
let data = '1'.repeat(2).split('').map( x => []);
let colsLength = [].map.call(rows[0].querySelectorAll('td'), x =>  x).length;

// creating the data form needed for floating bar charts: [ [start, end], ...]
for(let cIdx = 1; cIdx < 8; cIdx++){
    data.push([])
    for(let rowIdx = 0; rowIdx < 2; rowIdx++){
        let cols = [].map.call(rows[rowIdx].querySelectorAll('td'), x =>  moment(x.innerText, 'hh:mm'));
        data[cIdx - 1].push(cols[cIdx] );
    }

}

// chartjs config
let chartConfig = {
    type: 'bar',
    data: {
        labels: labels,
        datasets: [{
            label: '',
            data: data,
            borderWidth: 1
        }]
    },
   options:{
        scales: {
            y: {
                min: moment('00:00:00', 'hh:mm'),
                max: moment('23:59:59', 'hh:mm'),
                ticks: {
                stepSize: 60,
                beginAtZero: false,
                },
                type: 'time',
                time:{
                    minutes: 'hh:mm'
                }
            }
        }
    }
};

window.renderChart(chartConfig, this.container);

```

this should generate a chart like this:
screenshot obsidian-generated Chart

Info:要从图像中创建缺失的行,只需将两行数据集添加到chartConfig变量中,如this official example所示.

btw:,while building this demo, i noticed that the plugins or Obsidian, is abit buggy, so the rendering can vary or produce errors, but a simple restart of the application/plugins, fixes sometimes the problems..

Javascript相关问答推荐

TypScript界面中的Infer React子props

硬币兑换运行超时

类型脚本中只有字符串或数字键而不是符号键的对象

将旋转的矩形zoom 到覆盖它所需的最小尺寸&S容器

如何调用名称在字符串中的实例方法?

阿波罗返回的数据错误,但在网络判断器中是正确的

保持物品顺序的可变大小物品分配到平衡组的算法

无法使用单击按钮时的useState将数据从一个页面传递到另一个页面

Next.js服务器端组件请求,如何发送我的cookie token?

在Matter.js中添加从点A到另一个约束的约束

TypeError:无法读取未定义的属性(正在读取';宽度';)

是否可以在Photoshop CC中zoom 路径项?

SPAN不会在点击时关闭模式,尽管它们可以发送日志(log)等

如果一个字符串前面有点、空格或无字符串,后面有空格、连字符或无字符串,则匹配正则表达式

令牌JWT未过期

为什么在函数中添加粒子的速率大于删除粒子的速率?

当从其他文件创建类实例时,为什么工作线程不工作?

如何使用抽屉屏幕及其子屏幕/组件的上下文?

通过解构/功能组件接收props-prop验证中缺少错误"

在Puppeteer中使用promise进行日志(log)记录时出现TargetCloseError