Google Charts: Pie Chart title position

后端 未结 3 1612
没有蜡笔的小新
没有蜡笔的小新 2021-01-13 03:59

I was assigned to implement some Charts, and the bosses requested me to separate the title of the chart from the Chart, I tried to move the chart\'s area a little from the t

相关标签:
3条回答
  • 2021-01-13 04:27

    I don't think you can do this through options in the vis api.

    However....

    The title is held in a text element that uses x/y positioning

    If you are using JQuery, this becomes a piece of cake

    $("text:contains(" + vencOptions.title + ")").attr({'x':'60', 'y':'20'})
    

    Adding that immediately after the .draw call and tweaking the x and y coords gives you pixel-perfect control.

    You can do it without JQuery, but time is pressing and I'll leave that to someone else :)

    0 讨论(0)
  • 2021-01-13 04:28

    It's annoyed when Google did provide title position but with jQuery, you can do it

    $("#YOUR_GRAPH_WRAPPER svg text").first()
     .attr("x", (($("#time-series-graph svg").width() - $("#YOUR_GRAPH_WRAPPER svg text").first().width()) / 2).toFixed(0));
    

    Basically, you want to access the first text tag which is your chart title and change value of x attribute. To center it, take svg width (your graph width) subtract by title widtch, then divide by 2 :) Happy hacking :)

    0 讨论(0)
  • 2021-01-13 04:44

    as PerryW said, I don't think you can do this with the given API. The easiest way to do this would be to make an html table with the chart on the second row.

    <table>
        <thead>
            <th>Vencimientos prox. 6 meses</th>
        </thead>
        <tbody>
            <td>
                ***YOUR CHART HERE***
            </td>
        </tbody>
    </table>
    

    Now you can play around with the style and location as much as you want!

    0 讨论(0)
提交回复
热议问题