
@{
    //ViewData["Title"] = "仓库数据趋势图";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "库存汇总分析", "库存数据分析趋势图" };
}

<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content m-b-sm border-bottom">
            <form id="toolbar">
                <div class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        <label>统计日期：</label>
                        <input id="start" name="start" class="form-control" value="@(ViewBag.start)" placeholder="请选择开始日期" />至
                        <input id="end" name="end" class="form-control" value="@(ViewBag.end)" placeholder="请选择结束日期" />
                    </div>
                    <div class="form-group">
                        <label>&nbsp;</label>
                        <button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button>
                    </div>
                </div>
            </form>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <div id="echart-contain" style="width:100%;height:480px;">

            </div>
        </div>
    </div>
</div>

@section scripts{
    <script src="~/js/echarts.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            getData();
        })

        function getData() {
            var start = $('#start').val();
            var end = $('#end').val();

            if (start == "") {
                alert("请选择开始日期");
                return;
            }
            if (end == "") {
                alert("请选择结束日期");
                return;
            }

            $.submit({
                type:'POST',
                url: '@Url.Content("~/Reports/Warehouse/InventorySummaryChartJson")',
                paramData: 'warehousecode=@(ViewBag.warehousecode)&key=@(ViewBag.key)&start='+start+'&end='+end,
                func: function (result) {
                    if (result) {
                        showChart('@Html.Raw(ViewBag.warehousename)', result.dates, result.val);
                    }
                }
            })
        }

        function showChart(title, category, vals) {
            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('echart-contain'));

            option = {
                title: {
                    text: title
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: ['@Html.Raw(ViewBag.title)']
                },
                grid: {
                    left: '3%',
                    right: '4%',
                    bottom: '3%',
                    containLabel: true
                },
                toolbox: {
                    feature: {
                        saveAsImage: {}
                    }
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: category
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        name: '@Html.Raw(ViewBag.title)',
                        type: 'line',
                        stack: '总量',
                        data: vals
                    }
                ]
            };

            
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        }

    </script>
}

