mirror of
https://github.com/aleleba/chartjs-2-react.git
synced 2025-07-03 04:08:18 -06:00
Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
fe3bf8702e | |||
77ed20aa45 | |||
0d0304ae86 | |||
92599328ad | |||
783d248f1e | |||
5170fae311 | |||
c8306d2382 |
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
> Libreria de chart.js para React.js
|
> Libreria de chart.js para React.js
|
||||||
|
|
||||||
[](https://www.npmjs.com/package/chart-2-react) [](https://standardjs.com)
|
[](https://www.npmjs.com/package/chartjs-2-react) [](https://standardjs.com)
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
|
16003
example/package-lock.json
generated
16003
example/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,15 @@
|
|||||||
{
|
{
|
||||||
"name": "chart-2-react-example",
|
"name": "chartjs-2-react-example",
|
||||||
"homepage": "https://aleleba.github.io/chart-2-react",
|
"homepage": "https://aleleba.github.io/chartjs-2-react",
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"chartjs-2-react": "file:..",
|
||||||
"prop-types": "^15.6.2",
|
"prop-types": "^15.6.2",
|
||||||
"react": "^16.4.1",
|
"react": "^16.4.1",
|
||||||
"react-dom": "^16.4.1",
|
"react-dom": "^16.4.1",
|
||||||
"react-scripts": "^1.1.4",
|
"react-scripts": "^1.1.4"
|
||||||
"chart-2-react": "file:.."
|
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "react-scripts start",
|
"start": "react-scripts start",
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
|
||||||
|
|
||||||
<title>chart-2-react</title>
|
<title>chartjs-2-react</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"short_name": "chart-2-react",
|
"short_name": "chartjs-2-react",
|
||||||
"name": "chart-2-react",
|
"name": "chartjs-2-react",
|
||||||
"start_url": "./index.html",
|
"start_url": "./index.html",
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"theme_color": "#000000",
|
"theme_color": "#000000",
|
||||||
|
@ -1,13 +1,28 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
import { RadialGaugue } from 'chart-2-react'
|
import { RadialGauge, Bar, Line } from 'chartjs-2-react';
|
||||||
|
|
||||||
export default class App extends Component {
|
export default class App extends Component {
|
||||||
render () {
|
render () {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{maxWidth: '600px', marginTop: '25px'}}>
|
<div style={{paddingBottom: '100px'}}>
|
||||||
<h3 style={{textAlign: 'center'}}>RadialGaugue Component:</h3>
|
|
||||||
<RadialGaugue />
|
<div style={{maxWidth: '600px', marginTop: '25px', margin: 'auto'}}>
|
||||||
|
<h3 style={{textAlign: 'center'}}>RadialGauge Component:</h3>
|
||||||
|
<RadialGauge />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{maxWidth: '600px', marginTop: '25px', margin: 'auto'}}>
|
||||||
|
<h3 style={{textAlign: 'center'}}>Bar Component:</h3>
|
||||||
|
<Bar />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div style={{maxWidth: '600px', marginTop: '25px', margin: 'auto'}}>
|
||||||
|
<h3 style={{textAlign: 'center'}}>Line Component:</h3>
|
||||||
|
<Line />
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
27
package-lock.json
generated
27
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "chart-2-react",
|
"name": "chartjs-2-react",
|
||||||
"version": "1.0.0",
|
"version": "1.0.13",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -8956,8 +8956,7 @@
|
|||||||
"js-tokens": {
|
"js-tokens": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
|
||||||
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==",
|
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"js-yaml": {
|
"js-yaml": {
|
||||||
"version": "3.13.1",
|
"version": "3.13.1",
|
||||||
@ -9291,8 +9290,7 @@
|
|||||||
"lodash": {
|
"lodash": {
|
||||||
"version": "4.17.15",
|
"version": "4.17.15",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
|
||||||
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==",
|
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"lodash._reinterpolate": {
|
"lodash._reinterpolate": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
@ -9371,7 +9369,6 @@
|
|||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
|
||||||
"integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
|
"integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"js-tokens": "^3.0.0 || ^4.0.0"
|
"js-tokens": "^3.0.0 || ^4.0.0"
|
||||||
}
|
}
|
||||||
@ -10079,8 +10076,7 @@
|
|||||||
"object-assign": {
|
"object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
|
||||||
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=",
|
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"object-copy": {
|
"object-copy": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
@ -12708,7 +12704,6 @@
|
|||||||
"version": "15.7.2",
|
"version": "15.7.2",
|
||||||
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.7.2.tgz",
|
||||||
"integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==",
|
"integrity": "sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"loose-envify": "^1.4.0",
|
"loose-envify": "^1.4.0",
|
||||||
"object-assign": "^4.1.1",
|
"object-assign": "^4.1.1",
|
||||||
@ -12905,6 +12900,15 @@
|
|||||||
"prop-types": "^15.6.2"
|
"prop-types": "^15.6.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"react-chartjs-2": {
|
||||||
|
"version": "2.9.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-chartjs-2/-/react-chartjs-2-2.9.0.tgz",
|
||||||
|
"integrity": "sha512-IYwqUUnQRAJ9SNA978vxulHJTcUFTJk2LDVfbAyk0TnJFZZG7+6U/2flsE4MCw6WCbBjTTypy8T82Ch7XrPtRw==",
|
||||||
|
"requires": {
|
||||||
|
"lodash": "^4.17.4",
|
||||||
|
"prop-types": "^15.5.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"react-dev-utils": {
|
"react-dev-utils": {
|
||||||
"version": "5.0.3",
|
"version": "5.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-5.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/react-dev-utils/-/react-dev-utils-5.0.3.tgz",
|
||||||
@ -13075,8 +13079,7 @@
|
|||||||
"react-is": {
|
"react-is": {
|
||||||
"version": "16.12.0",
|
"version": "16.12.0",
|
||||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.12.0.tgz",
|
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.12.0.tgz",
|
||||||
"integrity": "sha512-rPCkf/mWBtKc97aLL9/txD8DZdemK0vkA3JMLShjlJB3Pj3s+lpf1KaBzMfQrAmhMQB0n1cU/SUGgKKBCe837Q==",
|
"integrity": "sha512-rPCkf/mWBtKc97aLL9/txD8DZdemK0vkA3JMLShjlJB3Pj3s+lpf1KaBzMfQrAmhMQB0n1cU/SUGgKKBCe837Q=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"react-scripts": {
|
"react-scripts": {
|
||||||
"version": "1.1.5",
|
"version": "1.1.5",
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"name": "chartjs-2-react",
|
"name": "chartjs-2-react",
|
||||||
"version": "1.0.7",
|
"version": "1.1.0",
|
||||||
"description": "Libreria de chart.js para React.js",
|
"description": "Libreria de chart.js para React.js",
|
||||||
"author": "aleleba",
|
"author": "aleleba",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"repository": "aleleba/chart-2-react",
|
"repository": "aleleba/chartjs-2-react",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"module": "dist/index.es.js",
|
"module": "dist/index.es.js",
|
||||||
"jsnext:main": "dist/index.es.js",
|
"jsnext:main": "dist/index.es.js",
|
||||||
@ -60,6 +60,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chart.js": "^2.9.3",
|
"chart.js": "^2.9.3",
|
||||||
"chartjs-chart-radial-gauge": "^1.0.3"
|
"chartjs-chart-radial-gauge": "^1.0.3",
|
||||||
|
"react-chartjs-2": "^2.9.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
85
src/Bar.jsx
Normal file
85
src/Bar.jsx
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
|
import { Bar } from 'react-chartjs-2';
|
||||||
|
|
||||||
|
import ID from './Service/ID.js';
|
||||||
|
|
||||||
|
class BarComponent extends Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
let id = this.props.id ? this.props.id : ID(),
|
||||||
|
data = {
|
||||||
|
labels: ['Valor 1', 'Valor 2', 'Valor 3', 'Valor 4', 'Valor 5'],
|
||||||
|
datasets: [{
|
||||||
|
label: 'Valor',
|
||||||
|
data: [],
|
||||||
|
backgroundColor: 'rgba(75, 192, 192, 0.2)',
|
||||||
|
borderColor: 'rgba(75, 192, 192, 1)',
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options = {
|
||||||
|
responsive: true,
|
||||||
|
scales: {
|
||||||
|
yAxes: [{
|
||||||
|
ticks: {
|
||||||
|
beginAtZero: true
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
display: true,
|
||||||
|
position: 'bottom'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
legend = {
|
||||||
|
display: true,
|
||||||
|
position: 'bottom'
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let i = 0; i < 5 ; i ++){
|
||||||
|
|
||||||
|
let dato = Math.round(Math.random() * 25)
|
||||||
|
|
||||||
|
data.datasets[0].data.push(dato)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
id,
|
||||||
|
data,
|
||||||
|
width: 100,
|
||||||
|
height: 50,
|
||||||
|
options,
|
||||||
|
legend,
|
||||||
|
redraw: false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount(){
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
id: this.props.id !== undefined ? this.props.id : this.state.id,
|
||||||
|
data: this.props.data !== undefined ? this.props.data : this.state.data,
|
||||||
|
options: this.props.options !== undefined ? this.props.options : this.state.options,
|
||||||
|
width: this.props.width !== undefined ? this.props.width : this.state.width,
|
||||||
|
height: this.props.height !== undefined ? this.props.height : this.state.height,
|
||||||
|
legend: this.props.legend !== undefined ? this.props.legend : this.state.legend,
|
||||||
|
redraw: this.props.redraw !== undefined ? this.props.redraw : this.state.redraw
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
render(){
|
||||||
|
|
||||||
|
return(
|
||||||
|
<Bar id={this.state.id} data={this.state.data} options={this.state.options} width={this.state.width} height={this.state.height} legend={this.state.legend} redraw={this.state.redraw} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BarComponent
|
86
src/Line.jsx
Normal file
86
src/Line.jsx
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
|
||||||
|
import { Line } from 'react-chartjs-2';
|
||||||
|
|
||||||
|
import ID from './Service/ID.js';
|
||||||
|
|
||||||
|
class LineComponent extends Component {
|
||||||
|
|
||||||
|
constructor(props) {
|
||||||
|
|
||||||
|
super(props)
|
||||||
|
|
||||||
|
let id = this.props.id ? this.props.id : ID(),
|
||||||
|
data = {
|
||||||
|
labels: ['Valor 1', 'Valor 2', 'Valor 3', 'Valor 4', 'Valor 5'],
|
||||||
|
datasets: [{
|
||||||
|
label: 'Valor',
|
||||||
|
fill: false,
|
||||||
|
data: [],
|
||||||
|
backgroundColor: 'rgba(75, 192, 192, 0.2)',
|
||||||
|
borderColor: 'rgba(75, 192, 192, 1)',
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options = {
|
||||||
|
responsive: true,
|
||||||
|
scales: {
|
||||||
|
yAxes: [{
|
||||||
|
ticks: {
|
||||||
|
beginAtZero: true
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
display: true,
|
||||||
|
position: 'bottom'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
legend = {
|
||||||
|
display: true,
|
||||||
|
position: 'bottom'
|
||||||
|
}
|
||||||
|
|
||||||
|
for(let i = 0; i < 5 ; i ++){
|
||||||
|
|
||||||
|
let dato = Math.round(Math.random() * 25)
|
||||||
|
|
||||||
|
data.datasets[0].data.push(dato)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state = {
|
||||||
|
id,
|
||||||
|
data,
|
||||||
|
width: 100,
|
||||||
|
height: 50,
|
||||||
|
options,
|
||||||
|
legend,
|
||||||
|
redraw: false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount(){
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
id: this.props.id !== undefined ? this.props.id : this.state.id,
|
||||||
|
data: this.props.data !== undefined ? this.props.data : this.state.data,
|
||||||
|
options: this.props.options !== undefined ? this.props.options : this.state.options,
|
||||||
|
width: this.props.width !== undefined ? this.props.width : this.state.width,
|
||||||
|
height: this.props.height !== undefined ? this.props.height : this.state.height,
|
||||||
|
legend: this.props.legend !== undefined ? this.props.legend : this.state.legend,
|
||||||
|
redraw: this.props.redraw !== undefined ? this.props.redraw : this.state.redraw
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
render(){
|
||||||
|
|
||||||
|
return(
|
||||||
|
<Line id={this.state.id} data={this.state.data} options={this.state.options} width={this.state.width} height={this.state.height} legend={this.state.legend} redraw={this.state.redraw} fill={false} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LineComponent
|
@ -4,30 +4,38 @@ import Chart from 'chart.js';
|
|||||||
|
|
||||||
import 'chartjs-chart-radial-gauge/build/Chart.RadialGauge.umd.min.js';
|
import 'chartjs-chart-radial-gauge/build/Chart.RadialGauge.umd.min.js';
|
||||||
|
|
||||||
|
import ID from './Service/ID.js'
|
||||||
|
|
||||||
class RadialGauge extends Component {
|
class RadialGauge extends Component {
|
||||||
|
|
||||||
componentDidMount(){
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
|
||||||
var ctx = document.getElementById('chart').getContext('2d');
|
let porcentaje = Math.round(Math.random() * 100),
|
||||||
|
porcentajeTexto = `${porcentaje} %`
|
||||||
/*var gradientStroke = ctx.createLinearGradient(500, 0, 100, 0);
|
|
||||||
gradientStroke.addColorStop(0, "#2A969E");
|
let id = this.props.id ? this.props.id : ID()
|
||||||
gradientStroke.addColorStop(1, "#2A969E");*/
|
|
||||||
//gradientStroke.addColorStop(2, "#f49080");
|
|
||||||
|
|
||||||
var config
|
this.state = {
|
||||||
|
id,
|
||||||
|
chart: null,
|
||||||
|
porcentaje,
|
||||||
|
porcentajeTexto
|
||||||
|
}
|
||||||
|
|
||||||
var randomScalingFactor = function() {
|
}
|
||||||
return Math.round(Math.random() * 100);
|
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
componentDidMount() {
|
||||||
|
|
||||||
|
var ctx = document.getElementById(`${this.state.id}`).getContext('2d');
|
||||||
|
|
||||||
|
var config = {
|
||||||
type: 'radialGauge',
|
type: 'radialGauge',
|
||||||
data: {
|
data: {
|
||||||
labels: this.props.config ? (this.props.config.data ? (this.props.config.data.labels || ["Porcentaje"]) : ["Porcentaje"]) : ["Porcentaje"],
|
labels: this.props.config ? (this.props.config.data ? (this.props.config.data.labels || ["Porcentaje"]) : ["Porcentaje"]) : ["Porcentaje"],
|
||||||
datasets: [
|
datasets: [
|
||||||
{
|
{
|
||||||
data: this.props.config ? ((this.props.config.data) ? (this.props.config.data.datasets !== undefined ? [this.props.config.data.datasets.data] : [randomScalingFactor()]) : [randomScalingFactor()]) : [randomScalingFactor()],
|
data: this.props.config ? ((this.props.config.data) ? (this.props.config.data.datasets !== undefined ? [this.props.config.data.datasets.data] : [this.state.porcentaje]) : [this.state.porcentaje]) : [this.state.porcentaje],
|
||||||
backgroundColor: this.props.config ? ( this.props.config.data ? (((this.props.config.data.datasets !== undefined) && (this.props.config.data.datasets.backgroundColor)) ? this.props.config.data.datasets.backgroundColor : '#2A969E') : '#2A969E') : '#2A969E',
|
backgroundColor: this.props.config ? ( this.props.config.data ? (((this.props.config.data.datasets !== undefined) && (this.props.config.data.datasets.backgroundColor)) ? this.props.config.data.datasets.backgroundColor : '#2A969E') : '#2A969E') : '#2A969E',
|
||||||
borderWidth: this.props.config ? ( this.props.config.data ? (((this.props.config.data.datasets !== undefined) && (this.props.config.data.datasets.borderWidth)) ? this.props.config.data.datasets.borderWidth : 0) : 0) : 0,
|
borderWidth: this.props.config ? ( this.props.config.data ? (((this.props.config.data.datasets !== undefined) && (this.props.config.data.datasets.borderWidth)) ? this.props.config.data.datasets.borderWidth : 0) : 0) : 0,
|
||||||
label: this.props.config ? ( this.props.config.data ? (((this.props.config.data.datasets !== undefined) && (this.props.config.data.datasets.label)) ? this.props.config.data.datasets.label : "Porcentaje") : "Porcentaje") : "Porcentaje"
|
label: this.props.config ? ( this.props.config.data ? (((this.props.config.data.datasets !== undefined) && (this.props.config.data.datasets.label)) ? this.props.config.data.datasets.label : "Porcentaje") : "Porcentaje") : "Porcentaje"
|
||||||
@ -87,15 +95,31 @@ class RadialGauge extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.setState({
|
||||||
new Chart(ctx, config);
|
chart: new Chart(ctx, config)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
|
||||||
<canvas id="chart" />
|
if (this.state.chart !== null) {
|
||||||
)
|
|
||||||
|
this.props.config ? ((this.props.config.data) ? (this.props.config.data.datasets !== undefined ? (this.state.chart.data.datasets[0].data[0] = this.props.config.data.datasets.data) : [this.state.porcentaje]) : [this.state.porcentaje]) : [this.state.porcentaje]
|
||||||
|
|
||||||
|
//this.state.chart.data.datasets[0].data[0] = this.props.config.data.datasets.data)
|
||||||
|
|
||||||
|
this.props.config ? ((this.props.config.options) ? (this.props.config.options.centerArea !== undefined ? (this.state.chart.options.centerArea.text = this.props.config.options.centerArea.text) : null) : null) : null
|
||||||
|
|
||||||
|
//this.state.chart.options.centerArea.text = this.props.config.options.centerArea.text
|
||||||
|
|
||||||
|
this.state.chart.update();
|
||||||
|
|
||||||
|
return <canvas id={`${this.state.id}`} />
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return <canvas id={`${this.state.id}`} />
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
src/Service/ID.js
Normal file
25
src/Service/ID.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// Generate unique IDs for use as pseudo-private/protected names.
|
||||||
|
// Similar in concept to
|
||||||
|
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
|
||||||
|
//
|
||||||
|
// The goals of this function are twofold:
|
||||||
|
//
|
||||||
|
// * Provide a way to generate a string guaranteed to be unique when compared
|
||||||
|
// to other strings generated by this function.
|
||||||
|
// * Make the string complex enough that it is highly unlikely to be
|
||||||
|
// accidentally duplicated by hand (this is key if you're using `ID`
|
||||||
|
// as a private/protected name on an object).
|
||||||
|
//
|
||||||
|
// Use:
|
||||||
|
//
|
||||||
|
// var privateName = ID();
|
||||||
|
// var o = { 'public': 'foo' };
|
||||||
|
// o[privateName] = 'bar';
|
||||||
|
var ID = function () {
|
||||||
|
// Math.random should be unique because of its seeding algorithm.
|
||||||
|
// Convert it to base 36 (numbers + letters), and grab the first 9 characters
|
||||||
|
// after the decimal.
|
||||||
|
return '_' + Math.random().toString(36).substr(2, 9);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ID
|
10
src/index.js
10
src/index.js
@ -1,3 +1,9 @@
|
|||||||
import RadialGaugue from './RadialGauge.jsx';
|
import RadialGauge from './RadialGauge.jsx';
|
||||||
|
import Bar from './Bar.jsx';
|
||||||
|
import Line from './Line.jsx';
|
||||||
|
|
||||||
export default { RadialGaugue }
|
export { RadialGauge }
|
||||||
|
export { Bar }
|
||||||
|
export { Line }
|
||||||
|
|
||||||
|
export default { RadialGauge }
|
||||||
|
Reference in New Issue
Block a user