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 if (chart.type === 'doughnut') return if (chart.type === 'line') return if (chart.type === 'pie') return if (chart.type === 'polar') return if (chart.type === 'radar') return } render = () => { return (
{this.renderChart()} { this.state.chart ? : '' }
) } } export default ChartViewer