如何隐藏谷歌图表中的列
我有一个 Google 图表表格,其中显示几列和几行。举例来说,我们有 4 列(分别为 A、B、C、D)。我怎样才能仍然加载 C 列的值,但只是隐藏该列以使其不显示?
提前致谢!
I've got a Google Charts Table that displays a couple of columns and rows. Say for instance we have 4 columns(A,B,C,D respectively). How would I be able to still load column C's values, but just hide the column so that it's not getting displayed?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您必须创建一个中间的 DataView 对象,在其中过滤原始数据,而不是绘制 DataTable。像这样的事情:
hideColumns 方法可能比 setColumns 更好,您自己选择!
干杯
Instead of drawing the DataTable, you have to create an in-between DataView object where you filter the original data. Something like this:
The hideColumns method is maybe better instead of setColumns, choose yourself!
Cheers
这是使用 ChartWrapper 而不是图表的替代方案。
如果您使用 ChartWrapper,您可以轻松添加一个函数来更改隐藏列或显示所有列。要显示所有列,请将
null
作为'columns'
的值传递。例如,在您的 html 中
使用 jQuery (注意:使用
eval
是为了简洁。使用适合您的代码的内容。这不是重点。)Here's an alternative using a ChartWrapper instead of a chart.
If you use a ChartWrapper, you can easily add a function to change the hidden columns, or show all the columns. To show all the columns, pass
null
as the value of'columns'
. For instance, using jQuery,In your html,
(Note:
eval
used for conciseness. Use what suits your code. It's beside the point.)您可以使用 CSS 来做到这一点。
“#table_div”是我的表格所在的 div。我使用它是因为同一页面上有多个表格。
我还在图表的行上有一个事件处理程序,并且仍然可以从隐藏列中获取数据。
You can do this with CSS.
"#table_div" is the div my table is wrapped in. I use this because there a multiple tables on the same page.
I also have an event handler on the chart's rows, and can still pick up the data from the hidden column.
如果您想在控件包装器中使用特定的列值,但不想在 Google 图表中显示该列,请执行以下操作。
1) 将所有列添加到您的谷歌图表数据表中。
2)将以下内容添加到图表包装器的选项中。
3) 在上面的代码系列中,0 表示折线图中的第一行。因此它将颜色设置为白色并隐藏图例中的列名称。
4)这种方式不是隐藏列的正确方式,建议使用DataView。每当您想要使用数据表中的数据向图表添加控件但又不想在图表中显示该列时,就是这样。
If you want to use particular column value in control wrapper but don't want to show that column in Google Charts then do following things.
1) Add all column to your google charts data table.
2) Add following things to options of your chartWrapper.
3) In above code series, 0 means the first line in your line chart. So It will set the color to white and also hide column name in Legends.
4) This way is not the proper way to hide columns, Using DataView is recommended. Whenever you want to use data in the data table for adding controls to your chart but don't want to show that column in the chart this is the way.