introductionnbsp;
通过这篇文章中,我试图解释我们如何使用谷歌图表报告在ASP.NET Web应用程序的目的。报告生成是相当普遍的东西,我们需要产生自我解释和良好的用户几乎每一次的报告。 "图像总是比话多说吗?因此,而不是在我们的报告只是显示的数字,我们可以让用户看到图表的图表,它可以帮助用户分析整个数据更迅速和容易。虽然微软本身。NET图表控件,但由谷歌与其他伟大的技术集成。
谷歌有其自己的目的,我们将使用这里图表非常真棒和简单的应用程序。我会请你简短的想法是什么谷歌图表,通过访问以下链接:
简短的东西下来,让我们看看一个例子。这可能会给你一个更好地了解谷歌图表。要使用"谷歌图表生成图表?我们需要通过适当的参数。
访问以下链接:{A}
在图表中,可以清楚地看到图表标题为"收回款项???如果你看到thenbsp; URL仔细,你会发现这个名字已被URL中传递,同样类似的图表类型的其他细节,轴,绘制图表的数据等,都是通过唯一的URL 。
现在让我们通过的所有参数,我们需要传递,以获得所需的图表。参数描述CHT图表类型。谷歌提供了几十种不同的图表类型,包括折线图,条形图,饼图,和其他周围。图表的大小。此值表示为CHS = WIDTHxHEIGHT,宽度和高度的像素宽度和高度来绘制图表的数量。例如,CHS = 250x100。最大的高度和宽度为1000像素,与产品的高度和宽度不能超过30万像素。chtt图表标题。冠心病
图表中的数据。使用此参数时,你必须指定的数据格式。谷歌图表API允许不同的数据编码。使用最简单的文字编码,是由字母T表示。经过编码,放置一个冒号(:),然后一个数据点值的逗号分隔的列表。默认的文字编码需要数据点的浮动点值之间的零(0.0)和一个100(100.0)。要正确扩展的数据,每个数据点转换成一个最大的数据点的百分比。 ERGO,最大的价值为100.0,而其他人将被最大的百分比表示???这一半大的最大的,这25%的最大25.0 50.0等等。呈现一个有10个数据点,20日和8图表,你会送:冠心病= T:50,100,40。注意T:这表明,使用文本编码格式的数据。您也可以使用文字编码方法与数据缩放,它允许任何积极或消极的浮点数的数据点。用这种方法,你必须指定一个缩放参数(CHDS)。在这篇文章中的例子使用默认的文字编码,限制在零和一百之间的所有数据点值。
上述指标仅仅是最基本的,你将需要绘制图表。有更高级的选项,你可以按你的要求使用。
到目前为止,我们只是在讨论谷歌图表。正如你现在有一个想法是什么谷歌图表,我们可以往前走,我们如何才能实现在我们的web应用这些。
你可以参考下面的代码为更好地了解。我所做的是,我用了一个形象的控制和图像的路径是谷歌图表路径。在下面的例子中,我们试图为所选择的选项来生成图表。using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace WebApplication1
{
public partial class graphs : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
int count = 0;
int count1 = 0;
int maxvalue = 0;
float amount = 0;
string[] amounts = null;
string[] months = null;
string query = ?
if ((Convert.ToInt32(to_month.SelectedItem.Value) ?
Convert.ToInt32(from_month.SelectedItem.Value) + 1) > 0)
{
amounts = new string[Convert.ToInt32(to_month.SelectedItem.Value) -
Convert.ToInt32(from_month.SelectedItem.Value) + 1];
months = new string[Convert.ToInt32(to_month.SelectedItem.Value) -
Convert.ToInt32(from_month.SelectedItem.Value) + 1];
query = select * from chart_table where month>=?+
from_month.SelectedItem.Value + ?and month }
StringBuilder chartUrl = new StringBuilder
(http://chart.apis.google.com/chart?chs=500200&chtt=Amount%20Collection?;
string connection =
System.Configuration.ConfigurationManager.ConnectionStrings
["ApplicationServices"].ConnectionString;
SqlConnection con = new SqlConnection(connection);
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
maxvalue = Convert.ToInt32(ds.Tables[0].Rows[0][1].ToString());
while (count1 {
if (maxvalue < Convert.ToInt32(ds.Tables[0].Rows[count1][1].ToString()))
{
maxvalue = Convert.ToInt32(ds.Tables[0].Rows[count1][1].ToString());
}
count1++;
}
chartUrl.Append(?amp;chxt=x,y?;
chartUrl.AppendFormat(?amp;chxr=1,0,{0}? maxvalue.ToString(??));
chartUrl.AppendFormat(?amp;cht={0}? Server.UrlEncode
(chart_type.SelectedValue));
while (count{
amount = (Convert.ToInt32(ds.Tables[0].Rows
[count][1].ToString()) * 100) / maxvalue;
amounts[count] = amount.ToString();
months[count] = ds.Tables[0].Rows[count][2].ToString();
count++;
}
chartUrl.AppendFormat(?amp;chxl=0