vba 将水平线延伸到图表区域的边缘
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22665199/
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
Extend horizontal line to edges of chart area
提问by neizan
In Excel 2007 I have a chart with a horizontal line (data series) similiar to what this pageshows. But, as you notice, the line starts and ends in the middle of the data point. So, if there are bars on the same chart, the horizontal line will not extend to cover the entire first and last bars. How can I extend the horizontal line to touch the chart edges on the left and right sides?
在 Excel 2007 中,我有一个类似于此页面显示的水平线(数据系列)的图表。但是,正如您所注意到的,该线在数据点的中间开始和结束。因此,如果同一图表上有柱线,则水平线不会延伸以覆盖整个第一个和最后一个柱线。如何延长水平线以触摸左右两侧的图表边缘?
I tried putting in "dummy" points at the beginning and end of the data series that had zero values (for the bars). This looked good, but the x-axis numbering started at zero and ended at one more than my last real data point, which, in my case is unacceptable.
我尝试在具有零值的数据系列的开头和结尾放置“虚拟”点(对于条形)。这看起来不错,但是 x 轴编号从零开始,以比我上一个实际数据点多一个结束,这在我的情况下是不可接受的。
Oh, and I'm creating the charts in VBA, so I need a VBA solution (which may be the same as the manual solution, just coded). Thanks.
哦,我正在 VBA 中创建图表,所以我需要一个 VBA 解决方案(可能与手动解决方案相同,只是编码)。谢谢。
采纳答案by neizan
回答by Brodderick
If you right click on the horizontal axis and go into axis options. At the very bottom under Position Axis: select "On Tick Marks"
如果您右键单击水平轴并进入轴选项。在位置轴下的最底部:选择“在刻度线上”
回答by Mitja Bezen?ek
I answered a similar questions here: Bar and Line charts are not synced when in the same chart area
我在这里回答了类似的问题: 条形图和折线图在同一图表区域中不同步
In the above question the user needed to move the line to the left, but you can do a similar thing for your case.
在上面的问题中,用户需要将线向左移动,但您可以为您的案例做类似的事情。
Use scatter chart for your line chart. Then you need to set the xvalues of the scatter chart to be a bit different than the ones for your column chart. So let's say that your x-axis numbering goes from 1 to 12. Then you should distribute your xvalues for scatter chart from 0.8 to 12.2. That moves the starting point a bit to the left (0.8 instead of 1) and the last point a bit to the right (12.2 instead of 12). The exact number that you should use will depend on your gap and overlap settings of the column chart.
为您的折线图使用散点图。然后,您需要将散点图的 xvalues 设置为与柱形图的 xvalues 略有不同。因此,假设您的 x 轴编号从 1 到 12。那么您应该将散点图的 x 值从 0.8 分配到 12.2。这将起点向左移动一点(0.8 而不是 1),最后一点向右移动一点(12.2 而不是 12)。您应该使用的确切数字取决于柱形图的间隙和重叠设置。