【问题标题】:Changing marker and line colours on an asp.net chart using c#使用 c# 在 asp.net 图表上更改标记和线条颜色
【发布时间】:2015-09-01 13:43:58
【问题描述】:

我在面积图上显示销售额,销售额是过去 12 个月的。所以 X 轴系列标签是月份,Y 轴系列标签是销售额。

我想知道是否可以从某个日期标记标记的更改。我在下面提供了一个示例。所以这是为不同类型的销售绘制的两条线。如果公司的管理层在 2014 年 10 月发生变化,我希望线条和标记在图表结束之前(2015 年 6 月)改变颜色。

我需要能够从后面的代码中更改它。我最好的解决方法是什么?

【问题讨论】:

  • @jstreet 我自己已经回答了这个问题。见下文。
  • @jstreet 我已经编辑了我的答案以包含一个图表示例。希望这可以帮助。谢谢,

标签: c# asp.net charts


【解决方案1】:

我最终使用了一个 for 循环来解决这个问题。

//  If company is selected and is participating
//  Plot the markers as crosses when SP started providing the traffic source
if (clientCompanyParticipating && startDate != DateTime.MinValue)
{
 int monthDifference = 0;

 //  If the Service StartDate is greater than the first date plotted on the chart
 if (startDate > _lastTwelveMonthsStart)
 {
  monthDifference = ((startDate.Year - _lastTwelveMonthsStart.Year) * 12) + startDate.Month - _lastTwelveMonthsStart.Month;
 }

 //  Foreach point specified (i) make the plot marker a cross
 for (int i = monthDifference; i <= 12; i++)
 {
  chtSourceSalesvOverallSalesBreakdown.Series[0].Points[i].MarkerStyle = MarkerStyle.Cross;
  chtSourceSalesvOverallSalesBreakdown.Series[0].Points[i].MarkerSize = 13;

  chtSourceSalesvOverallSalesBreakdown.Series[1].Points[i].MarkerStyle = MarkerStyle.Cross;
  chtSourceSalesvOverallSalesBreakdown.Series[1].Points[i].MarkerSize = 13;
  }
 }

这是我的图表的结果,能够从某个日期开始更改绘图。我会注意到我决定不改变颜色,而是改变标记样式。此示例中的更改发生在 2014 年 10 月以后。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-24
    • 1970-01-01
    • 1970-01-01
    • 2016-09-15
    • 2013-09-08
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    相关资源
    最近更新 更多