vba Excel 图表可以交互缩放和平移吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7559795/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 14:06:44  来源:igfitidea点击:

Can Excel charts be interactively zoomed and panned?

excelexcel-vbachartsvba

提问by Matt Chambers

I've always wanted this feature in excel

我一直想要这个功能在excel 中

I'm wondering if it's possible to develop a plugin or if one exists already?

我想知道是否可以开发插件或者是否已经存在?

回答by brettdj

They can if you use dynamic names ranges. Stephen Bullen has a great example here

如果您使用动态名称范围,它们可以。斯蒂芬布伦在这里有一个很好的例子

Screenshot below
The data can be zoomed (amount of data) and scrolled (change start position)

下面
截图数据可以缩放(数据量)和滚动(改变开始位置)

funchart7

功能图7

回答by onkel_keks

This might be irrelevant by now (seeing as it's been half a year), but: One improvement for Stephen Bullen's approach I would suggest is to map the scrollbar values to the actual values. What I mean is this: if you're fully zoomed out (you see everything), you can still scroll around which doesn't make sense. Additionally, if your dataset grows, you'd have to reformat the scrollbars max. values. I solved it like this:

现在这可能无关紧要(因为已经半年了),但是:我建议对 Stephen Bullen 方法的一项改进是将滚动条值映射到实际值。我的意思是:如果你完全缩小(你看到一切),你仍然可以滚动,这是没有意义的。此外,如果您的数据集增长,您必须重新格式化最大滚动条。值。我是这样解决的:

  • Let both scrollbars assume values 1-1000.

  • Let a specific cell contain the number of the last row of your dataset (can be formula-computed somehow, I guess) - I assume cell Z1 contains this information.

  • Define a new name 'ActualZoomVal', let it point to an arbitrary cell. I assume Z2 here.

  • Define a new name 'ActualScrollVal', let it point to a different arbitrary cell. I assume Z3 here.

  • Let the cell of 'ActualZoomVal' contain following formula: =MAX(2;ROUND(ZoomVal*($Z$1/1000);0))

  • Let the cell of 'ActualScrollVal' contain following formula: =ROUND(($Z$1-ActualZoomVal)*(ScrollVal/1000);0)

  • Create the diagram as suggested in Stephen Bullen's example file, but with ActualZoomVal/ActualScrollVal instead of ZoomVal/ScrollVal

  • 让两个滚动条假定值 1-1000。

  • 让特定单元格包含数据集最后一行的编号(我猜可以以某种方式进行公式计算) - 我假设单元格 Z1 包含此信息。

  • 定义一个新名称“ActualZoomVal”,让它指向任意单元格。我假设 Z2 在这里。

  • 定义一个新名称“ActualScrollVal”,让它指向不同的任意单元格。我假设 Z3 在这里。

  • 让 'ActualZoomVal' 的单元格包含以下公式: =MAX(2;ROUND(ZoomVal*($Z$1/1000);0))

  • 让 'ActualScrollVal' 的单元格包含以下公式:=ROUND(($Z$1-ActualZoomVal)*(ScrollVal/1000);0)

  • 按照 Stephen Bullen 示例文件中的建议创建图表,但使用 ActualZoomVal/ActualScrollVal 而不是 ZoomVal/ScrollVal

Not only is this a 'cleaner' and more flexible solution, it also improves usability - say you want to zoom in on the last part of the data set from a fully zoomed out state, then just set the scroll bar all the way to the right and keep zooming in until you've reached the desired zoom level.

这不仅是一个“更干净”和更灵活的解决方案,它还提高了可用性 - 假设您想从完全缩小状态放大数据集的最后一部分,然后只需将滚动条一直设置到向右并继续放大,直到达到所需的缩放级别。

回答by Excel Campus

Here is one solution for zooming on Excel charts. You add a zoom button to the chart, and pressing the button calls a macro to enlarge the chart by a specified amount.

这是放大 Excel 图表的一种解决方案。您向图表添加一个缩放按钮,按下该按钮会调用一个宏以将图表放大指定的数量。

The workbook containing the macro is available for free download at

包含宏的工作簿可在以下网址免费下载

http://www.excelcampus.com/vba/zoom-on-excel-charts

http://www.excelcampus.com/vba/zoom-on-excel-charts