热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

从图表系列获得主题颜色信息。-GettingThemeColorinfofromChartSeries

Ihaveachartseriesusingonecolor(itcanbeanmsoThemeColorAccent<#>oranyother)fort

I have a chart series using one color (it can be an msoThemeColorAccent<#> or any other) for the marker line, another color for the marker fill (it can be an msoThemeColorAccent<#>, lighter x%, or any other), and no lines. I want to determine if the chart series is using an msoThemeColorAccent<#> for the marker line, an msoThemeColorAccent<#>, lighter x%, for the marker fill, and if so which specific accent color in each case.

我有一个图表系列,使用一种颜色(可以是msoThemeColorAccent<#>或任何其他颜色)作为标记线,使用另一种颜色作为标记填充(可以是msoThemeColorAccent<#>,打火机x%或任何其他颜色),没有线。我想确定这个图表系列是否使用msoThemeColorAccent<#>作为标记线,使用msoThemeColorAccent<#>,更轻的x%作为标记填充,如果使用的话,每种情况下具体的重音颜色。

I tried returning some properties of a series, with no luck. At a breakpoint during execution of a Sub that has a reference sr to a chart series (which was, for testing purposes, set to have lines, with its color being the same as marker lines and marker fill, set at Accent1), and inside a With sr construction, I tested in the immediate window:

我试着返回一个系列的一些属性,但运气不佳。在一个断点执行的子老引用图表系列(出于测试目的,设置线,它的颜色是一样的标记线和标记,设置在Accent1),在老建筑,我测试了在立即窗口中:

? .Format.Line.BackColor.ObjectThemeColor, .Format.Line.ForeColor.ObjectThemeColor
0             0
? .Format.Fill.BackColor.ObjectThemeColor, .Format.Fill.ForeColor.ObjectThemeColor
0            -2

I expect to obtain in some way a value of msoThemeColorAccent1 (=5), which is used in my series. Is there any way to do this?

我希望在某种程度上获得msothemecolor1(=5)的值,这在我的系列文章中使用。有什么办法吗?

All the examples that I found used a msoThemeColorIndex for setting a color, none as a value that was read.

我找到的所有示例都使用msoThemeColorIndex来设置颜色,没有一个作为读取的值。

PS: I did not succeed in this first part, with a series with uniform color. I foresee that if I overcome this hurdle, I may still have problems in detecting the correct TintAndShade, or even the accent color in the target case of no line, different marker fill vs. marker line.

PS:我在第一部分中没有成功,因为系列的颜色都是统一的。我预见,如果我克服了这个障碍,我可能仍然在检测正确的丁当达色,甚至在没有线、不同的标记填充和标记线的情况下的重音颜色方面存在问题。

2 个解决方案

#1


2  

So this is interesting. I create a line chart using all defaults, and then I run this procedure:

这是有趣的。我使用所有的默认值创建一个折线图,然后运行这个过程:

enter image description here

Sub getLineCOlors()
Dim cht As Chart
Dim srs As Series
Dim colors As String
Dim pt As Point

Set cht = ActiveSheet.ChartObjects(1).Chart

For Each srs In cht.SeriesCollection
    With srs.Format.Line
    colors = colors & vbCrLf & srs.Name & " : " & _
            .ForeColor.RGB
    End With

Next

Debug.Print "Line Colors", colors

End Sub

The Immediate window then displays:

然后直接窗口显示:

Line Colors   
Series1 : 16777215
Series2 : 16777215
Series3 : 16777215

But this is clearly not the case. It is obvious that they all are different colors. If, instead of .RGB I do .ObjectThemeColor, then I get all 0, which is equally and demonstrably false by observing the chart!

但事实显然并非如此。很明显,它们都是不同的颜色。如果我使用.ObjectThemeColor而不是.RGB,那么我将得到所有的0,通过观察图表,这同样是错误的。

Line Colors   
Series1 : 0
Series2 : 0
Series3 : 0

Now here is where it gets interesting:

有趣的是:

If, after having created the chart I change the series colors (or even leave them unchanged, by assigning to the same ThemeColors), then the function shows valid RGBs:

如果在创建了图表之后,我更改了系列颜色(或者通过分配到相同的主题颜色来保持不变),那么该函数将显示有效的RGBs:

Line Colors   
Series1 : 5066944
Series2 : 12419407
Series3 : 5880731

It is as if Excel (and PowerPoint/etc.) are completely unable to recognize the automatically assigned colors, on Line Charts. Once you assign a color, then it may be able to read the color.

就好像Excel(和PowerPoint等)完全无法识别线形图上自动分配的颜色。一旦你指定了一种颜色,它就可以读取颜色。

NOTE: Line charts are picky, because you don't have a .Fill, but rather a .Format.Line.ForeColor (and .BackColor) and IIRC there are some other quirks, too, like you can select an individual point and change it's fill color, and then that affects the visual appearance of the preceding line segment, etc...

注意:线形图很挑剔,因为您没有. fill,而是. format .Line。ForeColor(和.BackColor)和IIRC也有一些其他的奇怪之处,比如您可以选择一个单独的点并改变它的填充颜色,然后影响前面的线段的视觉外观,等等……

Is this limited to line charts? Perhaps. My past experience says "probably", although I am not in a position to say that this is a bug, it certainly seems to be a bug.

这仅限于线图吗?也许。我过去的经验告诉我“可能”,虽然我不能说这是一个bug,但它确实是一个bug。

If I run a similar procedure on a Column Chart -- again using only the default colors that are automatically assigned,

如果我在列图表上运行类似的过程——同样只使用自动分配的默认颜色,

Sub getCOlumnColors()

Dim cht As Chart
Dim srs As Series
Dim colors As String
Dim pt As Point

Set cht = ActiveSheet.ChartObjects(2).Chart

For Each srs In cht.SeriesCollection

    With srs.Format.Fill
    colors = colors & vbCrLf & srs.Name & " : " & _
            .ForeColor.RGB
    End With

Next

Debug.Print "Column Colors", colors

End Sub

Then I get what appear to be valid RGB values:

然后我得到看似有效的RGB值:

Column Colors 
Series1 : 12419407
Series2 : 5066944
Series3 : 5880731

HOWEVER: It still doesn't recognize a valid ObjectThemeColor. If I change .RGB then this outputs:

然而:它仍然不能识别有效的ObjectThemeColor。如果我改变。rgb,那么输出如下:

Column Colors 
Series1 : 0
Series2 : 0
Series3 : 0

So based on these observations, there is certainly some inability to access the ObjectThemeColor and/or .RGB property of automatically-assigned color formats.

因此,基于这些观察,肯定有一些无法访问ObjectThemeColor和/或. rgb属性的自动分配的颜色格式。

As Tim Williams confirms, this was a bug as far back as 2005 at least as it pertains to the RGB, and probably that bug carried over in to Excel 2007+ with the ObjectThemeColor, etc... It is not likely to be resolved any time soon then, so we need a hack solution :)

正如Tim Williams所证实的那样,这是一个早在2005年就已经存在的bug,至少它与RGB有关,并且很可能是那个bug与ObjectThemeColor一起移植到Excel 2007+中……这个问题不太可能很快得到解决,所以我们需要一个解决方案:

UPDATED SOLUTION

更新的解决方案

Combine the two methods above! Convert each series from line to xlColumnClustered, then query the color property from the .Fill, and then change the series chart type back to its original state. This may be more reliable than trying to exploit the sequential indexing (which will not be reliable at all if the users have re-ordered the series, e.g., such that "Series1" is at index 3, etc.)

结合以上两种方法!将每个系列从行转换为xlcolumnclusters,然后从. fill查询颜色属性,然后将系列图表类型更改为原始状态。这可能比尝试利用顺序索引更可靠(如果用户重新排序了这个系列,比如“Series1”在索引3中,等等)。

Sub getLineColors()
Dim cht As Chart
Dim chtType As Long
Dim srs As Series
Dim colors As String

Set cht = ActiveSheet.ChartObjects(1).Chart

For Each srs In cht.SeriesCollection
    chtType = srs.ChartType
    'Temporarily turn this in to a column chart:
    srs.ChartType = 51
    colors = colors & vbCrLf & srs.Name & " : " & _
            srs.Format.Fill.ForeColor.RGB
    'reset the chart type to its original state:
    srs.ChartType = chtType
Next

Debug.Print "Line Colors", colors

End Sub

credit: David Zemens

信贷:大卫Zemens

#2


1  

It is one of solutions DeerSpotter. But after you change your chart type to some temp ChartType and then changing it back to original one. You are losing some format. For an example, you get second axis after it, what is not always need.

这是一种解决方法。但是在您将图表类型更改为一些临时的ChartType之后,然后将其更改为原始的图表类型。你正在丢失一些格式。例如,你在它之后得到第二个轴,它并不总是需要。

So, when your chart line color set automatically, you can not simply get color index of it. You would always receive 0 or 16777215 - white color. The best solution is to just before you try to change or get your chart line color, to do this little trick with Line.Visible tur off and then trun on. After it you can simply read and chnage your line color.

因此,当你的图表线自动设置颜色时,你不能简单地得到它的颜色索引。你会得到0或16777215 -白色。最好的解决方案是在您尝试更改或获取图表线颜色之前,对线条进行这个小技巧。可以看见,然后继续前进。在它之后,你可以简单地阅读和记录你的线条颜色。

ppSeries.Format.Line.Visible = msoFalse 
ppSeries.Format.Line.Visible = msoTrue

推荐阅读
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • Whatsthedifferencebetweento_aandto_ary?to_a和to_ary有什么区别? ... [详细]
  • 如何在HTML中获取鼠标的当前位置
    本文介绍了在HTML中获取鼠标当前位置的三种方法,分别是相对于屏幕的位置、相对于窗口的位置以及考虑了页面滚动因素的位置。通过这些方法可以准确获取鼠标的坐标信息。 ... [详细]
  • Introduction(简介)Forbeingapowerfulobject-orientedprogramminglanguage,Cisuseda ... [详细]
  • 【爬虫】关于企业信用信息公示系统加速乐最新反爬虫机制
    ( ̄▽ ̄)~又得半夜修仙了,作为一个爬虫小白,花了3天时间写好的程序,才跑了一个月目标网站就更新了,是有点悲催,还是要只有一天的时间重构。升级后网站的层次结构并没有太多变化,表面上 ... [详细]
  • 本博文基于《Amalgamationofproteinsequence,structureandtextualinformationforimprovingprote ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • http:my.oschina.netleejun2005blog136820刚看到群里又有同学在说HTTP协议下的Get请求参数长度是有大小限制的,最大不能超过XX ... [详细]
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • IjustinheritedsomewebpageswhichusesMooTools.IneverusedMooTools.NowIneedtoaddsomef ... [详细]
  • This article discusses the efficiency of using char str[] and char *str and whether there is any reason to prefer one over the other. It explains the difference between the two and provides an example to illustrate their usage. ... [详细]
  • ejava,刘聪dejava
    本文目录一览:1、什么是Java?2、java ... [详细]
  • 本文介绍了利用ARMA模型对平稳非白噪声序列进行建模的步骤及代码实现。首先对观察值序列进行样本自相关系数和样本偏自相关系数的计算,然后根据这些系数的性质选择适当的ARMA模型进行拟合,并估计模型中的位置参数。接着进行模型的有效性检验,如果不通过则重新选择模型再拟合,如果通过则进行模型优化。最后利用拟合模型预测序列的未来走势。文章还介绍了绘制时序图、平稳性检验、白噪声检验、确定ARMA阶数和预测未来走势的代码实现。 ... [详细]
author-avatar
iflbicfb_6114756
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有