echarts相关问题
来源:15-8 Echarts的动态化验证
_不羁的风_
2019-03-09
老师x轴坐标显示不全怎么搞啊?
写回答
3回答
-
翔仔
2019-03-11
具体可以参考我的代码
@RequestMapping(value = "/listproductselldailyinfobyshop", method = RequestMethod.GET) @ResponseBody private Map<String, Object> listProductSellDailyInfobyShop(HttpServletRequest request) throws ParseException { Map<String, Object> modelMap = new HashMap<String, Object>(); // 获取当前的店铺信息 Shop currentShop = (Shop) request.getSession().getAttribute("currentShop"); // 空值校验,主要确保shopId不为空 if ((currentShop != null) && (currentShop.getShopId() != null)) { // 添加查询条件 ProductSellDaily productSellDailyCondition = new ProductSellDaily(); productSellDailyCondition.setShop(currentShop); Calendar calendar = Calendar.getInstance(); // 获取昨天的日期 calendar.add(Calendar.DATE, -1); Date endTime = calendar.getTime(); // 获取七天前的日期 calendar.add(Calendar.DATE, -6); Date beginTime = calendar.getTime(); // 根据传入的查询条件获取该店铺的商品销售情况 List<ProductSellDaily> productSellDailyList = productSellDailyService .listProductSellDaily(productSellDailyCondition, beginTime, endTime); // 指定日期格式 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // 商品名列表,保证唯一性 LinkedHashSet<String> legendData = new LinkedHashSet<String>(); // x轴数据 LinkedHashSet<String> xData = new LinkedHashSet<String>(); // 定义series List<EchartSeries> series = new ArrayList<EchartSeries>(); // 日销量列表 List<Integer> totalList = new ArrayList<Integer>(); // 当前商品名,默认为空 String currentProductName = ""; for (int i = 0; i < productSellDailyList.size(); i++) { ProductSellDaily productSellDaily = productSellDailyList.get(i); // 自动去重 legendData.add(productSellDaily.getProduct().getProductName()); xData.add(sdf.format(productSellDaily.getCreateTime())); if (!currentProductName.equals(productSellDaily.getProduct().getProductName()) && !currentProductName.isEmpty()) { // 如果currentProductName不等于获取的商品名,或者已遍历到列表的末尾,且currentProductName不为空, // 则是遍历到下一个商品的日销量信息了, 将前一轮遍历的信息放入series当中, // 包括了商品名以及与商品对应的统计日期以及当日销量 EchartSeries es = new EchartSeries(); es.setName(currentProductName); es.setData(totalList.subList(0, totalList.size())); series.add(es); // 重置totalList totalList = new ArrayList<Integer>(); // 变换下currentProductId为当前的productId currentProductName = productSellDaily.getProduct().getProductName(); // 继续添加新的值 totalList.add(productSellDaily.getTotal()); } else { // 如果还是当前的productId则继续添加新值 totalList.add(productSellDaily.getTotal()); currentProductName = productSellDaily.getProduct().getProductName(); } // 队列之末,需要将最后的一个商品销量信息也添加上 if (i == productSellDailyList.size() - 1) { EchartSeries es = new EchartSeries(); es.setName(currentProductName); es.setData(totalList.subList(0, totalList.size())); series.add(es); } } modelMap.put("series", series); modelMap.put("legendData", legendData); // 拼接出xAxis List<EchartXAxis> xAxis = new ArrayList<EchartXAxis>(); EchartXAxis exa = new EchartXAxis(); exa.setData(xData); xAxis.add(exa); modelMap.put("xAxis", xAxis); modelMap.put("success", true); } else { modelMap.put("success", false); modelMap.put("errMsg", "empty shopId"); } return modelMap; }
00 -
翔仔
2019-03-10
同学好,没太明白同学的意思,x坐标显示不全是指那些柱状图如果为0的就不显示吗 ?如果是这样的话为0确实没办法显示呢。。
042019-03-12 -
_不羁的风_
提问者
2019-03-09
xAxis.axisLabel属性
axisLabel:{
interval:0,
rotate:40
}
private String type = "category";
//为了去重
private HashSet<String> data;这是老师您EchartXAxis中封装的属性,axisLabel这个属性怎么封装呢?
00
相似问题