Asp.net 从C语言绘制SVG#

Asp.net 从C语言绘制SVG#,asp.net,user-controls,svg,Asp.net,User Controls,Svg,我想创建一个由一个div组成的UserControl。div中有许多SVG渲染框。将根据数据确定多少个框及其相对位置 数据将以类框列表的形式显示,其中框如下所示: public class SVGBox { public int x { get; set; } // x coordinate of a corner public int y { get; set; } // x coordinate of same corner public int l { ge

我想创建一个由一个div组成的UserControl。div中有许多SVG渲染框。将根据数据确定多少个框及其相对位置

数据将以类框列表的形式显示,其中框如下所示:

 public class SVGBox
 {
    public int x { get; set; }  // x coordinate of a corner
    public int y { get; set; }  // x coordinate of same corner
    public int l { get; set; }  // length
    public int h { get; set; }  // height
    public string Color { get; set; }
    public string text { get; set; }
    public string uniqueKey { get; set; }

    public SVGBox (int X, int Y, int H, int W, string Text, string Key )
    {
        x = X;
        y = Y;
        h = H;
        w = W;
        text = Text;
        uniqueKey = Key;
    }
 }  

我在“Net”上找到了一个从C#呈现SVG的示例,但它涉及到在DOCTYPE中使用特定引用写出整个HTML页面。如何在用户控件中执行此操作?

好的,一旦正确启动,还不错

在ascx中,我只是添加了一个asp:Literal。下面是隐藏的代码:

public partial class Controls_SVGTest : System.Web.UI.UserControl
{
    public int Height { get; set; }
    public int Width { get; set; }
    public List<SVGBox> data { get; set; }

    const string HeaderText = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <svg xmlns=\"http://www.w3.org/2000/svg\" " +
                                "xmlns:xlink=\"http://www.w3.org/1999/xlink\" height=\"{0}\" width=\"{1}\" >";

    const string BoxSVG = "<rect x=\"{0}\" y=\"{1}\" height=\"{2}\" width=\"{3}\" rx=\"2\" fill=\"{4}\" stroke=\"#707070\" />";
    const string Footer = "</svg>";


    protected void Page_Load(object sender, EventArgs e)
    {
        LoadSVG();
    }

    public void LoadSVG()
    {
        Literal1.Text = String.Format(HeaderText, Height.ToString(), Width.ToString());
        foreach (SVGBox s in data)
        {
            Literal1.Text += String.Format(BoxSVG, s.x, s.y, s.h, s.w, s.Color);
        }
        Literal1.Text += Footer;
    }

}
public分部类控件\u SVGTest:System.Web.UI.UserControl
{
公共整数高度{get;set;}
公共整数宽度{get;set;}
公共列表数据{get;set;}
常量字符串HeaderText=“”;
常量字符串BoxSVG=“”;
常量字符串页脚=”;
受保护的无效页面加载(对象发送方、事件参数e)
{
LoadSVG();
}
公共void LoadSVG()
{
Literal1.Text=String.Format(HeaderText,Height.ToString(),Width.ToString());
foreach(数据中的SVGBox s)
{
Literal1.Text+=String.Format(BoxSVG、s.x、s.y、s.h、s.w、s.Color);
}
Literal1.Text+=页脚;
}
}

如果可能的话,我建议尝试使用Html5和JavaScript。我认为使用Html5时,框不是单独的元素。在我画完这个之后的下一步是让OnClick用唯一的键做一些事情。有什么理由支持Html5?