I’m using
System.Web.Helpers.Chart
to display charts in my MVC3 application.
@{
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();
}
However the colors of series are picked randomly by how many series there are on the chart. Does anyone know how to set specific color to certain series?
I found Charting samples online for setting colors, but they are using the namespace
System.Web.UI.DataVisualization.Charting
You need to create a ChartTheme if you want to customise the chart. Unfortuantely these look a little bit hacky…
Eg. try setting a theme like this:
You’ll notice your chart looks different. If you click on
ChartTheme.Greenand press F12 (Go To Definition), you’ll see the ChartTheme class is full of huge strings defining how the charts are styled:There’s a huge amount of stuff you can customise in this XML (why XML? I don’t know!), though the type of chart etc. that you use will influence much of what you can do. You can find the docs for this here:
http://msdn.microsoft.com/en-us/library/dd456696.aspx
Edit: This link may also be useful:
New asp.net charting controls – will they work with MVC (eventually)?