【问题标题】:Return asp.net chart within a .net user control (asp:wizard)在 .net 用户控件中返回 asp.net 图表(asp:wizard)
【发布时间】:2013-06-11 16:07:09
【问题描述】:

我整个下午都在谷歌上搜索了一些相关的东西,但无济于事,所以我希望你们中的一些人能帮助我。

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

我创建了一个单独的“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;

    }

然后我在向导控件(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 多行分开。这大概是“正确”的做事方式吧?

提前致谢。

【问题讨论】:

    标签: asp.net charts


    【解决方案1】:

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

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

    【讨论】:

    • 太好了——谢谢尤里。我知道字面意思是不对的,但我不知道如何纠正它。完美运行。
    猜你喜欢
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多