报表静态代码

来源:互联网 发布:阿里云学生机怎么抢 编辑:程序博客网 时间:2024/05/20 06:27

页面前台

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Charts1.aspx.cs" Inherits="TextExt.Charts1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>FusionCharts v3 Documentation</title>
    <link href="Contents/Style.css" rel="stylesheet" type="text/css" />

    <script src="JSClass/FusionCharts.js" type="text/javascript"></script>

</head>
<body>
    <form runat="server">
    <div>
        <asp:Label ID="lblTopInfo" Font-Size="Large" Font-Bold="true" Text="各率分布图" runat="server"></asp:Label>
    </div>
    </form>
     <%=GetProductChartHtml()%>
</body>
</html>
页面后台

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace TextExt
{
    public partial class Charts1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public string GetProductChartHtml()
        {
            string xmlDataYear = "<chart caption='优率直方图' numberSuffix='%25' XAxisName='Year' subcaption='" + "" + "' showValues='1' yAxisMaxValue='100' yAxisName='百分比' rotateyaxisname='0' baseFontSize='12'>";
            xmlDataYear += FusionCharts.GetHistogramData();
            xmlDataYear += "<styles><definition><style type='font' color='555555' name='CaptionFont' size='16' /><style type='font' name='SubCaptionFont' bold='0' size='12' /></definition><application><apply toObject='caption' styles='CaptionFont' /><apply toObject='SubCaption' styles='SubCaptionFont' /></application></styles>";
            xmlDataYear += "</chart>";
            return FusionCharts.RenderChart("Charts/DragColumn2D.swf", "", xmlDataYear, "SalesByYear", "550", "380", false, true);
        }
    }
    public class FusionCharts
    {
        public static string GetHistogramData()
        {
            StringBuilder xmlData = new StringBuilder();

            StringBuilder categories = new StringBuilder();
            StringBuilder strAmtDS = new StringBuilder();

            categories.Append("<categories>");
            categories.Append("<categorie label='计算机应用200901班'/>");
            categories.Append("<categorie label='计算机应用200902班'/>");
            categories.Append("<categories/>");

            strAmtDS.Append("<dataset seriesname='优率'>");
            strAmtDS.Append("<set value='12'/>");
            strAmtDS.Append("<set value='20'/>");
            strAmtDS.Append("<dataset/>");

            xmlData.Append(categories);
            xmlData.Append(strAmtDS);

            return xmlData.ToString();
        }
        public static string RenderChart(string chartSWF, string strURL, string strXML, string chartId,
            string chartWidth, string chartHeight, bool debugMode, bool registerWithJS)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendFormat("<!-- START Script Block for Chart {0} -->" + Environment.NewLine, chartId);
            builder.AppendFormat("<div id='{0}Div' align='center'>" + Environment.NewLine, chartId);
            builder.Append("Chart." + Environment.NewLine);
            builder.Append("</div>" + Environment.NewLine);
            builder.Append("<script type=/"text/javascript/">" + Environment.NewLine);
            builder.AppendFormat("var chart_{0} = new FusionCharts(/"{1}/", /"{0}/", /"{2}/", /"{3}/", /"{4}/", /"{5}/");" + Environment.NewLine, chartId, chartSWF, chartWidth, chartHeight, boolToNum(debugMode), boolToNum(registerWithJS));
            if (strXML.Length == 0)
            {
                builder.AppendFormat("chart_{0}.setDataURL(/"{1}/");" + Environment.NewLine, chartId, strURL);
            }
            else
            {
                builder.Append("chart_" + chartId + ".setDataXML(/"" + strXML + "/");" + Environment.NewLine);
            }


            builder.AppendFormat("chart_{0}.render(/"{1}Div/");" + Environment.NewLine, chartId, chartId);
            builder.Append("</script>" + Environment.NewLine);
            builder.AppendFormat("<!-- END Script Block for Chart {0} -->" + Environment.NewLine, chartId);
            return builder.ToString();
        }
        private static int boolToNum(bool value)
        {
            return value ? 1 : 0;
        }
    }
}

原创粉丝点击