javascript - 将 Highcharts(和模块)与 lit-element 一起使用
问题描述
根据GitHub 问题,这是一个后续问题:
我想将 Highcharts 和一些模块与 Lit-Element 一起使用,并在导入 Highcharts 和模块时遇到困难。
如果我使用import 'highcharts';
,我可以Highcharts
在我的代码中完美地使用 -Object 。使用给定的解决方案 ( import * as Highcharts from 'highcharts';
),它不起作用。
任何给定的模块导入解决方案都不起作用:
import 'highcharts/modules/exporting'; // doesn't throw an error, but can't bind it to Highcharts
import HC_exporting from 'highcharts/modules/exporting'; // does throw a 'no named default export' error
import * as HC_exporting from 'highcharts/modules/exporting'; // throws 'TypeError: HC_exporting is not a function'
ld-application-actions.js:56 Uncaught (in promise) SyntaxError: The requested module '../../../../node_modules/highcharts/modules/exporting.js' does not provide an export named 'default'
那么是否有可能导入和使用Highcharts 及其模块?
疯狂的事情:我试图在 Stackblitz 上创建一个示例,但它确实有效:https ://stackblitz.com/edit/ic7f4z
这里有什么区别?那是因为 Stackblitz 使用 TypeScript 导入而我使用polyserve
没有 TypeScript 吗?
更新:
我在 JSFiddle 上创建了相同的示例(请参阅https://jsfiddle.net/sebastianroming/uer59cnw/6/),这与我的机器上的相同:不起作用。随意取消注释注释行以获得控制台的输出。
谢谢!
解决方案
可以像这样下载使用lit-element
和polyserve
Highcharts 及其模块:
import 'highcharts';
import 'highcharts/modules/exporting';
import 'highcharts/modules/boost'
import 'highcharts/highcharts-more';
组件代码:
import { LitElement, html } from 'lit-element';
import 'highcharts';
import 'highcharts/modules/exporting';
import 'highcharts/modules/boost'
import 'highcharts/highcharts-more';
class ChartTest extends LitElement {
firstUpdated(changedProperties) {
this._enableChart();
}
render() {
return html`
<div id='container' style='width:500px;height:300px;border: 1px red solid;'>sfsdfs</div>
`;
}
_enableChart() {
Highcharts.chart(this.shadowRoot.querySelector('#container'), {
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
]
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4],
type: 'column'
}]
});
}
}
customElements.define('chart-test', ChartTest);
演示:
推荐阅读
- excel - Excel 2013 | 列出数组中非空白单元格的内容
- xcode - intentdefinition 生成代码中的类前缀
- javascript - 如何使用 Ajax 将 html 中的数组参数发布到控制器
- android - 为什么我的响应正文为空,状态为 200?
- hive - 在 HIVE 中排序观察
- html - 我如何缩小这个盒子的大小,以便让它们彼此对齐?
- python - 在 Beautiful Soup Python 中用文本打印类名
- android - 匕首刀柄在数据绑定之前注入
- emulation - 在visual studio中运行一个实时更新的模拟器,我似乎无法让我的运行
- google-cloud-platform - GKE VPN 到本地数据库