_layout.cshtml中的onchnage事件不影响order.shtml(我的查看页面)

时间:2018-08-06 11:20:29

标签: jquery asp.net-mvc-4 layout charts

  

在MVC中,我正在为Dashboard应用程序使用开源图表。我是MVC和Jquery的新手。请参见_layout.cshtml和order.cshtml中的以下代码。

$(document).ready(function () {
         var location = Get_location();
         function Get_location() {
             $.ajax({
                 "type": "GET",
                 "url": "Get_location",
                 "contentType": "application/json; charset=utf-8",
                 "async": false,
                 "cache": false,
                 "dataType": "text",
                 "success": onsuccess,
                 "error": function () {
                     alert('Error loc');
                 }
             });
             SelectElement("location", 'PHA_GU_NRR')



             function onsuccess(data) {
                 var resultJSON = JSON.parse(data);
                 var obj = JSON.parse(resultJSON);
                 var select = document.getElementById("location");
                 $.each(obj, function (i, item) {
                     var option = document.createElement('option');
                     option.text = obj[i].GLO_LOCATION_DESC;
                     option.value = obj[i].GLO_LOCATION_CD;
                     select.add(option, 0);

                 });

             }
         };



         $("#location").change(function () {
             Check_interval();
         });

     });
  

我必须在order.cshtml页面中使用所选的位置值。

$(document).ready(function () {

    var selectedlocation;

    var loc;
    var startd;
    var endd;

    loc = localStorage.getItem("lloc");
    startd = localStorage.getItem("lsdate");
    endd = localStorage.getItem("ledate");

            var stackchartdata = datacollection();
    function datacollection() {
        $("#stackchartforlens").empty();
        $.ajax({
            "type": "GET",
            "url": "GetStackchart_data",
            "contentType": "application/json; charset=utf-8",
            "data": { 'sdate': startd, 'edate': endd, 'loc': loc },
            "async": false,
            "dataType": "json",
            "cache": false,
            "success": function (data) {
                stackchartdata = data;
                //w(stackchartdata)
                return stackchartdata;
            }
        });


        var chart = AmCharts.makeChart("stackchartforlens", {
            "type": "serial",
            "theme": "light",
            "rotate": true,
            "marginBottom": 50,
            "startDuration": 1,
            "graphs": [{

                "fillAlphas": 0.8,
                "lineAlpha": 0.2,
                "type": "column",
                "valueField": "male",
                "title": "Male",
                "labelText": "[[value]]",
                "clustered": false,
                "labelFunction": function (item) {
                    return Math.abs(item.values.value);
                },
                "balloonFunction": function (item) {
                    return item.category + ": " + Math.abs(item.values.value) + "%";
                }
            }, {

                "fillAlphas": 0.8,
                "lineAlpha": 0.2,
                "type": "column",
                "valueField": "female",
                "title": "Female",
                "labelText": "[[value]]",
                "clustered": false,
                "labelFunction": function (item) {
                    return Math.abs(item.values.value);
                },
                "balloonFunction": function (item) {
                    return item.category + ": " + Math.abs(item.values.value) + "%";
                }
            }],
            "categoryField": "age",
            "categoryAxis": {
                "gridPosition": "start",
                "gridAlpha": 0.2,
                "axisAlpha": 0
            },
            "valueAxes": [{
                "gridAlpha": 0,
                "ignoreAxisWidth": true,
                "labelFunction": function (value) {
                    return Math.abs(value) + '%';
                },
                "guides": [{
                    "value": 0,
                    "lineAlpha": 0.2
                }]
            }],
            "balloon": {
                "fixedPosition": true
            },
            "chartCursor": {
                "valueBalloonsEnabled": false,
                "cursorAlpha": 0.05,
                "fullWidth": true
            },
            "allLabels": [{
                "text": "Male",
                "x": "28%",
                "y": "90%",
                "bold": true,
                "align": "middle"
            }, {
                "text": "Female",
                "x": "75%",
                "y": "90%",
                "bold": true,
                "align": "middle"
            }],
            "export": {
                "enabled": false
            }

        });

        chart.dataProvider = $.parseJSON(stackchartdata);

    }

但是ajax调用中的loc参数不会根据_layout.cshtml中选择的位置进行更新。

请帮助并提供更好的解决方案。

0 个答案:

没有答案