C#Echart的前后端传值

前端JS

<Html>
<style type="text/css">
        .chart {
            width: 470px;
            height: 300px;
            border: dashed 0.1px lightgray;
            float: left;
        }
</style>
<script type="text/javascript" src="Scripts/echarts.min.js"></script>
<script type="text/javascript" src="Scripts/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
$.ajaxSetup({ cache: false })//解决缓存问题导致的chart数据不更新
window.onload = function () {
            Test();            
        }

function Test() {
            var chart = echarts.init(document.getElementById("chart_id", "light"));


            chart.showLoading();
            $.get(
                'Test.ashx',
                {
                    
                    id:"123456"
                },
                function (data) {
                    chart.hideLoading();
                   
                    //var obj = eval(data);
                    var Y = data.split('-')[0];
                    var N = data.split('-')[1];

                    chart.setOption(
                        {
                            title: {
                                text: 'Chart 标题',
                                
                                x: 'center',
                                y: 'bottom'
                            },

                            tooltip: {  //提示框
                                trigger: 'item'
                            },
                            legend: {   //图形解释组件配置
                                orient: 'vertical',
                                left: 'left'
                            },
                            series: [
                                {
                                    name: 'series name',
                                    type: 'pie', //chart类型
                                    radius: '50%',
                                    data: [
                                       
                                        { value: Y, name: '参加' },
                                         { value: N, name: '未参加' }

                                    ],
                                    label: {
                                        normal: {//Label格式化 加%百分号
                                            show: true,
                                            formatter: '{b}:{c}人({d}%)'
                                        }
                                    }
                                    ,
                                    emphasis: {//透明度设置
                                        itemStyle: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    },
                                    itemStyle: {
                                        normal: {    //柱状图颜色自定义
                                            color: function (params) {
                                                var colorList = [ 'deepskyblue','lightgray'];
                                                return colorList[params.dataIndex]
                                            }

                                        }
                                    }
                                }
                                
                            ]
                        }

                    );



                }
            );



        }
</script>
<body>
<div class="chart" id="chart_id"></div>
</body>
</Html>

后端Test.ashx

using System.Web;
using System.Data;
public class CrossTrainingAjax : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
            
        string ID = context.Request["id"].Trim().ToString();
        //ID 获取JS传过来的ID号
        string Y="30";
        string N = "70";
        context.Response.Write(Y+"-"+N);//返回值


    }

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值