vba 线系列可以绘制为半实线、半虚线吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15106422/
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
Can Line series be plotted as half solid, half dotted line?
提问by Dinesh Haraveer
In an excel sheet contains an chart which is binding the data from another sheet.The chart series are all line series.I need half of the line series as solid line and another half as dotted line.This is can be done manually picking the point changing the line style,this is not the way i needed,the way which i need is from vba code can we do like half line with solid and another with dotted line.
在 Excel 工作表中包含一个图表,该图表绑定来自另一个工作表的数据。图表系列都是线系列。我需要线系列的一半作为实线,另一半作为虚线。这可以手动选择点改变线条样式,这不是我需要的方式,我需要的方式来自 vba 代码,我们可以像半线实线和虚线一样。
The above image i need to do this from vba code.I have search my site and applied the solutions provided but those are applying.Any solution provided is much appreciated.
上图我需要从 vba 代码中执行此操作。我已经搜索了我的网站并应用了提供的解决方案,但这些解决方案正在应用中。非常感谢提供的任何解决方案。
采纳答案by JustinJDavies
The short answer is no.
简短的回答是否定的。
The longer more useful answer is that you must split the series into two parts as this cannot be done for a single series. The line is a single object belonging to the SeriesCollection
object under it's formatting properties, as demonstrated by the very hacky code, which serves to demonstrate the underlying object model:
更长更有用的答案是您必须将系列分成两部分,因为这不能用于单个系列。该行是属于SeriesCollection
其格式属性下的对象的单个对象,如非常hacky的代码所示,用于演示底层对象模型:
Sub editChart()
Dim cO As Chart
Set cO = ActiveChart
Dim s As Series
Set s = cO.SeriesCollection(1)
s.Format.Line.DashStyle = msoLineDash
Set s = cO.SeriesCollection(2)
s.Format.Line.DashStyle = msoLineSolid
End Sub
You may be confused with custom formatting for Points
, of which there may be many attached to a SeriesCollection
, as these can be individually formatted.
您可能会对 的自定义格式感到困惑Points
,其中可能有许多附加到SeriesCollection
,因为它们可以单独格式化。
Note that if you want the lines to join up they must share one data point (rather than the first Series
stopping at point n
and the second Series
beginning at point n+1
).
请注意,如果您希望线条连接起来,它们必须共享一个数据点(而不是第一个Series
在点处停止,n
第二个Series
在点处开始n+1
)。
回答by user2696636
You should be able to do it like this:
你应该可以这样做:
ActiveChart.SeriesCollection(1).ChartType = xlLineStacked
ActiveChart.SeriesCollection(1).Points(14).Format.Line.DashStyle = 3
So in my case, the 1st data series is a plain line, but the last point (14 in this graph) has its format changed to dashes.
因此,在我的情况下,第一个数据系列是一条普通线,但最后一个点(此图中的 14)的格式已更改为破折号。