KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Center align google chart title #1878

Closed ankit raj opened this topic on on Jan 29, 2021 - 4 comments

ankit raj commented on Jan 29, 2021

Hi , I am using google combo chart to display data and the title is left aligned. What parameter should i use to center align it?

David Winterburn commented on Feb 1, 2021

Hi,

Did you mean the y axis label or the series names/legends?

ankit raj commented on Feb 1, 2021

Hi , i meant the chart title defined by the title attribute.

   \koolreport\widgets\google\ComboChart::create(array(
            "title"=>$title,

It is left aligned with respect to the chart and i want to center align it.

David Winterburn commented on Feb 2, 2021

Hi,

I think there's no option for setting Google chart's title position at the moment. However, you could put this javascript function at the end of your page to adjust them yourself:

<script>
                    setTimeout(function() {
                        var texts = document.querySelector('#googleLineChart').querySelectorAll('text'); //replace "googleLineChart" with your chart's name/id
                        console.log(texts);
                        for (var i=0; i<texts.length; i+=1) {
                            var text = texts[i];
                            if (text.textContent.trim() == "My Chart Title") { //replace "My Chart Title" with your chart's title
                                text.setAttribute("text-anchor", "middle");
                                text.setAttribute("x", "50%");
                                break;
                            }
                        };
                    }, 5000);
</script>

Let us know how it works for you. Thanks!

ankit raj commented on Feb 4, 2021

Thanks . Works perfect.

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

None