Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make it work on ReactJS ? #16

Open
phhoffmann opened this issue Oct 28, 2019 · 5 comments
Open

How to make it work on ReactJS ? #16

phhoffmann opened this issue Oct 28, 2019 · 5 comments

Comments

@phhoffmann
Copy link

Hey guys

I'm trying to use ChartFunnel on a project using ReactJS. I've tried using some things that i saw in this issue but unfortunatelly didn't have much success.
The console doesn't show any errors, but the chart doesn't render.
Does anyone achieved something with React and ChartFunnel ?

Thanks for the help :)

@dcworldwide
Copy link

Figure it out?

@phhoffmann
Copy link
Author

unfortunatelly, no. the team decided to use amcharts instead

@SirPhemmiey
Copy link

Any update on this please?

@JekRock
Copy link

JekRock commented Aug 12, 2020

I've made the example from here work by just importing the charts.funnel.js
The component example that makes the same chart as in the readme in a React component

import React, { Component } from "react";
import Chart from 'chart.js';
import * as funnel from 'chartjs-funnel'

export default class FunnelChart extends Component{
    chartRef = React.createRef();
    
    componentDidMount() {
        const myChartRef = this.chartRef.current.getContext("2d");
        
        new Chart(myChartRef, {
            type: 'funnel',
    data: {
        datasets: [{
            data: [30, 60, 90],
            backgroundColor: [
                "#FF6384",
                "#36A2EB",
                "#FFCE56"
            ],
            hoverBackgroundColor: [
                "#FF6384",
                "#36A2EB",
                "#FFCE56"
            ]
        }],
        labels: [
            "Red",
            "Blue",
            "Yellow"
        ]	
    },
            options: {
                //Customize chart options
            }
        });
    }
    render() {
        return (
                <canvas
                    id="myChart"
                    ref={this.chartRef}
                />
        )
    }
}

@mirajhad
Copy link

Instead of importing from chart.js use chartjs-funnel/dist/chart.funnel.bundled

`import React from 'react';
import Chart from 'chartjs-funnel/dist/chart.funnel.bundled';

var config = {
type: 'funnel',
sort:'asc',
data: {
datasets: [{
data: [100, 80, 75, 50, 40, 30],
backgroundColor: [
"#E33716",
"#F7940D",
"#029DE3",
"#339037",
"#204CB7"
],
hoverBackgroundColor: [
"#E33716",
"#F7940D",
"#029DE3",
"#339037",
"#204CB7"
]
}],
labels: [
"100%",
"80%",
"75%",
"50%",
"40%",
"30%"
]
},
options: {
sort: 'desc',
}
}

class FunnelChart extends React.Component {
constructor(props) {
super(props);
this.chartRef = React.createRef();
}

componentDidMount(){
    this.myChart = new Chart(this.chartRef.current, config);
}

render() {
    return(
    <>
    <canvas ref={this.chartRef}/>
    </>
    );
}

}
export default FunnelChart;`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants