You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Pine Script中实现表格最后一个单元格跨两列显示?

Pine Script 表格单元格跨列实现方案

你已经完成了3列5行的仪表盘表格开发,要让最后一个单元格(对应代码末尾的table.cell)跨两列显示,只需利用Pine Script中table.cell()函数的colspan参数即可实现。

修改方法

在最后一行的table.cell()调用中添加colspan=2参数,该参数会让单元格直接跨越指定数量的列,无需再为第2列的对应行单独创建单元格。

修改后的完整代码

var dashboard = table.new(position = position.top_right, columns = 3, rows = 5, border_width = 5, frame_color = color.new(color.white, 100))

table.cell(dashboard, 0, 0, text = "Trend", text_color = color.white, text_halign = text.align_left, text_valign = text.align_center, bgcolor = color.gray)
table.cell(dashboard, 1, 0, text = "Uptrend", text_color = color.white, text_halign = text.align_center, text_valign = text.align_center, bgcolor = color.lime, width = 5)
table.cell(dashboard, 2, 0, text = "Downtrend", text_color = color.white, text_halign = text.align_center, text_valign = text.align_center, bgcolor = color.red, width = 5)

table.cell(dashboard, 0, 1, text = "Stocks", text_color = color.white, text_halign = text.align_left, text_valign = text.align_center, bgcolor = color.gray)
table.cell(dashboard, 1, 1, text = str.tostring(uptrend), text_color = color.white, text_halign = text.align_center, text_valign = text.align_center, bgcolor = color.lime, width = 5)
table.cell(dashboard, 2, 1, text = str.tostring(downtrend), text_color = color.white, text_halign = text.align_center, text_valign = text.align_center, bgcolor = color.red, width = 5)

table.cell(dashboard, 0, 2, text = "Stocks (%)", text_color = color.white, text_halign = text.align_left, text_valign = text.align_center, bgcolor = color.gray)
table.cell(dashboard, 1, 2, text = str.tostring(uptrendPercentage), text_color = color.white, text_halign = text.align_center, text_valign = text.align_center, bgcolor = color.lime, width = 5)
table.cell(dashboard, 2, 2, text = str.tostring(downtrendPercentage), text_color = color.white, text_halign = text.align_center, text_valign = text.align_center, bgcolor = color.red, width = 5)

table.cell(dashboard, 0, 3, text = "Weight (%)", text_color = color.white, text_halign = text.align_left, text_valign = text.align_center, bgcolor = color.gray)
table.cell(dashboard, 1, 3, text = str.tostring(uptrendWeight), text_color = color.white, text_halign = text.align_center, text_valign = text.align_center, bgcolor = color.lime, width = 5)
table.cell(dashboard, 2, 3, text = str.tostring(downtrendWeight), text_color = color.white, text_halign = text.align_center, text_valign = text.align_center, bgcolor = color.red, width = 5)

table.cell(dashboard, 0, 4, text = "Dollar", text_color = color.white, text_halign = text.align_left, text_valign = text.align_center, bgcolor = color.gray)
// 新增colspan=2参数,实现跨两列显示
table.cell(dashboard, 1, 4, text = Dtrend, text_color = color.white, text_halign = text.align_center, text_valign = text.align_center, bgcolor = Dcolor, width = 5, colspan=2)

关键说明

  • colspan参数用于定义单元格跨越的列数,设置为2后,该单元格会同时占据第1列和第2列的位置
  • 无需再编写table.cell(dashboard, 2, 4, ...)的代码,跨列单元格已覆盖该位置

内容的提问来源于stack exchange,提问作者user19792349

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 02:15:32