ASP.NET MVC 3 MSChart Error: Only 1 Y values can be set for this data series

前端 未结 4 829
萌比男神i
萌比男神i 2020-12-20 02:34

I\'m attempting to build a stock chart using Microsoft\'s charting library.

I\'m using this code to create the chart in my view:

@{
    System.Web.H         


        
4条回答
  •  心在旅途
    2020-12-20 03:00

    After dealing with the same issue - only being able to add one value to a series - while trying to build a Stacked Column chart with multiple Y axis values - using the Web.Helper.Chart class.

    I did not find the one answer anywhere on MSDN or any other forum including StackOverflow. Turns out - it is quite simple: You can add more than one series with the .AddSeries method.

    In other words, in plain English, call the .AddSeries method once for each series you want to add to the chart.

    This example was used to report daily inventory which is measured in tons, as it would be at a steel plant - production measured in tons of steel in inventory.

            new Chart(1000, 500, ChartTheme.Blue)
                .AddTitle("Inventory")
    
                .AddSeries(name: "A",
                        chartType: "StackedColumn",
                        xValue: intDays,
                        yValues: dblTons_A)
    
                .AddSeries(name: "B",
                        chartType: "StackedColumn",
                        xValue: intDays,
                        yValues: dblTons_B)
    
                .AddSeries(name: "C",
                        chartType: "StackedColumn",
                        xValue: intDays,
                        yValues: dblTons_C)
    
                .AddSeries(name: "D",
                        chartType: "StackedColumn",
                        xValue: intDays,
                        yValues: dblTons_D)
    
                .Write("png");
    

提交回复
热议问题