Compare commits

...

10 Commits
1.0.7 ... 1.1.3

Author SHA1 Message Date
433a810c46 Se agrega ejemplo de MultiAxis Chart.
Se sube a version 1.1.3
Se sube a GitHub 1.1.3
2020-07-10 19:05:18 +00:00
af8bee047b Se agrega la funcion para que cuando se actualice props se actualice la grafica.
Se sube a version 1.1.2
Se sube a GitHub 1.1.2
Se sube a NPM 1.1.2
2020-02-12 08:56:44 -06:00
60cae61ef1 Se Elimina la libreria de react-chartjs-2 y trabjar directamente con chart.js para solucionar el problema al momento de actualizar data.
Se sube a version 1.1.1
Se sube a GitHub 1.1.1
2020-02-11 09:26:23 -06:00
fe3bf8702e Se agrega el Repositorio de npm que es en Readme.
Se agrega la libreria react-chartjs-2 para agregar las graficas de Barras y de Lineas.
Se sube a version 1.1.0
Se sube a GitHub 1.1.0
2020-02-08 15:15:09 -06:00
77ed20aa45 Se arregla el problema con el package-lock.json de example.
Se sube a version 1.0.13
Se sube a GitHub 1.0.13
Se sube a NPM 1.0.13
2019-12-07 02:15:33 -06:00
0d0304ae86 se arregla el problema de la version en package.json.
Se sube a version 1.0.12
Se sube a GitHub 1.0.12
Se sube a NPM 1.0.12
2019-12-07 00:58:17 -06:00
92599328ad Se arreglan las vulnerabilidades en los package-lock.json.
Se sube a version 1.0.11
Se sube a GitHub 1.0.11
Se sube a NPM 1.0.11
2019-12-07 00:48:14 -06:00
783d248f1e Se soluciona el problema de que existan varios RadialGauge en el mismo componente agregandoles un id único.
Se sube a version 1.0.10
Se sube a GitHub 1.0.10
Se sube a NPM 1.0.10
2019-12-05 23:40:15 -06:00
5170fae311 Se mejora RadialGauge para que al actualizar la data se actualice RadialGauge.
Se sube a version 1.0.9
Se sube a GitHub 1.0.9
Se sube a NPM 1.0.9
2019-12-05 19:30:28 -06:00
c8306d2382 Se vuelve a empaquetar con create react library ya que se coloco el nombre mal.
Se sube a version 1.0.8
Se sube a GitHub 1.0.8
Se sube a NPM 1.0.8
2019-12-05 15:44:46 -06:00
13 changed files with 961 additions and 15453 deletions

View File

