Formatting legend and axis in Google Charts
Asked Answered
C

3

10

I'm new with Google Charts and I am not able to obtain a fine result with the texts surrounding the graph.

This is how my chart looks:

This is how looks my chart

As you can see, it does cut both Horizontal-Axis and Legends, so the final result is not as good as It could be. Is there a way to solve this? I've been reading the official documentation and some posts from here, but I haven't found the way to do this.

Recap: How do we modify the legend or the axis texts so they are fully visible?

Colonize answered 15/2, 2012 at 11:54 Comment(0)
C
17

After some time experimenting, I daresay it is not posible to choose how much part of the words on legend or axis you can show.

However, you can play with their sizes and position so you get -more or less- what we were looking for. This is what can be done:

legend: {position: 'top', textStyle: {fontSize: 14}}

I've also made the image a little bit bigger so it fits the x-axis without problems (There was also the option of making its text smaller).

So doing this, this is what you get: enter image description here

Colonize answered 22/2, 2012 at 11:51 Comment(0)
P
6

Its basically about setting your chart area vs width / height.

width: [yourChoice]px,
chartArea: {width: '50%'}

ref https://mcmap.net/q/396493/-how-to-set-google-charts-legend-width-in-javascript

Also as @ArcDare says using the other available styling options such as font size etc

Provincial answered 30/11, 2012 at 6:10 Comment(0)
D
0

For optmized chart area,

chartArea: {'width': '90%', 'height': '60%'}, 
legend: { position: 'bottom' },
hAxis : { textStyle : { fontSize: 10} },
vAxis : { textStyle : { fontSize: 10} },

The trick is setting axis textStyle fontsize will enable better placement of legend on the bottom of the chart as the chart Area is about 60-70%

Feel free to use my custom Google Charts plugin which creates both chart and table. https://github.com/cosmoarunn/gapiExt

Dentilingual answered 29/11, 2017 at 10:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.