为 HTML 表中的数据创建相对颜色算法的最佳方法是什么?

发布于 2024-10-06 11:33:45 字数 274 浏览 0 评论 0原文

我有一个 HTML 数据表,我想模仿 Excel 颜色比例用于条件格式,因此它突出显示这组数据的相对值。

HTML表格只是绘制了一个行列表,对于每一行,我都有一个值(0-300),我想让它根据这个算法为表格行的背景着色,所以我假设它需要为输入的每个数字生成 HTML 颜色名称或值

有帮助从哪里开始吗?

I have an HTML table of data and I want to mimic the Excel Color scales for conditional formatting so it highlights the relative value across this set of data.

The HTML table is simply drawing out a list of rows and for each row I have a value ( 0 - 300) and i want to have it color the background of the row of the table based on this algorithm so I assume it will need to generate an HTML color name or value for each number that is input

Any help where to start here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静水深流 2024-10-13 11:33:45

您可以使用这个 ,并且在决定生成颜色时,将行值除以 300 以使用精确函数。

编辑(最初是注释)

指定 html 颜色时,可以使用 rgb(Rvalue, Gvalue, Bvalue) 表示法。或者您可以将十进制值转换为相当于 #RRGGBB 表示法的十六进制值。

在 javascript 中,这可以通过遵循 此方法来实现转换为十六进制

You could use this, and when deciding to generate the color, divide the row value/300 to use the exact function.

Edit (Originally a comment)

When specifying html colors, you can use the rgb(Rvalue, Gvalue, Bvalue) notation. Or you could convert the decimal values to their hex equivalent to to the #RRGGBB notation.

In javascript, this would be achieved by following this method to convert to hex

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文