@ -2,7 +2,7 @@
> Libreria de chart.js para React.js
[![NPM](https://img.shields.io/npm/v/chart-2-react.svg)](https://www.npmjs.com/package/chart-2-react) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![NPM](https://img.shields.io/npm/v/chart-2-react.svg)](https://www.npmjs.com/package/chartjs-2-react) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
## Install

16003
example/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,15 +1,15 @@
{
"name": "chart-2-react-example",
"homepage": "https://aleleba.github.io/chart-2-react",
"name": "chartjs-2-react-example",
"homepage": "https://aleleba.github.io/chartjs-2-react",
"version": "0.0.0",
"license": "MIT",
"private": true,
"dependencies": {
"chartjs-2-react": "file:..",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"react-scripts": "^1.1.4",
"chart-2-react": "file:.."
"react-scripts": "^1.1.4"
},
"scripts": {
"start": "react-scripts start",

View File

@ -7,7 +7,7 @@
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<title>chart-2-react</title>
<title>chartjs-2-react</title>
</head>
<body>

View File

@ -1,6 +1,6 @@
{
"short_name": "chart-2-react",
"name": "chart-2-react",
"short_name": "chartjs-2-react",
"name": "chartjs-2-react",
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",

View File

@ -1,14 +1,100 @@
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 {
render () {
return (
<div style={{maxWidth: '600px', marginTop: '25px'}}>
<h3 style={{textAlign: 'center'}}>RadialGaugue Component:</h3>
<RadialGaugue />
<div style={{paddingBottom: '100px'}}>
<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 style={{maxWidth: '600px', marginTop: '25px', margin: 'auto'}}>
<h3 style={{textAlign: 'center'}}>Multi Axis Bar Line Component:</h3>
<Bar config={{
data: {
datasets: [{
label: 'Bar Dataset',
data: [10, 20, 30, 40],
yAxisID: 'A',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)'
},
{
label: 'Bar Dataset',
data: [10, 20, 30, 40],
yAxisID: 'A',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)'
},
{
label: 'Bar Dataset',
data: [10, 20, 30, 40],
yAxisID: 'A',
backgroundColor: 'rgba(75, 192, 192, 0.2)',
borderColor: 'rgba(75, 192, 192, 1)'
},
{
// Changes this dataset to become a line
type: 'line',
yAxisID: 'B',
label: 'Line Dataset',
data: [5, 8, 10, 30],
backgroundColor: 'transparent',
borderColor: 'rgba(75, 192, 192, 1)'
},
{
// Changes this dataset to become a line
type: 'line',
yAxisID: 'B',
label: 'Line Dataset',
data: [15, 20, 25, 30],
backgroundColor: 'transparent',
borderColor: 'rgba(75, 192, 192, 1)'
}],
labels: ['January', 'February', 'March', 'April'],
},
options: {
scales: {
yAxes: [{
id: 'A',
type: 'linear',
position: 'left',
/*ticks: {
max: 1,
min: 0
}*/
}, {
id: 'B',
type: 'linear',
position: 'right',
/*ticks: {
max: 1,
min: 0
}*/
}]
}
}
}}/>
</div>
</div>
)
}
}

4
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "chart-2-react",
"version": "1.0.0",
"name": "chartjs-2-react",
"version": "1.1.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,10 +1,10 @@
{
"name": "chartjs-2-react",
"version": "1.0.7",
"version": "1.1.3",
"description": "Libreria de chart.js para React.js",
"author": "aleleba",
"license": "MIT",
"repository": "aleleba/chart-2-react",
"repository": "aleleba/chartjs-2-react",
"main": "dist/index.js",
"module": "dist/index.es.js",
"jsnext:main": "dist/index.es.js",

96
src/Bar.jsx Normal file
View File

@ -0,0 +1,96 @@
import React, { Component } from 'react';
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'
}
}
for(let i = 0; i < 5 ; i ++){
let dato = Math.round(Math.random() * 25)
data.datasets[0].data.push(dato)
}
this.state = {
id,
chart: null,
data,
options
}
}
componentDidMount(){
var ctx = document.getElementById(`${this.state.id}`).getContext('2d');
let config = {
type: 'bar',
data: (this.props.config !== undefined) && (this.props.config.data !== undefined) ? this.props.config.data : this.state.data,
options: (this.props.config !== undefined) && (this.props.config.options !== undefined) ? this.props.config.options : this.state.options
}
this.setState({
id: this.props.id !== undefined ? this.props.id : this.state.id,
chart: new Chart(ctx, config)
})
}
render(){
if (this.state.chart !== null) {
if((this.props.config !== undefined) && (this.props.config.data !== undefined)){
this.state.chart.data.labels = this.props.config.data.labels
this.state.chart.data.datasets = this.props.config.data.datasets
}
if((this.props.config !== undefined) && (this.props.config.options !== undefined)){
this.state.chart.options = this.props.config.options
}
this.state.chart.update();
return <canvas id={`${this.state.id}`} />
} else {
return <canvas id={`${this.state.id}`} />
}
}
}
export default BarComponent

98
src/Line.jsx Normal file
View File

@ -0,0 +1,98 @@
import React, { Component } from 'react';
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'
}
}
for(let i = 0; i < 5 ; i ++){
let dato = Math.round(Math.random() * 25)
data.datasets[0].data.push(dato)
}
this.state = {
id,
chart: null,
data,
options
}
}
componentDidMount(){
var ctx = document.getElementById(`${this.state.id}`).getContext('2d');
let config = {
type: 'line',
data: (this.props.config !== undefined) && (this.props.config.data !== undefined) ? this.props.config.data : this.state.data,
options: (this.props.config !== undefined) && (this.props.config.options !== undefined) ? this.props.config.options : this.state.options
}
this.setState({
id: this.props.id !== undefined ? this.props.id : this.state.id,
chart: new Chart(ctx, config)
})
}
render(){
if (this.state.chart !== null) {
if((this.props.config !== undefined) && (this.props.config.data !== undefined)){
this.state.chart.data.labels = this.props.config.data.labels
this.state.chart.data.datasets = this.props.config.data.datasets
}
if((this.props.config !== undefined) && (this.props.config.options !== undefined)){
this.state.chart.options = this.props.config.options
}
this.state.chart.update();
return <canvas id={`${this.state.id}`} />
} else {
return <canvas id={`${this.state.id}`} />
}
}
}
export default LineComponent

View File

@ -4,30 +4,38 @@ import Chart from 'chart.js';
import 'chartjs-chart-radial-gauge/build/Chart.RadialGauge.umd.min.js';
import ID from './Service/ID.js'
class RadialGauge extends Component {
componentDidMount(){
constructor(props) {
super(props)
var ctx = document.getElementById('chart').getContext('2d');
/*var gradientStroke = ctx.createLinearGradient(500, 0, 100, 0);
gradientStroke.addColorStop(0, "#2A969E");
gradientStroke.addColorStop(1, "#2A969E");*/
//gradientStroke.addColorStop(2, "#f49080");
let porcentaje = Math.round(Math.random() * 100),
porcentajeTexto = `${porcentaje} %`
let id = this.props.id ? this.props.id : ID()
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',
data: {
labels: this.props.config ? (this.props.config.data ? (this.props.config.data.labels || ["Porcentaje"]) : ["Porcentaje"]) : ["Porcentaje"],
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',
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"
@ -87,15 +95,31 @@ class RadialGauge extends Component {
}
};
new Chart(ctx, config);
this.setState({
chart: new Chart(ctx, config)
})
}
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
View 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

View File

@ -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 }