chart

/** 1. 功能:统计指定时间范围的用户在线时间
 *  2. 作者:龚义
 *  3. 创建日期:2009-4-29
 *  4. 最后修改日期:2009-4-29
**/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using InfoSoftGlobal;

public partial class ReportOrder : System.Web.UI.Page
{
    string connectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    private SqlConnection GetSqlConnection()
    {
        SqlConnection conn = new SqlConnection(connectionString);
        return conn;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.beginDate.Value = this.endDate.Value = DateTime.Now.ToString("yyyy-MM-dd");
            this.beginTime.Value = "00:00";
            this.endTime.Value = DateTime.Now.ToString("HH:mm");
        }


    }


    protected DataTable GetOrderDataTable()
    {
        string begin = beginDate.Value + " " + beginTime.Value;
        string end = endDate.Value + " " + endTime.Value;
        DataTable dt = new DataTable();
        string str = "select substring(convert(varchar(13),ordereddate,120),12,2) as hour,count(*) ordercount from t_payorder where ordereddate           >='" + begin + "' and ordereddate <'" + end + "' and orderstatus=1 group by substring(convert(varchar(13),ordereddate,120),12,2) order by hour";
        using (SqlConnection conn = GetSqlConnection())
        {
            SqlCommand cmd = new SqlCommand(str, conn);
            cmd.CommandText = str;
            SqlDataAdapter apt = new SqlDataAdapter(cmd);
            apt.Fill(dt);
            dt.TableName = "table";
            cmd.Dispose();
            conn.Close();
        }

        return dt;

    }

 


    public string CreateChart()
    {
        DataTable dt = new DataTable();
        dt = GetOrderDataTable();

        string[,] array = new string[dt.Rows.Count, 2];


        for (int i = 0; i < dt.Rows.Count; i++)
        {
            for (int j = 0; j < 2; j++)
            {
                array[i, j] = dt.Rows[i][j].ToString();
            }
        }


        string strXML, strCategories, strDataRev, strDataQty;

 

        strXML = "<graph caption='订单走势图' PYAxisName='Revenue' SYAxisName='Quantity (in Units)' numberPrefix='笔' formatNumberScale='0' showValues='0' decimalPrecision='0' anchorSides='14' anchorRadius='3' anchorBorderColor='FF8000'>";


        strCategories = "<categories>";


        strDataRev = "<dataset seriesName='24小时' color='AFD8F8' >";
        strDataQty = "<dataset seriesName='订单数量' parentYAxis='S' color='FF8000' >";

 

        for (int k = 0; k < dt.Rows.Count; k++)
        {

            strCategories += "<category name='" + array[k, 0] + "' />";
            strDataRev += "<set value='" + array[k, 1] + "' />";
            strDataQty += "<set value='" + array[k, 1] + "' />";
        }


        strCategories += "</categories>";


        //关闭<dataset>要素
        strDataRev += "</dataset>";
        strDataQty += "</dataset>";


        //组装现在整个的XML
        strXML += strCategories + strDataRev + strDataQty + "</graph>";

        //创建图表-质谱柱线组合三维图的数据载于strXML
        return FusionCharts.RenderChart("FusionCharts/FCF_MSColumn3DLineDY.swf", "", strXML, "", "780", "330", false, false);

    }

 

 


}

posted @ 2010-04-14 22:48  paymob  阅读(327)  评论(0编辑  收藏  举报