asp.net-mvc应用程序中的辅助Y轴

时间:2014-04-22 16:24:55

标签: c# asp.net-mvc-4 mschart

我正在asp.net-mvc4应用程序中创建图表。之前我在图表的左侧只有一个y轴,但现在我想在图表的右侧添加另一个y轴。我的主要y-axis代码是

public ActionResult PreviewChart(long id = 0, string Kanal = "")
    {
        ChartData returnValue = new ChartData();

        if (id != 0 & Kanal != "")
        {
            returnValue = SearchRepository.FillChart(id, Kanal);
        }

        var c = new Chart(width: 700, height: 420)
           .AddTitle(returnValue.Name)

           .AddSeries("Default", markerStep: 4, chartType: "Line", xValue:   
               returnValue.xData, yValues: returnValue.yData)
           .SetXAxis(returnValue.xUnit)
           .SetYAxis(returnValue.yUnit)
           .GetBytes("png");


      return File(c, "image/png");


    }

在视图中的代码是,Messungen是控制器的名称

<td width = "50%">
  <p><img src = "@Url.Action("PreviewChart", "Messungen", new { id = Model.ID, Kanal = ViewBag.Kanal }, null)"  /></p>
</td>

现在我已经编辑了第二个y-axis的代码。我把随机值放在这里只是为了测试,我没有从数据服务器获取。

public ActionResult PreviewChart(long id = 0, string Kanal = "")
    {


        System.Windows.Forms.DataVisualization.Charting.Chart chart1 = new System.Windows.Forms.DataVisualization.Charting.Chart();

        var lines = new Series("lines");
        lines.ChartType = SeriesChartType.Line;
        lines.Points.Add(new DataPoint(1, 20));
        lines.Points.Add(new DataPoint(2, 30));
        lines.Points.Add(new DataPoint(3, 34));
        lines.YAxisType = AxisType.Primary;
        chart1.Series.Add(lines);

        var branches = new Series("branches");
        branches.ChartType = SeriesChartType.Line;
        branches.Points.Add(new DataPoint(1, 5));
        branches.Points.Add(new DataPoint(2, 6));
        branches.Points.Add(new DataPoint(3, 8));
        branches.YAxisType = AxisType.Secondary;
        chart1.Series.Add(branches);

        using (var ms = new MemoryStream())
        {
            chart1.SaveImage(ms, ChartImageFormat.Png);
            ms.Seek(0, SeekOrigin.Begin);

            return File(ms.ToArray(), "image/png");
        }

       // return File(c, "image/png");

        //==============================================

        //==============================================

    }

问题是应用程序确实显示了情节。我没有对控制器的视图做任何改变。

0 个答案:

没有答案