ECharts 在 .net 中实现动态加载数据 柱图

前台

后台

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using 12OA.DB.Table;

namespace 12OA.JMJKGL.XQJKZK
{
    /// 
    /// SWSMZB_Service 的摘要说明
    /// 
    public class SWSMZB_Service : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string Sys_type = context.Request["sys_type"];
            if (Sys_type == "setChart2")
            {
                json = SetChart2();
            }
            context.Response.ContentType = "text/plain";
            context.Response.Write(json);
            context.Response.End();
        }

        public string SetChart2()
        {
            string cmd = "";
            string sql = @"select jbmc,sws from tbl_swyy_Info where 1=1  ";
             cmd = " and bgrq='" + year1 + "' and jbmc like '%小计' and sws>1  order by sws desc";
           //使用DataTable 保存数据
            DataTable dt = FrmBase.GetDataTable_Select(sql);

            string data_Fl = "";
            string data = "";
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                data_Fl += "\"" + dt.Rows[i]["jbmc"].ToString() + "\",";
                data += " { \"value\": " + dt.Rows[i]["sws"] + ", \"name\": \"" + dt.Rows[i]["jbmc"].ToString() + "\" },";

            }
            return "{\"legend_data\":[" + data_Fl.TrimEnd(',') + "]," + "\"series_data\":[" + data.TrimEnd(',') + "] }";
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
最终实现的效果
ECharts 在 .net 中实现动态加载数据 柱图_第1张图片



你可能感兴趣的:(.NET开发)