Echart折线图 Sql总结

这里写图片描述
这里写图片描述
现在前端想要获取车辆的闲置数量,用Echart表格展示出来。
问题有两个:
一是:sql 语句怎么写?问题描述:闲置数量是根据上传GPRS数据进行统计。这里闲置数量是当日里程小于3KM,则,为闲置数量。难点是通过数据库中查询每天的闲置数量,并通过时间进行排序升序排序。而Date为String类型,所以要进行时间格式的转换。而查出来是数量,是数据库中没有的字段。可以用DO处理,上一篇文章已经说过。现在给出完整Sql,如下

SELECT date_format( searchtime, '%Y-%m-%d %H-%m-%s' ) AS searchtime, sum(licheng < 3) AS count FROM cx_reportoneday WHERE licheng < 3 GROUP BY searchtime ORDER BY searchtime ASC

查询结果是:
这里写图片描述
二是:如何封装Json 格式数据传送到前台?前台接收的Json格式如图:
这里写图片描述
给出相关代码:

@RequiresPermissions("admin:echart:freecount")
    @RequestMapping(value="/echart/freecount",method=RequestMethod.POST)
    @ResponseBody
    public EchartDataVO loadData(){
        List<String> category = new ArrayList<String>();
        List<Integer> serisData=new ArrayList<Integer>();
        List<Freecount> list = freecountService.findCar_FreeCount();
        for (Freecount totalNum : list) {
            category.add(totalNum.getSearchtime());
            serisData.add(totalNum.getCount());
        }

        List<String> legend = new ArrayList<String>(Arrays.asList(new String[] { "顺丰车辆在线数量统计" }));// 数据分组
        List<SeriesVO> series = new ArrayList<SeriesVO>();// 纵坐标
        series.add(new SeriesVO("车辆闲置数量", "line", serisData));
        EchartDataVO targetdata = new EchartDataVO(legend, category, series);
        return targetdata;
    }

VO代码:


/**
 * E -Chart 显示数据
 */
public class SeriesVO<T> {

    public String name;

    public String type;
    public List<T> data;// 这里要用int 不能用String 不然前台显示不正常(特别是在做数学运算的时候)

    public SeriesVO(String name, String type, List<T> data) {
        super();
        this.name = name;
        this.type = type;
        this.data = data;
    }

}

EchartVO代码


public class EchartDataVO {


    public List<String> legend = new ArrayList<String>();// 数据分组
    public List<String> category = new ArrayList<String>();// 横坐标
    public List<SeriesVO> series = new ArrayList<SeriesVO>();// 纵坐标

    public EchartDataVO(List<String> legendList, List<String> categoryList,
            List<SeriesVO> seriesList) {
        super();
        this.legend = legendList;
        this.category = categoryList;
        this.series = seriesList;
    }

}

前台代码:

<script type="text/javascript">
   showBar();
        function showBar(){
            var myChart = echarts.init(document.getElementById('main2'));
            //图表显示提示信息
            myChart.showLoading();
            //定义图表options
            var options = {
                color : [ '#1abc9c' ],
                title : {
                    text : "顺丰车辆闲置数量统计"
                },
                tooltip : {
                    trigger : 'axis'
                },
                legend : {
                    data : []
                },
                toolbox : {
                    show : true,
                   feature: {
                    mark: { show: true },
                    dataView: { show: true, readOnly: false },
                    magicType: {
                        show: true,
                        type: ['pie', 'funnel'],
                        option: {
                            funnel: {
                                x: '25%',
                                width: '50%',
                                funnelAlign: 'left',
                                max: 1548
                            }
                        }
                    },
                    restore: { show: true },
                    saveAsImage: { show: true }
                }
                },
                calculable : true,
                xAxis : [ {
                    type : 'category',
                    data : []
                } ],
                yAxis : [ {
                    type : 'value',
                    splitArea : {
                        show : true
                    }
                } ],
                series : [ {
                    barWidth : '60%'
                } ]
            };

            //通过Ajax获取数据
            $.ajax({
                type : "post",
                async : false, //同步执行
                url : "${basePath}/admin/echart/freecount",
                dataType : "json", //返回数据形式为json
                success : function(result) {
                    if (result) {
                        //将返回的category和series对象赋值给options对象内的category和series
                        //因为xAxis是一个数组 这里需要是xAxis[i]的形式
                        options.xAxis[0].data = result.category;
                        options.series = result.series;
                        options.legend.data = result.legend;

                        myChart.hideLoading();
                        myChart.setOption(options);
                    }
                },
                error : function(errorMsg) {
                    alert("图表请求数据失败啦!");
                }
            });
    }

</script>

至此完毕!《end》
总结用到的知识点,一,复杂的Sql,二,Mybatis中处理字段不对应的关系,三,封装Json格式数据,四,前台通过Ajax异步请求数据。完整Echart折线图获取数据。
显示效果如图:
这里写图片描述

  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
To create an echart折线图 with data for 日(day), 周(week), and 年(year), you can use the following steps: 1. Import the echarts library into your project by adding the following code: ``` import echarts from 'echarts' Vue.prototype.$echarts = echarts ``` 2. Define your data in the `data()` method of your Vue component. This should include variables for `bdTimeIndex`, `bdScopeTime`, `bdTimeData`, `insuranceChart`, `insuranceOption`, `inquiryDataCount`, `payDataCount`, and `dataLineX`. 3. Create a method to handle the user's selection of 日(day), 周(week), or 年(year). This method should update the `bdTimeIndex` and `bdScopeTime` variables and call the API to fetch the corresponding line chart data. 4. Implement the API call to fetch the line chart data based on the selected timeframe (日, 周, or 年). Use the `bdScopeTime` variable to pass the selected timeframe to the API. 5. Configure the echart折线图 by setting the `insuranceOption` variable. This should include the necessary properties such as xAxis, yAxis, series, and any other customization options you require. 6. Render the echart折线图 by creating a div element in your template and applying the echart折线图 to it using the `insuranceChart` and `insuranceOption` variables. For more examples and documentation on how to use echarts, you can refer to the official echarts gallery at: https://gallery.echartsjs.com/explore.html#sort=createTime~timeframe=all~author=all . By following these steps, you can create an echart折线图 for 日周年 with the ability to switch between different timeframes and update the data accordingly.<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [echarts vue element-ui 实现根据选择项年月日时间切换数据显示折线图,vue页面监听自适应(二)](https://blog.csdn.net/SmartJunTao/article/details/125309447)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [vue引用echarts柱形加折线统计图(周月年动态切换数据)](https://blog.csdn.net/qq_42221334/article/details/96307823)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值