在.net用户控件(asp:向导)中返回asp.net图表

时间:2013-06-11 16:07:09

标签: asp.net charts

我整个下午试图在谷歌搜索一些相关内容无济于事,所以我希望你们中的一些人可以帮助我。

我正在使用一个asp:向导用户控件,它从用户收集各种值,并以表格的形式显示在最终的“结果页面”上。

我创建了一个单独的“GraphEngine”类,它使用Bool参数决定要创建哪个图表类型(行/堆积列)

//T13 is selection of line/stacked column chart type.
public Chart GetChart(bool T13)
    {

        Chart chart = new Chart();

        //define some shared properties no matter which ChartType.
        chart.Width = 900;
        chart.Height = 500;
        chart.ChartAreas.Add("ChartArea1");
        chart.Series.Add("Costs");
        chart.Series.Add("Stages");
        chart.Legends.Add("Legend1");

        if (T13 == true)
        {
            //chart = charttype1 and add values from Dictionary<string, bool>
        }
        else
        {
            //chart = charttype2 and add values..............
        }
        return chart;

    }

然后我在Wizard Control的最后一步(acsx.cs文件)中调用GetChart。

GraphEngine GE = new GraphEngine(GraphData);
System.Web.UI.DataVisualization.Charting.Chart Chart =  GE.GetChart(t13);
//What should I be saying here to render Chart as "Chart" rather than literal
LiteralGraph.Text =  GE.GetChart(getSetGraphData, t13).ToString();

我不确定如何渲染图表

ID为“Chart”的图表位于.ascx页面上 - 不应该只填充来自GE.GetChart的返回信息(t13); ?

注意:如果我在用户控制向导步骤中创建/定义所有图表值和轴等,它返回正常但我需要分离图形生成,因为ascx.cs中有许多代码行(验证等)文件,所以我想分开我的150多条线。这可能是“正确”的做事方式吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

如果您要返回实际的图表控件 - 您需要将其添加到表单上的控件集合中。例如,创建LiteralGraph而不是Literal - 一个Panel,然后你可以这样做:

LiteralGraph.Controls.Add(GE.GetChart(getSetGraphData, t13));