ala*_*ala 10 asp.net charts colors razor asp.net-mvc-3
我正在使用
System.Web.Helpers.Chart
在我的MVC3应用程序中显示图表.
@{
var myChart = new Chart(width: 600, height: 400)
.AddTitle("Resource Utilization in Projects in Week 1")
.AddSeries(
name: "Project1",
chartType: "StackedColumn",
xValue: new[] { "W1", "W2", "W3", "W4", "W5" },
yValues: new[] { 80, 60, 40, 20, 10}
)
.AddSeries(
name: "Project2",
chartType: "StackedColumn",
xValue: new[] { "W1", "W2", "W3", "W4", "W5" },
yValues: new[] { 10, 10, 0, 10, 10 }
)
.AddSeries(
name: "Available",
chartType: "StackedColumn",
xValue: new[] { "W1", "W2", "W3", "W4", "W5" },
yValues: new[] { "10", "30", "50", "70", "80" }
)
.AddLegend();
myChart.Write();
}
Run Code Online (Sandbox Code Playgroud)
然而,系列的颜色是由图表上有多少系列随机选取的.有谁知道如何设置某些系列的特定颜色?
我在网上找到了用于设置颜色的图表样本,但他们正在使用命名空间
System.Web.UI.DataVisualization.Charting
Dan*_*eny 10
如果要自定义图表,则需要创建ChartTheme.不幸的是,这些看起来有点hacky ......
例如.尝试设置这样的主题:
var myChart = new Chart(width: 600, height: 400, theme: ChartTheme.Green)
Run Code Online (Sandbox Code Playgroud)
您会注意到您的图表看起来不同.如果单击ChartTheme.Green并按F12(转到定义),您将看到ChartTheme类中充满了定义图表样式的巨大字符串:
public const string Blue = @"<Chart BackColor=""#D3DFF0"" BackGradientStyle=""TopBottom"" BackSecondaryColor=""White"" BorderColor=""26, 59, 105"" BorderlineDashStyle=""Solid"" BorderWidth=""2"" Palette=""BrightPastel"">
<ChartAreas>
<ChartArea Name=""Default"" _Template_=""All"" BackColor=""64, 165, 191, 228"" BackGradientStyle=""TopBottom"" BackSecondaryColor=""White"" BorderColor=""64, 64, 64, 64"" BorderDashStyle=""Solid"" ShadowColor=""Transparent"" />
</ChartAreas>
<Legends>
<Legend _Template_=""All"" BackColor=""Transparent"" Font=""Trebuchet MS, 8.25pt, style=Bold"" IsTextAutoFit=""False"" />
</Legends>
<BorderSkin SkinStyle=""Emboss"" />
</Chart>";
Run Code Online (Sandbox Code Playgroud)
你可以在这个XML中定制大量的东西(为什么是XML?我不知道!),尽管你使用的图表类型等会影响你可以做的很多事情.你可以在这里找到这里的文档:
http://msdn.microsoft.com/en-us/library/dd456696.aspx
编辑:此链接也可能有用:
新的asp.net图表控件 - 它们将与MVC(最终)一起使用吗?
| 归档时间: |
|
| 查看次数: |
13608 次 |
| 最近记录: |