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

前端 未结 4 827
萌比男神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 02:57

    I was able to work around this issue by building the chart myself, bypassing the helper.

    using (Chart chart = new Chart())
    {
        chart.Width = 600;
        chart.Height = 400;
        chart.RenderType = RenderType.BinaryStreaming;
        chart.Palette = ChartColorPalette.Bright;
    
        chart.ChartAreas.Add("Top");
        chart.ChartAreas.Add("Bottom");
    
        chart.Series.Add("Price");
        chart.Series.Add("Volume");
    
        chart.Series["Price"].ChartArea = "Top";
        chart.Series["Volume"].ChartArea = "Bottom";
    
        chart.Series["Price"].ChartType = SeriesChartType.Stock;
        chart.Series["Volume"].ChartType = SeriesChartType.Column;
    
        for (int x = 0; x < data.Quotes.Count / 2; x++)
        {
            Quote quote = data.Quotes[x];
    
            chart.Series["Price"].Points.AddXY(quote.Date, quote.Open, quote.High, quote.Low, quote.Close);
            chart.Series["Volume"].Points.AddXY(quote.Date, quote.Volume);
        }
    
        using (MemoryStream memStream = new MemoryStream())
        {
            chart.SaveImage(memStream, ChartImageFormat.Jpeg);
    
            return File(memStream.ToArray(), "image/jpeg");
        }
    }
    

    This code is in my controller, and no view exists for it, because it is returning an actual image resource.

提交回复
热议问题