简体   繁体   中英

How To Create A StackedColumn Chart in ASP.NET WebPages C#?

I need to create a StackedColumn chart in my WebPages (C#, Razor) project. Looking around this and other sites, I see something similar has been asked for various alternatives, but not this one.

Let's look at some commonly published code that creates a basic column chart:

var myChart = new Chart(width: 600, height: 400)
    .AddTitle("Chart Title")
    .AddSeries(
        name: "Employee",
        xValue: new[] {  "Peter", "Andrew", "Julie", "Mary", "Dave" },
        yValues: new[] { "2", "6", "4", "5", "3" })
    .Write();

Obviously, I need to add:

chartType: "StackedColumn",

to the AddSeries list, but how do I add further yValues for the values I want to add as the second, third, etc. layers?

Also, could someone direct me to a page that gives me a list of main options & syntax for chart formatting, such as fill colour, background colour, font type/size, etc.?

You can find all chart types here: https://msdn.microsoft.com/en-us/library/dd489233.aspx

Now to get the stacked columns I added two series with chartType: "StackedColumn100" like this:

var chart = new Chart(width: 600, height: 400)
    .AddTitle("Sample")
    .AddSeries(name: "A",
        xValue: new[] {"H", "W", "D"},
        yValues: new[] {"12", "10", "5"},
        chartType:"StackedColumn100")
    .AddSeries(name: "B",
        xValue: new[] {"T", "B", "C"},
        yValues: new[] {"0", "2", "7"},
        chartType: "StackedColumn100")
    .Write();

从上面的代码生成的图表

In my case all values had to sum up to 100%. If they don't in your case, you can use charType: "StackedColumn"

Also you can find pretty much everything on creating and styling charts here www.asp.net/web-pages/overview/data/7-displaying-data-in-a-chart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM