本文介绍了使用DotNet HighCharts dll将代码中的图表放在后面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现了DotNetHighCharts dll来制作图表:



我将dll添加到我的项目中,并将一个示例代码放在我的Page_Load事件中获得一个饼图(我现在不使用MVC,所以

  protected void Page_Load(object sender,EventArgs e)
{
Highcharts chart = new Highcharts(chart)
.InitChart(新图表{PlotShadow = false})
.SetTitle(新标题{Text =浏览器在特定网站的市场份额,2010})
.SetTooltip(new Tooltip {Formatter =function(){return'< b> + this.point.name +'< / b>:'+ this.percentage +' %';}})
.SetPlotOptions(new PlotOptions
{
Pie = new PlotOptionsPie
{
AllowPointSelect = t rue,
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(新系列
{
类型= ChartTypes.Pie,
Name =浏览器共享,
Data = new Data(new object []
{
new object [] {Firefox,45.0},
new object [] {IE, 26.8},
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}
})
});


$ b $ / code $ / pre>

}



问题在于北行出现在我的页面中,并且
有什么要添加的吗?
在此先感谢

解决方案

我对库并不熟悉,但所有代码似乎都在创建代码背后的一个对象。你将需要做一些事情,使其呈现在页面中。



查看代码后面的示例代码,有一行

  ltrChart.Text = chart.ToHtmlString(); 

这是您错过的位。您需要在图表对象上调用ToHtmlString(),并将该字符串分配给页面中的文字或占位符。



要创建文字,只需将该代码添加到网页....

 < asp:Literal ID =ltrChartrunat =server>< / asp :文字> 

...您的图表应该出现在那里。


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 thisIs there anything to add ?Thanks in advance

解决方案

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.

这篇关于使用DotNet HighCharts dll将代码中的图表放在后面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 09:20