import React, { Component } from 'react'
import FocusChart from '../../Models/Chart/FocusChart'
import { Doughnut, Bar, Line, Pie, Polar, Radar } from 'react-chartjs-2'
import { Button } from 'semantic-ui-react'
import download from 'downloadjs'
class ChartViewer extends Component {
constructor () {
super ()
this.focusChart = new FocusChart()
this.chart = React.createRef()
this.state = {
chart: null,
reportValue: ''
}
document.addEventListener('setSelectedChart', this.setFocusChart)
}
handleGroupByChange = (e, value) => {
this.setState({ reportValue: value.value })
}
saveChart = () => {
console.log(this.chart.current)
const base64OfChart = this.chart.current.chartInstance.toBase64Image()
download(base64OfChart, this.focusChart.chart.label, 'image/png')
}
setFocusChart = () => {
const focusChart = this.focusChart.chart
if (focusChart) {
this.setState({
chart: focusChart
})
}
}
renderChart = () => {
const { chart } = this.state
if (!chart) return
console.log(chart)
if (chart.type === 'bar') return