Google charts legend manipulation

后端 未结 5 2090
無奈伤痛
無奈伤痛 2020-12-07 00:47

Using google area chart: http://code.google.com/apis/chart/interactive/docs/gallery/areachart.html

Does anyone know how I can freelly manipulate the legends?

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 01:33

    Maybe something like this (it's depends on the font that you use, you need fetch the proportion of your font)

    var my_legend = "this is my legend x";
    
    var len_legend = my_legend.length;
    
    var width_graph = 400;
    
    var chars_per_line = width_graph / [REPLACE_BY_PROPORTION]
    
    if (len_legend > chars_per_line) {
    
        my_legend = wordwrap(my_legend, 20, '
    \n'); }

    AND THE WRAP WORD FUNCTION (or anything like this)

    function wordwrap( str, width, brk, cut ) {
    
        brk = brk || '\n';
    
        width = width || 75;
    
        cut = cut || false;
    
        if (!str) { return str; }
    
        var regex = '.{1,' +width+ '}(\\s|$)' + (cut ? '|.{' +width+ '}|.+$' : '|\\S+?(\\s|$)');
    
    
    return str.match( RegExp(regex, 'g') ).join( brk );
    
    }
    

    SO FOR your code...

    replace values at

    var chart = new google.visualization.AreaChart(document....
    

    etc

    by your vars.

    not use width = 400, use width, and so on... and your string.

提交回复
热议问题