CanvasJS-访问变量-访问属性toString的权限被拒绝

CanvasJS - accessing variables - permission denied to access property toString

本文关键字:访问 权限 拒绝 属性 变量 CanvasJS- toString      更新时间:2023-11-25

因此,我有一个要在图表中显示的表单值。代码如下:

var chart;
function createChart() {
  console.log($("#kok").val()); // this prints a number
  try {
  chart = new CanvasJS.Chart("chart", {
    theme: "theme2",
    title: {text:"Kannatus"},
    data: [{
      type:"column",
      dataPoints: [
        {label:"KOK", y:$("#kok").val()}, // the problem is here
        {label:"KESK", y:$("#kesk").val()},
        {label:"SDP", y:$("#sdp").val()},
        {label:"PS", y:$("#ps").val()},
      ]
    }]
  });
} catch(e) {
  console.log(e.message);
}
chart.render();

这里怎么了?我应该换一个图书馆吗?

这里$("#kok").val()的类型是字符串。将其转换为数字将帮助您。

你可以参考http://www.w3schools.com/js/js_type_conversion.asp