angular - 如何将 Highcharts 渲染为 id 作为容器的 div - Angular?
问题描述
我试过写下面的代码。html:
<div id="container"></div>
Ts 组件:
var chart = Highcharts.chart('container', {
chart: {
type: 'bar',
marginLeft: 100,
plotAreaWidth: 50,
plotAreaHeight: 450,
},
title: {
text: 'Bar series - data sorting'
},
yAxis: {
title: {
text: ''
}
},
xAxis: {
type: 'category',
min: 0,
labels: {
animate: false
}
},
legend: {
enabled: false
},
series: [{
zoneAxis: 'x',
zones: [{
value: 2,
color: 'red'
}],
dataLabels: {
enabled: true,
format: '{y:,.2f}'
},
dataSorting: {
enabled: true,
sortKey: 'y'
},
data: [["hello",1],["hello",1],["hello",1],["hello",1],]
}]
});
我收到以下错误:
error TS2769: No overload matches this call.
Overload 1 of 2, '(options: Options, callback?: ChartCallbackFunction): Chart', gave the following error.
Type '"container"' has no properties in common with type 'Options'.
426 var chart = Highcharts.chart('container', {
即使我遇到错误,我也可以在容器中看到图表呈现。谁能建议我如何解决这个错误,我正在使用 Visual Studio 作为 IDE。
提前致谢!!!
解决方案
要使其工作,您需要指定chartOptions 对象的类型,并从chartOptions 中删除无效的属性(没有像chart.plotAreaHeight
,chart.plotAreaWidth
或那样的属性labels.animate
)。然后您需要为每个系列指定一个类型(在您的情况下只需添加type: 'bar'
)。正如您在下面附加的演示中所看到的,在进行了这些更正之后,一切都正常工作。
现场演示:
https ://stackblitz.com/edit/highcharts-angular-basic-line-dg4fpj
另外,请记住,建议在使用 angular 时使用官方的 highcharts-angular 包装器。您可以在此处找到有关用法的更多信息:https ://github.com/highcharts/highcharts-angular
现场演示:(使用 highcharts-angular 制作的相同图表):
https ://stackblitz.com/edit/highcharts-angular-basic-line-txhzcr
推荐阅读
- api - 与 BigCommerce API 连接时出现问题
- github - git中的文件类型是什么?
- mongodb - 如何将多张图片上传到 Deno?
- c++ - 按字母顺序对结构内数组变量中的名称进行排序
- powershell - 创建指向 UNC 路径的符号链接不起作用?
- android-studio - 如何从颤振的 android studio 构建 apk
- matlab - MATLAB 如何在我当前的程序中添加 surf 函数
- javascript - 如何将多个复选框的状态保存到后端?
- python - 如何在我的 CSV 文件中选择某个数据点并绘制所有值为 + 或 - 1 的值?
- r - R 中的动态规划 - 仓库位置之间距离的算法