Tantrum
Posts: 1
Joined: Thu Jan 27, 2022 8:06 am

color: "contrast" not working for some reason.

As i said in the title, for some reason
style: {
color: "contrast"
}

does not change the color of the datalabels on my piechart. If the slice is black, the text is black too. And ofc I want it to be white.
Here is the config code that i am working with:

Code: Select all

export class HighChart_Pie extends Component {

    constructor(props){
        super(props) 
        this.state = {
            config: {
                    chart: {
                        plotBackgroundColor: null,
                        plotBorderWidth: null,
                        plotShadow: false,
                        type: 'pie',
                        styledMode: false
                    },
                    exporting: {
                        enabled: false
                    },
                    title: {
                        text: "",
                    },
                    tooltip: {
                        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
                    },
                    accessibility: {
                        point: {
                            valueSuffix: '%'
                        }
                    },
                    legend: {
                        layout: "vertical",
                        align: "right",
                        verticalAlign: "middle",
                        className: "HC_legend",

                        itemMarginTop: 10,
                        itemStyle: {
                            fontSize: "1.4em",
                            padding: "20px",
                            overflow: "scroll"
                        },
                        maxHeight: 200,
                    },
                    plotOptions: {
                        pie: {
                            innerSize: ["50%", "75%"],
                            allowPointSelect: true,
                            cursor: 'pointer',
                            dataLabels: {
                                format: "{point.percentage:.1f}%",
                                enabled: true,
                                distance: -35,
                                style: {
                                    textOutline: "none",
                                    fontSize: "1.2em",
                                    textShadow: false,
                                    color: "contrast",
                                }
                                
                            },
                            size: 280,
                            showInLegend: true,
                            colors: [
                                "#cfd7e2", 
                                "#20bc9d", 
                                "#7d8ba0", 
                                "#1e283c", 
                                "#9fafc9", 
                                "#8b61b8"
                            ],
                        }
                    },
                    series: [{
                        data: [],
                    
                    }],
                    drilldown: {
                        series: []
                    }

                }
            }
    }

    
    componentDidUpdate(prevProps){
        if(this.props.series !== prevProps.series){
            const series = this.props.series
            const brand = this.props.brand
            const drilldown = this.props.children
            console.log(drilldown)

            const config = {
                ...this.state.config,
                series: [{
                    name: brand,
                    data: series
                
                }],
                drilldown: drilldown,
            }
            this.setState({config: config})
       }
    }


    render() {
        console.log(this.state.config)
        return (
            <div id="pieChartMainContainer">
                <h4 id="pieTitle" className="VisualTitle">{this.props.title}</h4>
                <div id="pieContainer">
                    <ReactHighcharts highcharts={Highcharts} options={this.state.config} immutable={true} /> 
                </div>
            </div>
        )
    }
}   


export default HighChart_Pie



I've been looking around everywhere and cant find anyone else that has had this issue it seems. As far as I can see, it should be working!
Hope anyone can help me look in the right place for a bug/misstake I have done somewhere that could affect this.

Thanks alot!
// :)
magdalena
Posts: 517
Joined: Tue Aug 24, 2021 1:32 pm

Re: color: "contrast" not working for some reason.

Hello Tantrum,

Welcome to our forum and thanks for contacting us with your question!

For now, I don't see any mistakes in the configuration. Could you please reproduce this example to the working demo? You can start here: https://codesandbox.io/s/highcharts-react-demo-e1ue3

Regards!
Magdalena Gut
Developer and Highcharts Support Engineer

Return to “Highcharts Usage”