c# - 如何在图表上设置系列颜色?

标签 c# asp.net-mvc-3 charts

我正在使用 System.Web.Helpers.Chart

Namespace:  System.Web.Helpers
Assembly:   System.Web.Helpers (in System.Web.Helpers.dll)

有没有办法设置系列颜色?这种浅黄色很难辨认...

temperature over time

图表代码:

new Chart(width: w, height: h, theme: ChartTheme.Blue)
    .AddLegend("Legenda")
    .SetYAxis(min: 0, max: 30)
    .AddSeries(
        name: "Temperatura",
        chartType: DataVisualization.SeriesChartType.FastLine.ToString(),
        xValue: dataRange.Select(d => d.RecordDate.ToString("dd/MM")).ToList(),
        yValues: dataRange.Select(d => d.TemperatureAvg).ToList())
    .AddSeries(
        name: "Ponto de orvalho",
        chartType: DataVisualization.SeriesChartType.FastLine.ToString(),
        xValue: dataRange.Select(d => d.RecordDate.ToString("dd/MM")).ToList(),
        yValues: dataRange.Select(d => d.DewAvg).ToList())
    .Write();

最佳答案

您需要为系列设置主题并定义颜色。如下所示:

string customSeriesColor = @"<Chart BorderlineDashStyle=""Solid"" BorderWidth=""1"">

    <ChartAreas>
         <ChartArea Name=""Default"" _Template_=""All""> 
      <AxisY Interval=""50""> 
        <LabelStyle Font=""Verdana, 70px"" /> 
      </AxisY> 
<AxisX Interval=""200""> 
        <LabelStyle Font=""Verdana, 70px"" /> 
      </AxisX>
    </ChartArea>
    </ChartAreas>
 <Titles>
        <Title Font=""Times New Roman, 16pt, style=Bold"" Name=""Title"" Text=""Costs"">
        </Title>
    </Titles>
  <Series>
     <Series Name=""Temperatura"" BorderWidth=""1"" Color=""Red"">
     </Series>
<Series Name=""Ponto de orvalho"" BorderWidth=""1"" Color=""Blue"">
     </Series>

   </Series>
    <Legends>
        <Legend _Template_=""All"" BackColor=""Transparent"" Font=""Trebuchet MS, 12.25pt, style=Bold"" IsTextAutoFit=""False"" />
    </Legends>
    <BorderSkin SkinStyle=""Emboss"" />
  </Chart>";

您的图表代码如下:

new Chart(width: w, height: h, theme: customSeriesColor)

关于c# - 如何在图表上设置系列颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6499991/

相关文章:

c# - .NET Core 单元测试 - 模拟 IOptions<T>

c# - asp.net JavascriptSerializer 可以将空值编码为空字符串吗?

javascript - 图表 js 悬停时显示旧图表数据

c# - 格式化特定数据点的 Microsoft Chart Control X 轴标签

c# - 在 react 性管道中管理状态

c# - 如何在单元测试中从 Automapper 模拟 IValueResolver 的依赖关系

asp.net-mvc - 将 MVC Content 文件夹放入 Area

c# - 通过单个字符串搜索 Linkedin?

reporting-services - 更改 SSRS 中的图例形状

c# - 在 C# 中使用 if (!bool) 与 if (bool == false)