【问题标题】:How can I read the Series.Color during runtime when using a ChartColorPalette?使用 ChartColorPalette 时如何在运行时读取 Series.Color?
【发布时间】:2012-03-28 13:46:20
【问题描述】:

我有一个包含多个系列的图表。我正在使用 ChartColorPalette 为每个系列自动设置不同的颜色。

在那一刻,当我创建我的系列时,我想读取颜色以给 dropDownList.listItem 相同的背景颜色。但不幸的是,在那一刻,颜色仍未设置。

系列是否有可能在 ASP.NET 的 Rendering-Event 后期从 ChartColorPalette 中获取颜色定义?

或者我做错了什么?

Chart newChart = new Chart();
newChart.Palette = ChartColorPalette.Bright;

Series newSeries;

foreach (....)
{
   newSeries = new Series();
   newChart.Series.Add(newSeries);

   // no color found :(
   string colorName = newSeries.Color.Name

   // same here
   string colorName = newChart.Series[identifier].Color.Name;

   myDropDownList.Items.FindByValue(identifier).Attributes.Add("style", "background: " + colorName + ";");
}

【问题讨论】:

  • 你的代码中不应该是 newSeries 而不是 Newseries 吗?

标签: c# asp.net mschart


【解决方案1】:

从 Dundas 网站(MS 图表代码的原始来源,自 2018 年 8 月起不再在线提供),您可以强制它手动应用调色板。

newChart.ApplyPaletteColors();
Color thisColor = newChart.Series[identifier].Color;

我认为您需要先添加所有系列,然后在应用调色板并取出颜色以填充下拉列表后循环遍历它们。

【讨论】:

  • 非常感谢!这正是我想要的 =)
  • 链接已失效。
【解决方案2】:

为什么不直接使用 ChartColor Pallette 呢?

foreach(string colorName in Enum.GetNames(typeof(ChartColorPallette))
{
}

【讨论】:

  • 通过这个你得到ChartColorPalette枚举的值,与颜色无关
  • 是的,我只知道调色板的名称,而不是每种颜色的名称。我不确定这是否可能。但即便如此,我认为这也不是一个干净的解决方案。
猜你喜欢
  • 2013-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-09
  • 2016-02-05
  • 1970-01-01
相关资源
最近更新 更多