feat: added all simple chartjs tyoes
This commit is contained in:
parent
ea6c13bf0c
commit
a8633bdc70
@ -1,3 +1,3 @@
|
|||||||
export default [
|
export default [
|
||||||
'line', 'bar', 'radar', 'doughnut', 'pie', 'bubble', 'scatter', 'area', 'mixed'
|
'line', 'bar', 'radar', 'doughnut', 'pie', 'polar', /*'bubble', 'scatter', 'area', 'mixed' */
|
||||||
]
|
]
|
3
src/Constants/chartjsTypes.js
Normal file
3
src/Constants/chartjsTypes.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export default [
|
||||||
|
'line', 'bar', 'radar', 'doughnut', 'pie', 'polar', /*'bubble', 'scatter', 'area', 'mixed' */
|
||||||
|
]
|
@ -2,31 +2,90 @@ import Chart from './Chart.js'
|
|||||||
import { GroupByNodule } from 'lovelacejs'
|
import { GroupByNodule } from 'lovelacejs'
|
||||||
|
|
||||||
class ChartJsDataset extends Chart {
|
class ChartJsDataset extends Chart {
|
||||||
get doughnut () {
|
constructor (props) {
|
||||||
const groupByNodule = new GroupByNodule({
|
super(props)
|
||||||
|
|
||||||
|
this.groupByNodule = new GroupByNodule({
|
||||||
id: this.id,
|
id: this.id,
|
||||||
label: `${this.label} groupedBy ${this.groupByValue}`,
|
label: `${this.label} groupedBy ${this.groupByValue}`,
|
||||||
tables: [this.table],
|
tables: [this.table],
|
||||||
groupByValue: this.groupByValue
|
groupByValue: this.groupByValue
|
||||||
}).export()
|
}).export()
|
||||||
|
|
||||||
const labels = Object.keys(groupByNodule)
|
this.chartLabels = Object.keys(this.groupByNodule)
|
||||||
|
|
||||||
let groupByCounts = []
|
this.groupByCounts = []
|
||||||
for (let key in groupByNodule) {
|
for (let key in this.groupByNodule) {
|
||||||
groupByCounts.push(groupByNodule[key].length)
|
this.groupByCounts.push(this.groupByNodule[key].length)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get bar () {
|
||||||
return {
|
return {
|
||||||
labels: labels,
|
labels: this.chartLabels,
|
||||||
|
datasets: [{
|
||||||
|
label: this.label,
|
||||||
|
backgroundColor: `rgb(${this._generateRandomRGBNumber()}, ${this._generateRandomRGBNumber()}, ${this._generateRandomRGBNumber()})`,
|
||||||
|
data: this.groupByCounts
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get doughnut () {
|
||||||
|
return {
|
||||||
|
labels: this.chartLabels,
|
||||||
datasets: [{
|
datasets: [{
|
||||||
label: `${this.label} groupedBy ${this.groupByValue}`,
|
label: `${this.label} groupedBy ${this.groupByValue}`,
|
||||||
data: groupByCounts,
|
data: this.groupByCounts,
|
||||||
backgroundColor: this._getbackgroundColors()
|
backgroundColor: this._getbackgroundColors()
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get line () {
|
||||||
|
return {
|
||||||
|
labels: this.chartLabels,
|
||||||
|
datasets: [{
|
||||||
|
label: this.label,
|
||||||
|
backgroundColor: `rgb(${this._generateRandomRGBNumber()}, ${this._generateRandomRGBNumber()}, ${this._generateRandomRGBNumber()})`,
|
||||||
|
data: this.groupByCounts
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get pie () {
|
||||||
|
return {
|
||||||
|
labels: this.chartLabels,
|
||||||
|
datasets: [{
|
||||||
|
label: `${this.label} groupedBy ${this.groupByValue}`,
|
||||||
|
data: this.groupByCounts,
|
||||||
|
backgroundColor: this._getbackgroundColors()
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get polar () {
|
||||||
|
return {
|
||||||
|
labels: this.chartLabels,
|
||||||
|
datasets: [{
|
||||||
|
label: this.label,
|
||||||
|
backgroundColor: this._getbackgroundColors(),
|
||||||
|
data: this.groupByCounts
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get radar () {
|
||||||
|
return {
|
||||||
|
labels: this.chartLabels,
|
||||||
|
datasets: [{
|
||||||
|
label: this.label,
|
||||||
|
backgroundColor: `rgba(${this._generateRandomRGBNumber()}, ${this._generateRandomRGBNumber()}, ${this._generateRandomRGBNumber()}, 0.2)`,
|
||||||
|
data: this.groupByCounts
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_generateRandomRGBNumber () {
|
_generateRandomRGBNumber () {
|
||||||
const max = 255
|
const max = 255
|
||||||
const min = 0
|
const min = 0
|
||||||
@ -36,7 +95,7 @@ class ChartJsDataset extends Chart {
|
|||||||
_getbackgroundColors () {
|
_getbackgroundColors () {
|
||||||
const labels = this.labels
|
const labels = this.labels
|
||||||
const backgroundColors = labels.map(l => {
|
const backgroundColors = labels.map(l => {
|
||||||
return `rgb(${this._generateRandomRGBNumber()}, ${this._generateRandomRGBNumber()}, ${this._generateRandomRGBNumber()})`
|
return `rgba(${this._generateRandomRGBNumber()}, ${this._generateRandomRGBNumber()}, ${this._generateRandomRGBNumber()}, 0.4)`
|
||||||
})
|
})
|
||||||
return backgroundColors
|
return backgroundColors
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { uuid } from 'uuidv4'
|
import { uuid } from 'uuidv4'
|
||||||
import ChartJsDataset from '../../Models/Chart/ChartjsDataset'
|
import ChartJsDataset from '../../Models/Chart/ChartjsDataset'
|
||||||
|
import chartjsTypes from '../../Constants/chartjsTypes'
|
||||||
|
|
||||||
let instance = null
|
let instance = null
|
||||||
|
|
||||||
@ -12,8 +13,7 @@ class Charts {
|
|||||||
|
|
||||||
addNewChart = chart => {
|
addNewChart = chart => {
|
||||||
let newChart = null
|
let newChart = null
|
||||||
if (chart.type === 'bar') newChart = this._generateChartJsDataset(chart)
|
if (chartjsTypes.includes(chart.type)) newChart = this._generateChartJsDataset(chart)
|
||||||
if (chart.type === 'doughnut') newChart = this._generateChartJsDataset(chart)
|
|
||||||
|
|
||||||
if (newChart) this.collection.push(newChart)
|
if (newChart) this.collection.push(newChart)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import FocusChart from '../../Models/Chart/FocusChart'
|
import FocusChart from '../../Models/Chart/FocusChart'
|
||||||
import { Doughnut } from 'react-chartjs-2'
|
import { Doughnut, Bar, Line, Pie, Polar, Radar } from 'react-chartjs-2'
|
||||||
import { Button } from 'semantic-ui-react'
|
import { Button } from 'semantic-ui-react'
|
||||||
import download from 'downloadjs'
|
import download from 'downloadjs'
|
||||||
|
|
||||||
@ -29,7 +29,6 @@ class ChartViewer extends Component {
|
|||||||
|
|
||||||
setFocusChart = () => {
|
setFocusChart = () => {
|
||||||
const focusChart = this.focusChart.chart
|
const focusChart = this.focusChart.chart
|
||||||
console.log(focusChart)
|
|
||||||
if (focusChart) {
|
if (focusChart) {
|
||||||
this.setState({
|
this.setState({
|
||||||
chart: focusChart
|
chart: focusChart
|
||||||
@ -41,7 +40,12 @@ class ChartViewer extends Component {
|
|||||||
const { chart } = this.state
|
const { chart } = this.state
|
||||||
if (!chart) return
|
if (!chart) return
|
||||||
|
|
||||||
return <Doughnut data={chart[chart.type]} width={600} height={600} ref={this.chart} />
|
if (chart.type === 'bar') return <Bar data={chart[chart.type]} width={600} height={600} ref={this.chart} />
|
||||||
|
if (chart.type === 'doughnut') return <Doughnut data={chart[chart.type]} width={600} height={600} ref={this.chart} />
|
||||||
|
if (chart.type === 'line') return <Line data={chart[chart.type]} width={600} height={600} ref={this.chart} />
|
||||||
|
if (chart.type === 'pie') return <Pie data={chart[chart.type]} width={600} height={600} ref={this.chart} />
|
||||||
|
if (chart.type === 'polar') return <Polar data={chart[chart.type]} width={600} height={600} ref={this.chart} />
|
||||||
|
if (chart.type === 'radar') return <Radar data={chart[chart.type]} width={600} height={600} ref={this.chart} />
|
||||||
}
|
}
|
||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user