๋๋ Highcharts๊ฐ Babel/Browserify/ES6 ๊ฐ์ ธ์ค๊ธฐ์ ํจ๊ป ์๋ํ๋๋ก ํ ์ ์๋ ๋ชจ๋ ๊ฒ์ ์๋ํ์ต๋๋ค. ReferenceError: Highcharts is not defined
์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ์ด์ ์ highstock-browserify๋ฅผ ์ฌ์ฉํ์ง๋ง ์ด๋ํฐ๋ฅผ ์ ๊ฑฐํ ํ ๊ณ ์ฅ๋ฌ์ต๋๋ค.
๋๋ ํ๋ค
npm install highcharts --save-dev
๋ด๊ฐ ํ์ด
//highcharts libraries
import Highcharts from 'highcharts/highstock';
import 'highcharts-ng'; //angular highcharts bindings
dev ๋๊ตฌ๋ฅผ ๋ณด๋ฉด ํ์ผ์ ์ ๊ฐ์ ธ์ค๊ณ ์์ต๋๋ค.
๋์์ ์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค. stackoverflow ์ ๊ด๋ จ๋ ๋ฌธ์ ์ผ ์ ์์ต๋๋ค.
ํธ์งํ๋ค:
๋ํ highcharts-release
ํจํค์ง๋ก ํ์ฌ์ ์ผ๋ก( :P ) ์๋ํ์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ๋. ์ ๋ ์ถ์ฒํ๋ ๋ฐฉ๋ฒ์ ์๋ํด๋ดค์ต๋๋ค. ํ์ผ์ด ์์ค์ ํฌํจ๋ ๊ฒ์ผ๋ก ๋ณด์ด์ง๋ง Highcharts๋ ์์ง ์ ์๋์ง ์์์ต๋๋ค.
//highcharts libraries
let Highcharts = require('highcharts/highstock');
import 'highcharts-ng';
CC- @laytzehwu
๋๋ webpack ng es6์ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ์๋์ํค๋ ์ ์ผํ ๋ฐฉ๋ฒ์
var Highcharts = require('highcharts/highstock');
window.Highcharts = Highcharts;
require('highcharts/modules/exporting')(Highcharts);
๋๊ตฐ๊ฐ๊ฐ ๊ฐ์ ธ์ค๊ธฐ ๊ตฌ๋ฌธ์ ์ฌ์ฉํ์ฌ ์ด ์์ ์ ์ํํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์๋ค๋ฉด ํ์ ํด ์ฃผ์ญ์์ค.
@ ์กด ์ด ๋๊ณ ๋ฅด
์ ๊ณ ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค! ๊ฐ๋ฅํ ํ ๋นจ๋ฆฌ ์ด์ ๋ํด ์กฐ์ฌํ๊ฒ ์ต๋๋ค. ๊ทธ ๋์ ๋์์ผ๋ก babel-loader ๊ฐ ์๋ webpack ์ ์ดํด๋ณผ ์ ์์ต๋๋ค.
์๋ ํ์ธ์, @jon-a-nygaard์ ๋๋ค. Webpack์ ํ์คํ ์์ผ๋ก ๋์๊ฐ ๋ฐฉํฅ์ ๋๋ค. ์ฐ๋ฆฌ๋ ๊ทธ๊ฒ์ ๋ค์ ํ๋ก์ ํธ์์ ์ฌ์ฉํ ๊ฒ์ ๋๋ค. ๊ทธ๋ฌ๋ ์ด ํ๋ก์ ํธ๋ ๋ง์ ๋ธ๋ผ์ฐ์ ํ ์ฌ์ฉ์ ์ง์ ๋ฒ๋ค๋ก ์ธํด ๋๋ฌด ์ฑ์ํ์ต๋๋ค. ๋น์ ์ด ์ด๊ฒ์ ์์๋ด๋ฉด ์ ์๊ฒ ์๋ ค์ฃผ์ญ์์ค.
๊ด์ฐฎ์. @ragefuljoe - window.Highcharts = Highcharts
๊ฐ ํ์ํ ๊ฒ์ด์์ต๋๋ค. ์ด ๊ฐ์ ธ์ค๊ธฐ ๊ตฌ๋ฌธ๊ณผ ํจ๊ป ์๋ํฉ๋๋ค!
import Highcharts from 'highcharts/highstock';
window.Highcharts = Highcharts; //this line did the magic
import 'highcharts-ng';
์ด๊ฒ์ ๋ซ์์ผ ํฉ๋๊น ์๋๋ฉด ์ฝ๋ ๋ด๋ถ์ window.Highcharts๋ฅผ ๋ฐ์ธ๋ฉํ์๊ฒ ์ต๋๊น? ๋๋ ์ด๊ฒ์ด ์ฃผ์ ๋ฌธ์๋ ์ด๋๊ฐ์ ์ถ๊ฐ๋์ด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
@piggyslasher ๋คํ @ragefuljoe์์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๋์๋ค. ES6 ๊ฐ์ ธ์ค๊ธฐ๋ก Highchart ๋ก๋๋ฅผ ๊ฐ์ ํ๋ ์์ ์ ํ ์ ์๋๋ก ์ด ๋ฌธ์ ๋ฅผ ์ด์ด ๋ก๋๋ค.
๋๋ ์ด๊ฒ์ด ์ฃผ์ ๋ฌธ์๋ ์ด๋๊ฐ์ ์ถ๊ฐ๋์ด์ผ ํ๋ค๊ณ ์๊ฐํฉ๋๋ค.
์ค์ ๋ก npm ์์
๋ฉ์ง๋ค์ @piggyslasher. ๊ฐ์ ธ์ค๊ธฐ ๊ตฌ๋ฌธ์ผ๋ก exporting.js
๊ฐ์ ธ์ค๊ธฐ์ ํ์ด์ด ์์ต๋๊น?
_์
๋ฐ์ดํธ_
์ฌ๊ธฐ์ ์ง๋๊ฐ ํ์ํ ๋ชจ๋ ํ์ด์ฐจํธ ๊ด๋ จ ๋ผ์ธ์ด ์์ต๋๋ค.
import Highcharts from 'highcharts/highstock';
window.Highcharts = Highcharts;
require('highcharts/modules/map')(Highcharts);
require('highcharts/modules/exporting')(Highcharts);
require('./pages/home-page/world'); //I'm downloading this from example links. any better way?
import 'highcharts-ng';
ํน์ ์ง๋ ๋ฐ์ดํฐ๋ฅผ ์ฒ๋ฆฌํ๋ ๋ ์ข์ ๋ฐฉ๋ฒ์ด ์์ต๋๊น? ์, ๋ค์ด๋ก๋ํ๊ณ ์ฌ๊ธฐ์ world.js๋ฅผ ๋ช ์์ ์ผ๋ก ํฌํจํฉ๋๋ค(๋ค๋ฅธ ์ต์ ์ ๋ฐฑ์๋์์ json์ ๊ฐ์ ธ์ค๋ ๊ฒ์ ๋๋ค. ์ด ์์ ์ ์ํํ ์ ์์)
์ ํํ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ๋ด ํ๋ก์ ํธ์์ ํ๊ณ ์ถ์ ์ผ์ 'Highcharts'๋ฅผ ๊ฐ์ ธ์์ ๋๋ด๋ ๊ฒ๋ฟ์ ๋๋ค. ๋ค๋ฅธ ๋ชจ๋ ์ฃผ์ JS ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๊ธฐ๋ณธ์ ์ผ๋ก "์๋"ํ๋ฉฐ Highcharts๊ฐ ์๋ํ์ง ์๋ ์ด์ ๋ฅผ ์ดํดํ ์ ์์ต๋๋ค.
@jon-a-nygaard @TorsteinHonsi - Angular, lodash, ๋ฐ์ค, ui-router ๋ฐ ๊ธฐํ ์๋ง์ JS ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ๋ธ๋ผ์ฐ์ ํ/์นํฉ ๋ฑ์ ๊ธฐ๋ฅ์ ๋ ธ์ถํ๊ณ ํ์ด์ฐจํธ์์ ๋ณต์ ํ๋ ๋ฐฉ๋ฒ์ ์ดํด๋ณด๋ ๊ฒ์ด ์ข์ต๋๋ค.
@romiem ํ ๊ฐ์ฌํฉ๋๋ค. ํ์ฌ ์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด ์์ ์ค์ด๋ฉฐ ๋ค์ ์ ์ง ๊ด๋ฆฌ ๋ฆด๋ฆฌ์ค์ ์ ์ฉํ ๊ณํ์ ๋๋ค.
์๋
ํ์ธ์,
highcharts 4.2.5์ ๋น์ทํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ๋๋ Use Highcharts to create chart in React ๊ธฐ์ฌ๋ฅผ
๊ฐ์ ธ์ค๊ธฐ ๊ตฌ๋ฌธ, ์ฆ import Highcharts from 'highcharts'
ํ๋ฉด Uncaught TypeError: _highcharts2.default[(this.props.type || "Chart")] is not a constructor
์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
@ragefuljoe ์์ ์ ์ํ ๊ตฌ๋ฌธ์ ์ฌ์ฉํ๋ฉด ์๋ํฉ๋๋ค! ๊ทธ๋ฌ๋,์ด ๋ฐฉ๋ฒ ์ฌ์ฉ์ ๋ํ, ๋๋ฅผ ์๊ฐํ๊ฒ 'highcharts/highstock
๋์ 'highcharts'
? ๊ธ์, ๊ทธ๊ฒ์ ๊ฐ์ ธ์ค๊ธฐ ๊ตฌ๋ฌธ๊ณผ ํจ๊ป ์๋ํฉ๋๋ค. ์ฐจ์ด์ ์ ๋ฌด์์
๋๊น, ์๋๋ฉด ๊ทธ๋ฐ ์์ผ๋ก ์๋ํ๋ ๊ฒ์ผ๋ก ์๊ฐ๋๊ณ ๊ฐ์ ธ ์ค๊ธฐ๋ฅผ ์๋ชป ์ฌ์ฉํ๊ณ ์์ต๋๊น?
๋ค์์ ์์ ํ (์๋ํ๋) ์ฝ๋์ ๋๋ค:
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import Highcharts from 'highcharts/highstock';
class Chart extends Component {
constructor(props) {
super(props);
}
// When the DOM is ready, create the chart.
componentDidMount() {
// Extend Highcharts with modules
if (this.props.modules) {
this.props.modules.forEach(function (module) {
module(Highcharts);
});
}
this.chart = new Highcharts[this.props.type || "Chart"](
this.props.container,
this.props.options
);
}
//Destroy chart before unmount.
componentWillUnmount() {
this.chart.destroy();
}
//Create the div which the chart will be rendered to.
render() {
return React.createElement('div', { id: this.props.container });
}
}
export default Chart;
์ด ์ค๋ ๋์ ๋ํด ์๋ ค์ฃผ์ @jon-a-nygaard์๊ฒ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
๐ ํฅ์๋ Webpack ์ง์. ๋๋ CodePen์์ ๋ชจ๋ React/Highsoft ์คํ์ ํด์์ง๋ง ๊ณง ์ ์ ํ ๋ ธ๋ ํ๊ฒฝ์ผ๋ก ์ด๋ํ ๊ฒ์ ๋๋ค. Webpack/Import/ES6์ ์ข์ ๊ฒ์ ๋๋ค.
highcharts 5๊ฐ ์๋ typescript/angular 2 ์์ฉ ํ๋ก๊ทธ๋จ์ "highcharts" ๋ชจ๋์์ "๋จ์" ๊ฐ์ ธ์ค๊ธฐ { Highcharts}์ ๋ํ ์์์ด ์์ต๋๊น? ํญ์ ์ฝ๊ฐ ํดํค ์ธ "Highcharts ํ์"์ ๋ํ ๋ฌธ์ ๋ง ์ฐพ์์ต๋๋ค ...
@ ์กด ์ด ๋๊ณ ๋ฅด
@Skuriles ์ด๋ค ์ ํ์ ์ ES6 ๋ฐ Babelify์์ Highcharts๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ์์ ๋๋ค.
@jon-a-nygaard ์ ๋ SystemJs๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค
@Skuriles ๋ค์์ SystemJS์ ํจ๊ป Highcharts๋ฅผ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ ์
๊ฐ๋ฅํ ๋นจ๋ฆฌ ์๋ํ๊ณ ์ฌ๊ธฐ์ ์๋ฃจ์
์ ๊ฒ์ํ๊ฒ ์ต๋๋ค!
๋น์ ์ ์๋ฅผ ๋ค์ด ์ฃผ์
์ ๋๋จํ ๊ฐ์ฌํฉ๋๋ค!!
๊ทํ์ ์ ์์ผ๋ก ์ธํด ๋ด ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ์ง๋ง ์ฌ์ ํ intellisens์์ typescript ์ค๋ฅ๊ฐ ๋ฐ์ํ๊ณ gulp-typescript ์ปดํ์ผ๋ฌ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค. ์ปดํ์ผ๋ ์ฑ์์ ์๋ํ์ง๋ง ๋ง์กฑ์ค๋ฝ์ง ์์ต๋๋ค.
import Highcharts from 'highcharts/highstock.js'๋ ์ฌ์ ํ ์ ์ ์๋ ๋ชจ๋์ ๋๋ค.
๋๋ ๋ํ typescript-babel ํ๋ฌ๊ทธ์ธ์ผ๋ก ์๋ํ์ง๋ง ์ด๊ฒ์ ๋ค๋ฅธ ๊ฒ๋ค์ ์ํด ์ปดํ์ผ๋ฌ๋ฅผ ๋์ก์ต๋๋ค.
๊ทธ๋์ ๋ง์ง๋ง์ผ๋ก systemjs ์์ด highstock.js ํ์ผ์ ์ง์ ๋ก๋ํ๊ณ ์ปดํ์ผ ์ค๋ฅ๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด TS ํ์ผ์์ Highcharts๋ฅผ ์ ์ธํ๊ธฐ ์ํด ๋ค์ ๋์๊ฐ์ต๋๋ค.
๋๋ ์ค์ ES6 ๋ชจ๋์ ๊ธฐ๋ค๋ฆฌ์ง๋ง ์ง๊ธ์ ๋ฆด๋ฆฌ์ค๋ฅผ ์ํด systemjs๊ฐ ์๋ ์ฌ์ ์ปดํ์ผ๋ ๋ฒ๋ค ๋ฒ์ ์ผ๋ก ์ ํํ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์ง๊ธ์ ๊ทธ๋๋ก ์ด ์ ์์ต๋๋ค!
@jon-a-nygaard ๋ด recat ์ฑ์์ ํ์ด์ฐจํธ๋ฅผ ๋ ๋๋งํ ์ ์์ต๋๋ค. ๋ด๊ฐ ์ป๋ ๋ชจ๋ ๊ฒ์ ๋น ํ๋ฉด์ ๋๋ค. ์ด๊ฒ์ด ๋ด๊ฐ ํ์ด ์ฐจํธ์ ๋ํด ์ํํ๋ ์์ ์ ๋๋ค.
import React, {Component, PropTypes} from 'react';
import Highcharts from 'highcharts/highcharts';
import styles from './styles/linechart.css';
import cssModules from 'react-css-modules';
import request from 'axios';
import moment from 'moment';
@cssModules(styles)
class LineChart extends Component {
constructor(props) {
super(props);
}
static propTypes = {
modules: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
PropTypes.array
]),
container: PropTypes.oneOfType([
PropTypes.string,
PropTypes.object,
PropTypes.array,
]),
options: PropTypes.oneOfType([
PropTypes.object,
PropTypes.array
]),
};
highchartsModules() {
if (this.props.modules) {
this.props.modules.forEach(function(module) {
module(Highcharts);
});
}
}
componentDidMount() {
const inComing = [];
const outGoing = [];
const xAxisData = [];
request.get('/dashboard/hourly', {
params: {
timezone: moment().utcOffset(),
date: '2016-07-06'
// date: moment(new Date()).format('YYYY-DD-MM')
}
}).then(response => {
response.data.forEach(item => {
const flattened = {};
const out = {};
flattened.name = item.date;
flattened.y = item.inCount;
out.name = item.date;
out.y = item.outCount;
xAxisData.push(item.hour);
inComing.push(flattened);
outGoing.push(flattened);
});
});
console.log('InComing data: ', inComing);
console.log('OutGoing data: ', outGoing);
console.log('X Axis data: ', xAxisData);
const chartOptions = {
tooltip: {
borderRadius: 20,
backgroundColor: 'rgba(18, 21, 23, 0.9)',
style: {
color: 'white',
},
shadow: false,
},
title: {
text: ''
},
subTitle: {
text: ''
},
xAxis: {
categories: xAxisData,
labels: {
enabled: false
},
crosshair: {
width: 1,
dashStyle: 'Dash',
color: 'black',
snap: false,
},
tickInterval: 2
},
legend: {
enabled: false,
},
series: [{
name: 'Incoming Calls',
data: inComing
}, {
name: 'Outgoing Calls',
data: outGoing
}
]
};
this.highchartsModules();
console.log('CHART OPTIONS: ', chartOptions);
if (typeof window !== 'undefined') {
this.chart = new Highcharts['Chart'](
this.props.container,
chartOptions
);
}
}
render() {
const { container } = this.props;
return (
// <div styleName="chart">
<div class="chart" id={container} />
// </div>
);
}
}
export default LineChart;
๋ด ์ฑ์์ ๋ค์๊ณผ ๊ฐ์ ๋ฐฉ์์ผ๋ก ์ด ํ์ด ์ฐจํธ๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
<LineChart container="chart" type="chart" />
๋์์ ์ฃผ์๋ฉด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค. ๋ฏธ๋ฆฌ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
์ง๊ธ๊น์ง ๋๋ ๊ทธ๊ฒ์ ์๋์์ผฐ๋ค.
import Highcharts from "highcharts";
์์คํ
์ง๋:
'highcharts': "npm:highcharts"
ํจํค์ง:
'highcharts': { main: "highstock", defaultExtension: "js"}
์ ์ผํ ๋ฌธ์ :
@types/highharts์ ๋ค์ ๋ฌธ์ ๊ฐ ์์ผ๋ฏ๋ก ์ปดํ์ผ๋ฌ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
Property 'StockChart' does not exist on type 'Static'.
ํ์ง๋ง ์ฑ์ ์ ์ด๋
๋๊ตฐ๊ฐ๊ฐ Rollup๊ณผ ํจ๊ป ๊ทธ๊ฒ์ ํ์๋ก ํ ๊ฒฝ์ฐ๋ฅผ ๋๋นํ์ฌ
์๋ํ๋ ๋ค์ ์ค์ ์ด ์์ต๋๋ค.
๋๋ vendor.ts ํ์ผ์์
import * as _highcharts from 'highcharts/highcharts';
...
export default {
...
_highcharts
};
๊ณต๊ธ์
์ฒด ๋ฒ๋ค์ ์์ฑํฉ๋๋ค.
๊ทธ๋ฐ ๋ค์ ๋ด app.rollup.js(๋ด ์ฑ ๋ฒ๋ค์ ๋ง๋ค๊ธฐ ์ํ ๊ตฌ์ฑ ํ์ผ)์์.
export default {
entry: 'src/main.ts',
dest: 'bundles/app.js',
format: 'iife',
sourceMap: true,
moduleName: 'app',
plugins: [
...
],
external: [
'highcharts/highcharts'
],
globals: {
...
'highcharts/highcharts': 'vendor._highcharts'
}
};
๊ทธ๋ฆฌ๊ณ ๋ง์ง๋ง์ผ๋ก ๋ด ์์ฉ ํ๋ก๊ทธ๋จ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค.
import Highcharts from 'highcharts/highcharts';
@jon-a-nygaard ๋ถํํ๋ ๊ทํ์ ์์ ๋ typescript ์ปดํ์ผ๋ฌ์์ ์๋ํ์ง ์์ต๋๋ค. 'highchart' has no default export
์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
@Skuriles ๋ ์ ๊ทผ ๋ฐฉ์์ด ํจ๊ณผ๊ฐ
'ํ์ด์ฐจํธ' ๊ฐ์ ธ์ค๊ธฐ;
(๊ทํ์ ๋ค๋ฅธ ์ ์ ์ธ์๋)
๊ฐ์ฌ ํด์
์์ ์๋ฃจ์ ์ค ์ด๋ ๊ฒ๋ ๋๋ฅผ ์ํด ์ต์ typescript ๋ฒ์ ์์ ์ ์๊ฒ ํจ๊ณผ๊ฐ ์์์ต๋๋ค.
import Highcharts from 'highcharts/highcharts.src.js';
import {default as HighchartsMore} from 'highcharts/highcharts-more.src.js';
HighchartsMore(Highcharts);
TypeScript์์ Highcharts๋ก ์์ ํ๋ ๋ถ๋ค ์ ์ํด ์์ ์ค์ ์
import * as Highcharts from 'highcharts'
import * as HighchartsMore from 'highcharts/highcharts-more.src.js'
HighchartsMore(Highcharts)
import Highcharts from 'highcharts'
๊ฐ ์๋ํ์ง ์๋ ์ด์ ๋ ๊ทธ๋ฌํ ๊ตฌ๋ฌธ์ ์ฌ์ฉํ๋ ค๋ฉด ๋ชจ๋์ด ๊ธฐ๋ณธ๊ฐ์ ๋ด๋ณด๋ด์ผ ํ์ง๋ง ๊ทธ๋ ์ง ์๊ธฐ ๋๋ฌธ์
๋๋ค. ๊ด์ฌ ์๋ ์ฌ๋๋ค์ ์ํด Typescript์๋ ๋ค์ํ ํ์์ ๊ฐ์ ธ์ค๊ธฐ์ ๋ํ ์ข์
์๋ ํ์ธ์ Jon, ์ ๊ฒฝ์ฐ์๋ Google ํฌ๋กฌ์์ ์ ๋๋ก ์๋ํ๊ณ ์ฐจํธ๋ ํ์๋ฉ๋๋ค. ๊ทธ๋ฌ๋ ์ด๋ฌํ ์ฐจํธ๋ mozilla์ ๊ฒฝ์ฐ์ ๋์ค์ง ์์ผ๋ฉฐ ์ฝ์์์๋ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ง ์์ต๋๋ค. ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ข ์๋ ค์ฃผ์ธ์.
์ด๊ฑฐ ํด๊ฒฐํ์ ๋ถ ๋์์ฃผ์ธ์
์๋ ํ์ธ์ @Sandipj38 ,
ES6 ๊ฐ์ ธ์ค๊ธฐ์๋ ๋ฌธ์ ๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ํฌ๋ผ์์ ์ฃผ์ ๋ฅผ ๋ง๋ค๊ฑฐ๋ ์ด๋ฉ์ผ( ์ธ๋ถ์ ๋ณด )์ ๋ณด๋ด์ฃผ์๊ฒ ์ต๋๊น? ๊ฐ์ฌ ํด์!
์๋
ํ์ญ๋๊น,
๋๋ ๋ฐ์ ๋ฐ ํ์ด ์ฐจํธ์ ํจ๊ป webpack์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
Uncaught TypeError: _highcharts2.default[(this.props.type || "Chart")] is not a constructor
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ง๋ง ํด๊ฒฐ์ฑ ์ ์ฐพ์ง ๋ชปํ์ต๋๋ค. ๋๋ ๊ฐ๋ฅํ ๋ชจ๋ ์์ด๊ณผ import/require 'highcharts', 'highcharts/highstock,'highcharts.js'์ ์กฐํฉ์ ์๋ํ์ง๋ง ์ด์ ๋ ์์ ํ ์ ํ์ ์ฌ์ง๊ฐ ์์ต๋๋ค.
var Chart = React.createClass({
componentDidMount: function () {
// Extend Highcharts with modules
if (this.props.modules) {
this.props.modules.forEach(function (module) {
module(Highcharts);
});
}
// Set container which the chart should render to.
this.chart = new Highcharts[this.props.type || "Chart"](
this.props.container,
this.props.options
);
},
//Destroy chart before unmount.
componentWillUnmount: function () {
this.chart.destroy();
},
//Create the div which the chart will be rendered to.
render: function () {
return React.createElement('div', { id: this.props.container });
}
}), element2;
์ฌ๊ธฐ ์ข ๋์์ฃผ์๊ฒ ์ด์?
@satishrao84 https://github.com/kirjs/react-highcharts ๋ฅผ ๋ณผ ๊ฐ์น๊ฐ ์์ ๊ฒ์ ๋๋ค. ์ ์๊ฒ ์ ๋ง์ต๋๋ค.
๋๋ ๋ฒ๋ค, js ํ์ผ์ ํฌํจ๋ ํ ๋ง์ ํจ๊ป ์ฑ๊ณต์ ์ผ๋ก webpack์ ์ฌ์ฉํ์ฌ ES6 ๊ฐ์ ธ์ค๊ธฐ ์์ ์ ํ๋ Highcharts์ Highstock์ ์ป์ ์ ์์์ต๋๋ค.
๋๋ https://github.com/pablojim/highcharts-ng/issues/624 ์์ highcharts-ng ๋ฆฌํฌ์งํ ๋ฆฌ์ ๋ฌธ์ ์ ๋ํด ์ผ์ต๋๋ค.
ํด๊ฒฐ์ฑ ์ highcharts/highstock์ ๊ฐ์ ธ์จ ๋ค์ ํ ๋ง๋ฅผ ๊ฐ์ ธ์จ ๋ค์ ๋ด ๋ฉ์ธ ์ฑ์์ highcharts-ng๋ฅผ ๊ฐ์ ธ์จ ๋ค์ ๋ด webpack ๊ตฌ์ฑ์ ๋ฒ๋ค ์ ์ญ์ Highcharts๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ด์๊ณ ์๋ํ์ต๋๋ค.
*์ฐธ๊ณ : 1.1.0์๋ Highcharts 5๊ฐ ํฌํจ๋์ด ์๊ณ Highcharts ์ ํ์ ๊ฐ์ ๋ก ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ highcharts-ng v1.0.1๋ก ๋ค์ด๊ทธ๋ ์ด๋ํด์ผ ํ์ต๋๋ค. Highstock์ด ํ์ํ๊ณ v1.0.1๋ก ๋๋๋ฆฌ๋ฉด Highcharts ์ข ์์ฑ์ด ํฌํจ๋์ง ์์ผ๋ฏ๋ก ํด๋ผ์ด์ธํธ ์ธก์์ Highchart๋ฅผ ์ด์ค ๋๋ ์ผ์ค ๋ก๋ํ์ง ์๊ณ ๋ ๋ด ๋ฒ๋ค์์ Highstock v6 ๋ฐ ๋ด ํ ๋ง๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
ํธ์ง: ๊ฐ์ ธ์ค๊ธฐ ES6 ๊ตฌ๋ฌธ์ผ๋ก๋ ๋ด๋ณด๋ด๊ธฐ ์์ ์ ์ํํ ์ ์์์ต๋๋ค.
import Highcharts from "highcharts/highstock";
import "../../js/highcharts.theme";
import "highcharts-ng";
import Exporter from "highcharts/modules/exporting";
// connect exporter to Highcharts bundle global
Exporter(Highcharts);
๊ทธ๋ฆฌ๊ณ webpack.config์์ ํ ๋ง์ ๋ํ ์ ์ญ Highcharts๋ฅผ ์ค์ ํฉ๋๋ค.
plugins: [
new webpack.ProvidePlugin({
jQuery: "jquery",
$: "jquery",
"window.jQuery": "jquery",
Highcharts: "highcharts/highstock"
})
]
@satishrao84 highstock ์ฐจํธ๋ฅผ ์ฌ์ฉํ๋ ค๊ณ ํ ๋ ๋์ผํ ์ค๋ฅ๊ฐ ๋ฐ์ํ์ง๋ง highchart๋ง ๋ก๋ํ์ต๋๋ค. Highstock JS์ ๋ํ webpack bundle.js๋ฅผ ํ์ธํ๊ณ ์์ถ๋์ด ์๋์ง ๋๋ Highcharts๊ฐ ๋์ ์๋์ง ํ์ธํ์ญ์์ค. import๋ก highstock ๋ก๋์ ๋ํ ์์ ๋ด ์๊ฒฌ์ ์ฐธ์กฐํ์ญ์์ค. highstock๊ณผ highcharts-ng๋ก ์์ ํ๋ ํ ๋ง๊ฐ ์์ง๋ง bundle.js์ ์๊ณ Highcharts๊ฐ ์ฃผ์ ๋๊ณ ์์ง๋ง ์์ง ๋ด๋ณด๋ด๊ธฐ๊ฐ ์๋ํ๋๋ก ํ ์ ์์ต๋๋ค. ๋ฉ๋ด ์์ด์ฝ์ด ์์ง ๋ด ์ฐจํธ์ ํ์๋์ง ์์ต๋๋ค.
์ด ๋ฌธ์ ๋ ์ด์ ์ปค๋ฐ 7da7361์์ ์ํ๋ ์ ๋ฐ์ดํธ๋ก ์ธํด ๋ซํ ๊ฒ์ผ๋ก ๊ฐ์ฃผ๋ฉ๋๋ค. ์ด ์ปค๋ฐ์ ES6์์ Highcharts๋ฅผ ๋ก๋ํ๋ ๋ฐฉ๋ฒ์ ๋ํ ๋ฌธ์๋ฅผ ๊ฐ์ ํฉ๋๋ค. ์ด๋ ์ฌ๊ธฐ์ ๋ฐ๋ณต๋๋ ๋ฌธ์ ๋ก ๊ฐ์ฃผ๋ฉ๋๋ค. ์ด ์ ๋ฐ์ดํธ๋ฅผ www.highcharts.com/docs ์๋ ์ ์ฉํ๊ฒ ์ต๋๋ค.
์๊ฐ์ด ์ง๋จ์ ๋ฐ๋ผ ์ด ๋ฌธ์ ๋ ์ฌ๋ฌ ๊ฐ์ง ๋ค๋ฅด์ง๋ง ์ ์ฌํ ๋ฌธ์ ๊ฐ ํผํฉ๋ ๊ฒ์ผ๋ก ๋ฐ์ ํ์ฌ ์ถ์ ํ๊ธฐ๊ฐ ์กฐ๊ธ ์ด๋ ค์์ก์ต๋๋ค. ์ด ์ฃผ์ ์ ์ ์ฌํ ๋ฌธ์ ๋ฅผ ๊ฒช๊ณ ์๋ ์ฌ๋์ด ์์ผ๋ฉด ์ ์ ํ ๋์์ ์ ๊ณตํ๋ ๊ฒ์ด ๋ ์ฌ์ธ ์ ์์ผ๋ฏ๋ก ์ ๋ฌธ์ ๋ฅผ ์์ฑํ์ญ์์ค.
ES6 ๋ชจ๋์ ๊ธฐ๋ค๋ฆฌ๋ ์ฌ๋๋ค์ ์ด์ #7186์ ๋ฐ๋ฅด์ญ์์ค.
์ด ์ฃผ์ ์ ๊ด๋ จํ์ฌ ์ง๋ฌธ์ด ์์ผ๋ฉด ์๊ฒฌ์ ๋ณด๋ด์ฃผ์ญ์์ค.
์น์ ํ๋
๊ทธ๊ฒ์ ์ฐพ๋ ๋ฐ ์๊ฐ์ด ๊ฑธ๋ ธ์ง ๋ง ๊ฒฐ๊ตญ ๋ ธ์ถ์ ์ฌ์ฉํ๊ฒ๋์์ต๋๋ค.
๊ฐ๋จํ ์ค์น ํ์ด ์ฐจํธ
๊ทธ๋ฆฌ๊ณ
๊ฐ์ ธ์ค๊ธฐ '๋
ธ์ถ?ํ์ด์ฐจํธ!ํ์ด์ฐจํธ/ํ์ด์ฐจํธ';
@ omer123456 ์ ์๋ฃจ์ ์ ๋ฌธ์ ๋ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค๋ ๊ฒ์ ๋๋ค.
BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders.
You need to specify 'expose-loader' instead of 'expose',
see https://webpack.js.org/guides/migrating/#automatic-loader-module-name-extension-removed
์๋ํ๋ ํ ๊ฐ์ง ๋ฐฉ๋ฒ์
๋น์ ์ ๋ฉ์ธ js์์
import Highcharts from 'highcharts';
import 'highcharts-ng'
๊ทธ๋ฐ ๋ค์ webpack.config.js์ ์ ๊ท์น์ ์ถ๊ฐํฉ๋๋ค.
{
test: require.resolve('highcharts'),
use:[{
loader: 'expose-loader',
options: 'Highcharts'
}]
}
์ด๊ฒ์ ๋ํ Cannot read property 'Chart' of null
์ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํฉ๋๋ค.
์ด ์ค๋ ๋์ ์ธ๊ธ๋์ด ์์ง๋ง ๋์น๊ธฐ ์ฝ์ต๋๋ค. ์ต์ ๋ฒ์ ์ highcharts์๋ ์์๋๋ก ์๋ํ๋ ์ค์ es6 ๋ชจ๋์ด ์์ต๋๋ค.
https://github.com/highcharts/highcharts/issues/7186
์จ๋ผ์ธ ๋ฌธ์์์ ๊ทธ๋ค์ ๋ํ ์ธ๊ธ์ด ์ฌ์ ํ ๋๋ฝ๋ ๊ฒ์ผ๋ก ๋ณด์ด์ง๋ง-
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
๋๋ webpack ng es6์ ์ฌ์ฉํ๊ณ ์์ผ๋ฉฐ ์๋์ํค๋ ์ ์ผํ ๋ฐฉ๋ฒ์
๋๊ตฐ๊ฐ๊ฐ ๊ฐ์ ธ์ค๊ธฐ ๊ตฌ๋ฌธ์ ์ฌ์ฉํ์ฌ ์ด ์์ ์ ์ํํ๋ ๋ฐฉ๋ฒ์ ์๊ณ ์๋ค๋ฉด ํ์ ํด ์ฃผ์ญ์์ค.