HashMap<String, Object> data = new HashMap<>();
HashMap<String, Object> yAxis = new HashMap<>();
HashMap<String, Object> xAxis = new HashMap<>();
HashMap<String, Object> xAxisData = new HashMap<>();
HashMap<String, Object> axisLabel = new HashMap<>();
HashMap<String, Object> series = new HashMap<>();
ArrayList<Integer> seriesData = new ArrayList<>();
HashMap<String, Object> tooltip = new HashMap<>();
HashMap<String, Object> title = new HashMap<>();

axisLabel.put('rotate', 30);
xAxisData.put('type', 'category');
xAxisData.put('data', Arrays.asList('1-101-智能设备05', '1-101-智能设备02', '1-101-智能设备16', '1-101-智能设备15', '1-101-智能设备01', '1-101-显示器', '2-108-摄像头', '2-109-键盘', '3-103-打印机', '3-102-显示器', '2-111-鼠标', '2-104-条码阅读器', '2-106-摄像头'));
xAxisData.put('axisLabel', axisLabel);
xAxis.put('xAxis', Arrays.asList(xAxisData));

seriesData.addAll(Arrays.asList(1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1));
series.put('series', Arrays.asList(new HashMap<String, Object>() {{
    put('data', seriesData);
    put('type', 'bar');
}}));

tooltip.put('tooltip', new HashMap<String, Object>());

title.put('title', new HashMap<String, Object>() {{
    put('text', '设备统计');
}});

data.put('yAxis', yAxis);
data.putAll(xAxis);
data.putAll(series);
data.putAll(tooltip);
data.putAll(title);

该代码使用 Java HashMap 创建一个 JSON 数据结构,包含以下属性:

  • yAxis: 用于设置 Y 轴的属性
  • xAxis: 用于设置 X 轴的属性,包括数据列表和标签旋转角度
  • series: 用于设置图表数据系列,包含数据和图表类型
  • tooltip: 用于设置鼠标悬停提示
  • title: 用于设置图表标题

这个代码示例展示了如何使用 Java HashMap 来构造图表数据格式,这对于在 Java 应用中使用图表库,例如 ECharts 或 Highcharts 非常有用。

注意: 为了清晰起见,代码示例中没有进行任何错误处理,在实际应用中,需要进行相应的错误处理。

Java HashMap 代码展示数据格式 - 设备统计图表

原文地址: https://www.cveoy.top/t/topic/n4OX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录