123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443 |
-
- @{
- Layout = null;
- }
- <!DOCTYPE html>
- <html>
- <head>
- <meta name="viewport" content="width=device-width" />
- <title>MajorQuoteMarketCmpHighCharts</title>
- <link href="~/easyui/themes/default/easyui.css" rel="stylesheet" />
- <link rel="stylesheet" type="text/css" href="~/easyui/themes/icon.css" />
- <link href="~/Content/css/bootstrap.min.css" rel="stylesheet" />
- <link href="~/Content/js/plugins/layer/skin/layer.css" rel="stylesheet" />
- @*<script src="~/Content/js/jquery.min.js"></script>*@
-
- <script src="~/Content/plugins/highcharts/jquery.min.js"></script>
- @*<script src="~/easyui/jquery.easyui.min.js"></script>
- <script src="~/easyui/jquery.easyui.mobile.js"></script>
- <script src="~/easyui/locale/easyui-lang-zh_CN.js"></script>*@
- <script src="~/Content/js/plugins/layer/laydate/laydate.js"></script>
- <script src="~/Content/js/plugins/layer/layer.min.js"></script>
- <script src="~/js/Utils.js"></script>
- <link href="~/Content/css/Styles.css" rel="stylesheet" />
- <link href="~/Content/css/style.min862f.css" rel="stylesheet" />
- <script src="~/Content/plugins/highcharts/highcharts.js"></script>
- <script type="text/javascript" src="~/Content/plugins/highcharts/modules/exporting.js"></script>
- </head>
- <body>
- <section class="hidden">
- <input type="hidden" id="hid_ReportTitle" value="@ViewBag.ReportTitle" />
- <input id="hid_IsMarketSysAccount" name="hid_IsMarketSysAccount" type="hidden" value="@ViewBag.IsMarketSysAccount" />
- <input id="hid_MarketID" name="hid_MarketID" type="hidden" value="@ViewBag.MarketID" />
- <input id="hid_ChartType" name="hid_ChartType" type="hidden" value="LINE" />
- <input id="hid_NumberFormat" name="hid_NumberFormat" type="hidden" value="0" />
- <input id="hid_IsExportImage" name="hid_IsExportImage" type="hidden" value="N" />
- </section>
- <table class="tableStyle1" style="Z-INDEX:101;LEFT:5px;WIDTH:725px;TOP:10px;POSITION:absolute;">
- <tr>
- <td class="td1"><img alt="" src="../Images/icon_1.gif" />商品名称:</td>
- <td class="td2">
- <select id="MajorGoods" style="height: 25px; width: 200px">
- @Html.Raw(ViewBag.SelMajorGoods)
- </select>
- </td>
- <td class="td1"><img alt="" src="../Images/icon_1.gif" />日期:</td>
- <td class="td2">
- <input class="laydate-icon layer-date" type="text" id="SearchStartTime" name="SearchStartTime" style="height: 25px; width: 200px" data-options="" placeholder="开始日期" />
- </td>
- <td class="td1">到:</td>
- <td class="td2">
- <input class="laydate-icon layer-date" type="text" id="SearchEndTime" name="SearchEndTime" style="height: 25px; width: 200px" data-options="" placeholder="截止日期" />
- </td>
- <td class="td1"><img alt="" src="../Images/icon_1.gif" />周期:</td>
- <td class="td2">
- <select style="height: 25px; width: 200px" id="cmbQueryCycle" name="cmbQueryCycle" onchange="f_CycleSelChanged()">
- <option value="1" selected>日</option>
- <option value="2">月</option>
- <option value="3">季</option>
- <option value="4">年</option>
- </select>
- </td>
- </tr>
- <tr>
- <td class="td1"><img alt="" src="../Images/icon_1.gif" />市场名称:</td>
- <td class="td2" colspan="7" height="150px">
- <select class="form-control" multiple="true" style="height: 150px; width: 400px" id="MarketIDs" name="MarketIDs" >
- @Html.Raw(ViewBag.SelMarketInfo)
- </select>
- </td>
- </tr>
- <tr>
- <td class="td1">
- <input type="radio" name="ChartType" value="LINE" style="margin: 5px 3px 0 0" checked="checked" /> 趋势图
- </td>
-
- <td class="td1" colspan="7">
- <div align="center">
- <div align="center">
- <input id="BtnPrintChart" type="button" class="but1" style=" height: 25px" onclick="LoadChart();" value="查询" />
- <input id="BtnPrintChart" type="button" onclick="PrintBtnClk()" style="width:60px" class="but1" value="打印图片" />
- <input id="BtnExportChart" type="button" onclick="ExportChartBtnClk()" style="width:60px" class="but1" value="导出图片" />
- </div>
- </div>
- </td>
- </tr>
- </table>
- <div id="container" style="Z-INDEX: 103; LEFT: 5px; WIDTH: 1000px; POSITION: absolute; TOP: 250px; HEIGHT: 400px"></div>
- <script>
- var chart;
- function LoadChart() {
- chart = new Highcharts.Chart({
- chart: {
- renderTo: 'container',
- defaultSeriesType: 'spline',
- events: {
- load: ChartQry
- }
- },
- title: {
- text: $('#hid_ReportTitle').val()
- },
- xAxis: {
- tickWidth: 3,
- minPadding: 0.1,
- maxPadding: 0.1,
- //gridLineWidth:1,
- endOnTick: false,
- //tickPixelInterval : 125, // 对固定Category的x轴不适用
- type: 'datetime', // x轴无固定Category,必须用datetime类型
- labels: {
- rotation: 0,
- align: 'center',
- formatter: function () {
- // Date.UTC值是长整数,转换成日期格式
- var strDate = Highcharts.dateFormat('%Y/%m/%d', this.value);
- var days = strDate.split('/');
- if ($('#cmbQueryCycle').val() == '1') {
- return days[1] + '/' + days[2];
- } else if ($('#cmbQueryCycle').val() == '2') {
- return days[0] + '/' + days[1];
- } else if ($('#cmbQueryCycle').val() == '3') {
- return days[0] + '/' + days[1];
- } else {
- return days[0];
- }
- }
- }
- },
- yAxis: {
- title: {
- text: ''
- }
- },
- tooltip: {
- enabled: true,
- formatter: function () {
- return '<b>' + this.series.name + '</b><br/>' +
- Highcharts.dateFormat('%Y-%m-%d', 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: []
- });
- }
-
- var _IsExportImage = 'N';
- function ChartQry() {
-
- //var sDate, eDate;
- //sDate = document.getElementById("SearchStartTime").value;
- //eDate = document.getElementById("SearchEndTime").value;
- var MarketIDs = document.getElementById("MarketIDs");
- var strs = "";
- for (var i = 0; i < MarketIDs.length; i++) {
- //marketIds += marketIds == "" ? MarketIDs[i] : ',' + MarketIDs[i];
- if (MarketIDs.options[i].selected) {
- strs += MarketIDs.options[i].value + ",";
- }
- }
- if (strs.length > 0) {
- strs = strs.substr(0, strs.length - 1);
- }
- if (strs.length <= 0) {
- return;
- }
- var MajorGoods = $("#MajorGoods").val();
- var startTime = $('#SearchStartTime').val();
- var endTime = $('#SearchEndTime').val();
- var chartType = $("#hid_ChartType").val();
- var reportType = $("#hid_ReportType").val();
- var cmbQueryCycle = $("#cmbQueryCycle").val();
- $.ajax({
- url: '@Url.Action("ShowMajorQuoteMarketCmpHighCharts", "DataCharts")', // 查询接口
- type: 'post',
- dataType: 'json', // 查询接口返回的数据类型
- timeout: 1000000, // 单位=毫秒。为了测试写成1000秒,正式环境下可改为20秒
- data: {
- MarketIDs: strs,
- MajorGoods: MajorGoods,
- startTime: startTime,
- endTime: endTime,
- chartType: chartType,
- cmbQueryCycle: cmbQueryCycle,
- IsExportImage: _IsExportImage
- },
- success: function (srv_resp, textStatus) {
- // 查询接口无数据返回
- var count = eval(srv_resp.__totalcount);
- if (count == "" || count == null || count == "undefined" || count <= 0) {
- return;
- }
- var step = Math.ceil(count / 10.0);
- if (step < 1) { step = 1; }
- if ($("#hid_ChartType").val() == 'LINE') {
- if (srv_resp.__series == null) {
- return;
- }
- if (srv_resp.__series.length > 0) {
- // 设置x轴label间隔,否则可能因为数据量而过密
- if ($('#cmbQueryCycle').val() == '1') {
- chart.xAxis[0].options.tickInterval= step * 24 * 3600 * 1000;
- } else if ($('#cmbQueryCycle').val() == '2') {
- chart.xAxis[0].options.tickInterval= 30 * step * 24 * 3600 * 1000;
- } else if ($('#cmbQueryCycle').val() == '3') {
- chart.xAxis[0].options.tickInterval= 90 * step * 24 * 3600 * 1000;
- }else {
- chart.xAxis[0].options.tickInterval= 365 * step * 24 * 3600 * 1000;
- }
-
- // 设置各series的数据
- for (var i = 0; i < srv_resp.__series.length; i++) {
- var addFlag = 1;
- for (var j = 0; j < srv_resp.__series[i].length; j++) {
- // 把数据中的日期转换成Data.UTC值
- var temp = srv_resp.__series[i][j].x;
- if (temp != null) {
- var days = temp.split('/');
- // 日统计
- if ($('#cmbQueryCycle').val() == '1') {
- if (days.length == 3) {
- srv_resp.__series[i][j].x = Date.UTC(days[0], days[1]-1, days[2]);
- }
- }
- // 月统计
- else if ($('#cmbQueryCycle').val() == '2') {
- if (days.length == 2) {
- srv_resp.__series[i][j].x = Date.UTC(days[0], days[1]-1, 1);
- }
- }
- // 季统计(x轴类型为datetime,季度必须转换到月份)
- else if ($('#cmbQueryCycle').val() == '3') {
- if (days.length == 2) {
- srv_resp.__series[i][j].x = Date.UTC(days[0], 3*(days[1]-1), 1);
- }
- }
- // 年统计
- else {
- if (days.length == 1) {
- srv_resp.__series[i][j].x = Date.UTC(days[0], 0, 1);
- }
- }
- }
- else {
- addFlag = 0;
- }
- } //for j
- if (addFlag == 1) {
- chart.addSeries({ name: srv_resp.__names[i],
- data: srv_resp.__series[i] },
- false);
- }
- else {
- // 无数据的series
- chart.addSeries({ name: srv_resp.__names[i],
- data: [] },
- false);
- }
- }
- chart.redraw();
- }
- }
- },
- // 捕获出错信息(服务器应答超时、返回数据不是json格式等,用于调试)
- error: function (xmlHttpRequest, textStatus) {
- layer.alert(textStatus, { icon: 2, title: '提示信息' });
- },
- cache: false
- });
- }
-
- $(function() {
- if ($("#hid_IsMarketSysAccount").val() === "0") {
- $("#MarketIDs").find("option[value='" + $('#hid_MarketID').val() + "']").attr("selected", true);
- $("#MarketIDs").attr('disabled', 'disabled')
- } else {
- $("#MarketIDs").find("option[value='" + $('#hid_MarketID').val() + "']").attr("selected", true);
- }
- console.log($("#MarketIDs").val());
- //$('#MarketIDs').val($('#hid_MarketID').val())
- laydate(start);
- laydate(end);
- f_CycleSelChanged();
- LoadChart();
- });
- //返回两个时间的天数:要求比较的时间的格式为:YYYY-MM-DD
- function better_time(strDateStart, strDateEnd) {
- strDateStart = strDateStart.replace("/", "-").replace("/", "-");
- strDateEnd = strDateEnd.replace("/", "-").replace("/", "-");
- var strSeparator = "-"; //日期分隔符
- var strDateArrayStart;
- var strDateArrayEnd;
- var intDay;
- if (strDateStart == "" || strDateEnd == "") {
- //alert("ddddddd");
- }
- strDateArrayStart = strDateStart.split(strSeparator);
- strDateArrayEnd = strDateEnd.split(strSeparator);
- var strDateS = new Date(strDateArrayStart[0] + "/" + strDateArrayStart[1] + "/" + strDateArrayStart[2]);
- var strDateE = new Date(strDateArrayEnd[0] + "/" + strDateArrayEnd[1] + "/" + strDateArrayEnd[2]);
- intDay = (strDateS - strDateE) / (1000 * 3600 * 24);
- return intDay;
- }
- var start = {
- elem: "#SearchStartTime",
- format: "YYYY-MM-DD",
- min: "2010-01-01",
- event: "focus",
- choose: function (datas) {
- end.min = datas; //开始日选好后,重置结束日的最小日期
- end.start = datas; //将结束日的初始值设定为开始日
- $('#SearchStartTime').val(datas);
- }
- },
- end = {
- elem: "#SearchEndTime",
- format: "YYYY-MM-DD",
- min: "2010-01-01",
- event: "focus",
- choose: function (datas) {
- start.max = datas; //结束日选好后,重置开始日的最大日期
- $('#SearchEndTime').val(datas);
- }
- };
- // '查询周期'选择变化
- function f_CycleSelChanged() {
- var obj = $('#cmbQueryCycle').val();
- // 结束日期
- var dateE = new Date();
- document.getElementById("SearchEndTime").value = FormatDate(dateE);
- // 开始日期
- var dateB = new Date();
- if (obj == "1") {
- dateB.setDate(dateE.getDate() - 30);
- }
- else if (obj == "2") {
- dateB.setMonth(dateE.getMonth() - 6);
- }
- else if (obj == "3") {
- dateB.setMonth(dateE.getMonth() - 16);
- }
- else {
- dateB.setYear(dateE.getFullYear() - 6);
- }
- document.getElementById("SearchStartTime").value = FormatDate(dateB);
- }
- // 格式化Date类型的数据为yyyy-mm-dd
- function FormatDate(d) {
- // 获取年份
- s = d.getFullYear();
- // 获取月份
- c = d.getMonth() + 1;
- if (c < 10) {
- s += "-0" + c;
- }
- else {
- s += "-" + c;
- }
- // 获取日
- e = d.getDate();
- if (e < 10) {
- s += "-0" + e;
- }
- else {
- s += "-" + e;
- }
- return s;
- }
- // 打印图片
- function PrintBtnClk() {
- //$("#container").printArea();
- chart.print();
- }
- // 导出图片
- function ExportChartBtnClk() {
- _IsExportImage = 'Y';
-
- chart.exportChart({ type: 'image/png', width: 1200 });
- _IsExportImage = 'N';
- }
- </script>
- </body>
- </html>
|