使用 DotNet HighCharts dll 在代码隐藏中制作图表

发布于 2025-01-04 10:59:37 字数 2320 浏览 0 评论 0原文

我刚刚发现了 DotNetHighCharts dll 来制作图表: http://dotnethighcharts.codeplex.com/

我将 dll 添加到我的项目中,并放置了示例代码以获取我的 Page_Load 事件中的一个饼图(我现在没有使用 MVC,所以我只是使用了演示控制器中的内容)

    protected void Page_Load(object sender, EventArgs e)
    {
        Highcharts chart = new Highcharts("chart")
        .InitChart(new Chart { PlotShadow = false })
        .SetTitle(new Title { Text = "Browser market shares at a specific website, 2010" })
        .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }" })
        .SetPlotOptions(new PlotOptions
        {
            Pie = new PlotOptionsPie
            {
                AllowPointSelect = true,
                Cursor = Cursors.Pointer,
                DataLabels = new PlotOptionsPieDataLabels
                {
                    Color = ColorTranslator.FromHtml("#000000"),
                    ConnectorColor = ColorTranslator.FromHtml("#000000"),
                    Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }"
                }
            }
        })
        .SetSeries(new Series
        {
            Type = ChartTypes.Pie,
            Name = "Browser share",
            Data = new Data(new object[]
                                       {
                                           new object[] { "Firefox", 45.0 },
                                           new object[] { "IE", 26.8 },
                                           new DotNet.Highcharts.Options.Point
                                           {
                                               Name = "Chrome",
                                               Y = 12.8,
                                               Sliced = true,
                                               Selected = true
                                           },
                                           new object[] { "Safari", 8.5 },
                                           new object[] { "Opera", 6.2 },
                                           new object[] { "Others", 0.7 }
                                       })
        });

    }
}

}

问题是北移出现在我的页面中 有什么要补充的吗? 提前致谢

I just discovered the DotNetHighCharts dll to make charts:
http://dotnethighcharts.codeplex.com/

I added the dll to my project and put a sample code to get a pie in my Page_Load event ( i'm not working with MVC right now, so i just took what was in the controller of the demo )

    protected void Page_Load(object sender, EventArgs e)
    {
        Highcharts chart = new Highcharts("chart")
        .InitChart(new Chart { PlotShadow = false })
        .SetTitle(new Title { Text = "Browser market shares at a specific website, 2010" })
        .SetTooltip(new Tooltip { Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }" })
        .SetPlotOptions(new PlotOptions
        {
            Pie = new PlotOptionsPie
            {
                AllowPointSelect = true,
                Cursor = Cursors.Pointer,
                DataLabels = new PlotOptionsPieDataLabels
                {
                    Color = ColorTranslator.FromHtml("#000000"),
                    ConnectorColor = ColorTranslator.FromHtml("#000000"),
                    Formatter = "function() { return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %'; }"
                }
            }
        })
        .SetSeries(new Series
        {
            Type = ChartTypes.Pie,
            Name = "Browser share",
            Data = new Data(new object[]
                                       {
                                           new object[] { "Firefox", 45.0 },
                                           new object[] { "IE", 26.8 },
                                           new DotNet.Highcharts.Options.Point
                                           {
                                               Name = "Chrome",
                                               Y = 12.8,
                                               Sliced = true,
                                               Selected = true
                                           },
                                           new object[] { "Safari", 8.5 },
                                           new object[] { "Opera", 6.2 },
                                           new object[] { "Others", 0.7 }
                                       })
        });

    }
}

}

the problem is that northing appears in my page with this
Is there anything to add ?
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

流星番茄 2025-01-11 10:59:37

我不熟悉这个库,但所有这些代码似乎都是在后面的代码中创建一个对象。您需要执行一些操作才能将其呈现到页面中。

看看他们的代码后面的示例代码,有一行“

ltrChart.Text = chart.ToHtmlString();

This is the bit you miss”。您需要在图表对象上调用 ToHtmlString() 并将该字符串分配给页面中的文字或占位符。

要创建文字,只需在页面上的某个位置添加此代码......

<asp:Literal ID="ltrChart" runat="server"></asp:Literal>

,您的图表就会出现在那里。

I'm not familiar with the library but all this code appears to be doing is creating an object in the code behind. You will need to do something to cause this to render in to the page.

Looking at their example code behind code there is a line

ltrChart.Text = chart.ToHtmlString();

This is the bit you are missing. You need to call ToHtmlString() on your chart object and assign this string to a literal or placeholder in the page.

To create the literal just add this code somewhere on the page....

<asp:Literal ID="ltrChart" runat="server"></asp:Literal>

...and your chart should appear there.

漫雪独思 2025-01-11 10:59:37

根据他们的示例,您需要将 HTML 发送到客户端,并使用“

Response.Write(result);

It Works to me, while it prints it at the top of the screen and I 希望我可以设置它的位置”这一行。

Based on their example you need to send the HTML to the client side with the line

Response.Write(result);

It works to me, though it prints it at the top of the screen and I wish I could set the position for it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文