mirror of
https://github.com/aleleba/chartjs-2-react.git
synced 2025-07-03 04:08:18 -06:00
Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
92599328ad | |||
783d248f1e | |||
5170fae311 |
72
example/package-lock.json
generated
72
example/package-lock.json
generated
@ -1661,8 +1661,43 @@
|
|||||||
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz",
|
"resolved": "https://registry.npmjs.org/chardet/-/chardet-0.4.2.tgz",
|
||||||
"integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I="
|
"integrity": "sha1-tUc7M9yXxCTl2Y3IfVXU2KKci/I="
|
||||||
},
|
},
|
||||||
|
"chart.js": {
|
||||||
|
"version": "2.9.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-2.9.3.tgz",
|
||||||
|
"integrity": "sha512-+2jlOobSk52c1VU6fzkh3UwqHMdSlgH1xFv9FKMqHiNCpXsGPQa/+81AFa+i3jZ253Mq9aAycPwDjnn1XbRNNw==",
|
||||||
|
"requires": {
|
||||||
|
"chartjs-color": "^2.1.0",
|
||||||
|
"moment": "^2.10.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"chartjs-2-react": {
|
"chartjs-2-react": {
|
||||||
"version": "file:.."
|
"version": "file:..",
|
||||||
|
"requires": {
|
||||||
|
"chart.js": "^2.9.3",
|
||||||
|
"chartjs-chart-radial-gauge": "^1.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"chartjs-chart-radial-gauge": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/chartjs-chart-radial-gauge/-/chartjs-chart-radial-gauge-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-orm3XGWww46rmsKvAnwyOhXA5MtVfjsxfD463iE/gBBVOfozeFnsydZWx8Rqj5fy3DoxZROYUCR02RexvoMsHQ=="
|
||||||
|
},
|
||||||
|
"chartjs-color": {
|
||||||
|
"version": "2.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/chartjs-color/-/chartjs-color-2.4.1.tgz",
|
||||||
|
"integrity": "sha512-haqOg1+Yebys/Ts/9bLo/BqUcONQOdr/hoEr2LLTRl6C5LXctUdHxsCYfvQVg5JIxITrfCNUDr4ntqmQk9+/0w==",
|
||||||
|
"requires": {
|
||||||
|
"chartjs-color-string": "^0.6.0",
|
||||||
|
"color-convert": "^1.9.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"chartjs-color-string": {
|
||||||
|
"version": "0.6.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/chartjs-color-string/-/chartjs-color-string-0.6.0.tgz",
|
||||||
|
"integrity": "sha512-TIB5OKn1hPJvO7JcteW4WY/63v6KwEdt6udfnDE9iCAZgy+V4SrbSxoIbTw/xkUIapjEI4ExGtD0+6D3KyFd7A==",
|
||||||
|
"requires": {
|
||||||
|
"color-name": "^1.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"chokidar": {
|
"chokidar": {
|
||||||
"version": "2.1.8",
|
"version": "2.1.8",
|
||||||
@ -3462,9 +3497,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"esprima": {
|
"esprima": {
|
||||||
"version": "2.7.3",
|
"version": "4.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz",
|
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
|
||||||
"integrity": "sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE="
|
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
|
||||||
},
|
},
|
||||||
"esquery": {
|
"esquery": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
@ -5808,12 +5843,12 @@
|
|||||||
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
|
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
|
||||||
},
|
},
|
||||||
"js-yaml": {
|
"js-yaml": {
|
||||||
"version": "3.7.0",
|
"version": "3.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
|
||||||
"integrity": "sha1-XJZ93YN6m/3KXy3oQlOr6KHAO4A=",
|
"integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"argparse": "^1.0.7",
|
"argparse": "^1.0.7",
|
||||||
"esprima": "^2.6.0"
|
"esprima": "^4.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"jsbn": {
|
"jsbn": {
|
||||||
@ -6401,6 +6436,11 @@
|
|||||||
"minimist": "0.0.8"
|
"minimist": "0.0.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"moment": {
|
||||||
|
"version": "2.24.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/moment/-/moment-2.24.0.tgz",
|
||||||
|
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg=="
|
||||||
|
},
|
||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
@ -9939,6 +9979,22 @@
|
|||||||
"mkdirp": "~0.5.1",
|
"mkdirp": "~0.5.1",
|
||||||
"sax": "~1.2.1",
|
"sax": "~1.2.1",
|
||||||
"whet.extend": "~0.9.9"
|
"whet.extend": "~0.9.9"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"esprima": {
|
||||||
|
"version": "2.7.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz",
|
||||||
|
"integrity": "sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE="
|
||||||
|
},
|
||||||
|
"js-yaml": {
|
||||||
|
"version": "3.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.7.0.tgz",
|
||||||
|
"integrity": "sha1-XJZ93YN6m/3KXy3oQlOr6KHAO4A=",
|
||||||
|
"requires": {
|
||||||
|
"argparse": "^1.0.7",
|
||||||
|
"esprima": "^2.6.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sw-precache": {
|
"sw-precache": {
|
||||||
|
@ -5,9 +5,13 @@ import { RadialGauge } 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>
|
||||||
<h3 style={{textAlign: 'center'}}>RadialGauge Component:</h3>
|
|
||||||
<RadialGauge />
|
<div style={{maxWidth: '600px', marginTop: '25px'}}>
|
||||||
|
<h3 style={{textAlign: 'center'}}>RadialGauge Component:</h3>
|
||||||
|
<RadialGauge />
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "chartjs-2-react",
|
"name": "chartjs-2-react",
|
||||||
"version": "1.0.0",
|
"version": "1.0.10",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "chartjs-2-react",
|
"name": "chartjs-2-react",
|
||||||
"version": "1.0.8",
|
"version": "1.0.10",
|
||||||
"description": "Libreria de chart.js para React.js",
|
"description": "Libreria de chart.js para React.js",
|
||||||
"author": "aleleba",
|
"author": "aleleba",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -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
|
Reference in New Issue
Block a user