javascript - 无法显示折线图
问题描述
我想为我的 JSP 页面添加一个 js 折线图。但它不会显示在页面上。也无法弄清楚错误。这是我的代码。对此的任何帮助表示赞赏。
window.onload = function() {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "light2",
title: {
text: "Title"
},
axisX: {
title: "Year"
},
axisY: {
title: "Value",
includeZero: true,
},
data: [{
name: "A",
type: "spline",
showInLegend: true,
dataPoints: <%out.write(dataPoints);%>
}]
});
chart.render();
}
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="com.google.gson.Gson"%>
<%@ page import="com.google.gson.JsonObject"%>
<%
Gson gsonObj = new Gson();
Map<Object,Object> map = null;
List<Map<Object,Object>> list = new ArrayList<Map<Object,Object>>();
map = new HashMap<Object,Object>();
map.put("x","2017");
map.put("y", 188);
list.add(map);
map = new HashMap<Object,Object>();
map.put("x","2018");
map.put("y", 200);
list.add(map);
map = new HashMap<Object,Object>();
map.put("x","2019");
map.put("y", 202);
list.add(map);
String dataPoints = gsonObj.toJson(list);
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<div>
<div id="chartContainer" style="height: 370px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</div>
</body>
解决方案
推荐阅读
- html - 浮动:内容太长时右推插入符号,如何工作?
- java - 我应该将哪个版本的 OpenJFX (JavaFX) 和 Scene Builder 与 Amazon Corretto 11 (OpenJDK) 一起使用?
- python - 在 3d 条形图中将刻度和基本形状之间的空间从正方形更改为矩形
- reactjs - 如何在反应表中使用复选框?
- javascript - 如何将我的数组转换为对象或 json webscraping
- c# - ASP.NET Core MVC 从 cshtml 页面调用异步方法
- mono - 在 Linux 中加载 Mono 库时如何处理未定义的符号
- dynamics-crm - 如何在不引用特定实体的情况下调用 Dynamics Web api 绑定的自定义操作?
- kotlin - 为什么 Gradle 会报告意外的 Kotlin 版本?
- c++ - 类成员变量的隐式默认值?