| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 | @{    Layout = null;}<!DOCTYPE html><html><head>    <meta name="viewport" content="width=device-width" />    <title>MajorQuoteTrendHighCharts</title>    <script src="~/Content/js/jquery.min.js"></script>    @*<script src="~/Content/plugins/highcharts/highcharts.js"></script>*@    <script src="~/Content/plugins/highcharts/highcharts5.0.14.js"></script>    <script type="text/javascript" src="~/Content/plugins/highcharts/modules/exporting.js"></script></head><body>    <div id="container" style="Z-INDEX: 103; LEFT: 5px; WIDTH: 1000px; POSITION: absolute; TOP: 120px; HEIGHT: 400px"></div>    <script>        var chart;        function LoadChart() {                      if (true) {                chart = new Highcharts.Chart({                    chart: {                        renderTo: 'container',                        defaultSeriesType: 'spline',                        events: {                            load: ChartQry                        }                    },                    title: {                        text: ''                    },                    xAxis: {                        categories: [],                        tickWidth: 3,                        tickmarkPlacement: 'on',                        labels: {                            rotation: 0,                            align: 'center',                            formatter: function () {                                // x轴的日期进行格式化                                var days = this.value.split('/');                                if (days.length == 3)                                    return days[1] + '/' + days[2];                                else                                    return this.value;                            }                        }                    },                    yAxis: {                        title: {                            text: ''                        }                    },                    tooltip: {                        enabled: true,                        formatter: function () {                            return '<b>' + this.series.name + '</b><br/>' +                                this.x + ': ' + Highcharts.numberFormat(this.y, 2) + '元';                        }                    },                    exporting: {                        buttons: {                            printButton: {                                enabled: false                            },                            exportButton: {                                enabled: false,                                menuItems: [{                                    text: 'PNG格式',                                    onclick: function () {                                        this.exportChart({                                            type: 'image/png',                                            width: 1200                                        });                                    }                                }, {                                    text: 'JPG格式',                                    onclick: function () {                                        this.exportChart({                                            type: 'image/jpeg',                                            width: 1200                                        });                                    }                                },                                null,                                null]                            }                        },                        //url: 'HighchartsExport.aspx',                        url: 'http://export.highcharts.com.cn',                        filename: 'MyChart',                        width: 1200                    },                    plotOptions: {                        spline: {                            dataLabels: {                                enabled: true,  // 是否在线上各点标注y轴数值                                formatter: function () {                                    return Highcharts.numberFormat(this.y, 2);                                }                            },                            enableMouseTracking: true                        }                    },                    credits: {                        enabled: false                    },                    series: [{                        name: '最高价',                        color: '#C85B6F',                        data: []                    }, {                        name: '最低价',                        color: '#15AE67',                        data: []                    }, {                        name: '平均价',                        //color: '#59C3E2',                        color: 'gray',                        dashStyle: 'longdash',                        data: []                    }]                });            }        }        function ChartQry() {                                  $.ajax({                url: '@Url.Action("ShowChartMajorQuoteTrendHighCharts", "DataCharts")',   // 查询接口                type: 'post',                dataType: 'json',               // 查询接口返回的数据类型                timeout: 10000000,               // 单位=毫秒。为了测试写成1000秒,正式环境下可改为20秒                data: {                                       ChartType: 'LINE'                                   },                success: function (srv_resp, textStatus) {                    // 查询接口无数据返回                    var count = eval(srv_resp.__totalcount);                    if (count == "" || count == null || count == "undefined" || count <= 0) {                        return;                    }                    if (true) {                        chart.xAxis[0].setCategories(srv_resp.__categories);                        if (srv_resp.__series.length == 3) {                            // 设置x轴label间隔,否则可能因为数据量而过密                            var step = Math.ceil(count / 10.0);                            if (step < 1) { step = 1; }                            //chart.xAxis[0].options.labels.step = step;                            chart.xAxis[0].options.tickInterval = step;                            // 设置各series的数据                            chart.series[0].setData(srv_resp.__series[0], false);                            chart.series[1].setData(srv_resp.__series[1], false);                            chart.series[2].setData(srv_resp.__series[2], false);                            chart.redraw();                        }                    }                },                // 捕获出错信息(服务器应答超时、返回数据不是json格式等,用于调试)                error: function (xmlHttpRequest, textStatus) {                    layer.alert(textStatus, { icon: 2, title: '提示信息' });                },                cache: false            });        };        $(function () {		                       LoadChart();            //加载日历控件            //$("#hid_ChartType").val("LINE");        });    </script></body></html>
 |