Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Chart cannot color horizontal axis (hAxis)

Somehow I haven't been able to color the text of my horizontal axis. This is what I have set for options:

var options = {
    colors: ['#B20054', '#993D69', '#BD00FF', '#FFFE40', '#CCB814', '#998F3D', '#40B2FF'],
    timeline: { colorByRowLabel: true, rowLabelStyle: { fontSize: 9, color: '#603913' },
            barLabelStyle: {  fontSize: 9 }  }
    hAxis: {
        textStyle:{color: '#FFF'}
    }
};

Screenshot:

Screenshot problem

Complete code:

var container = document.getElementById('timetracking_Dennis');
  var chart = new google.visualization.Timeline(container);
  var dataTable = new google.visualization.DataTable();

  dataTable.addColumn({ type: 'string', id: 'Term' });
  dataTable.addColumn({ type: 'string', id: 'Name' });
  dataTable.addColumn({ type: 'date', id: 'Start' });
  dataTable.addColumn({ type: 'date', id: 'End' });

  dataTable.addRows([
    [ '#5700', 'Vernieuwing wifi-netwerk', new Date(0,0,0,10,16,0), new Date(0,0,0,10,17,0) ],
    [ '#5704', 'Account Mike Hees', new Date(0,0,0,10,23,0), new Date(0,0,0,10,28,0) ],
    [ '#5798', 'Laptop Bas van der Beer traag', new Date(0,0,0,10,15,0), new Date(0,0,0,11,14,0) ],
    [ '#5832', 'Problemen iMac', new Date(0,0,0,11,24,0), new Date(0,0,0,11,25,0) ],
    [ '#5832', 'Problemen iMac', new Date(0,0,0,11,34,0), new Date(0,0,0,11,35,0) ],
    [ '#5856', 'Problemen iMac', new Date(0,0,0,17,28,0), new Date(0,0,0,18,0,0) ],
    [ '#5856', 'Internet Broekseweg', new Date(0,0,0,9,14,0), new Date(0,0,0,9,15,0) ],
    [ '#5856', 'Internet Broekseweg', new Date(0,0,0,9,0,0), new Date(0,0,0,10,0,0) ],
    [ '#5856', 'Internet Broekhovenseweg', new Date(0,0,0,16,2,0), new Date(0,0,0,16,12,0) ],
    [ '#5857', 'gebruiker Abdel issues met opstarten', new Date(0,0,0,11,37,0), new Date(0,0,0,11,38,0) ],
    [ '#5895', 'Printer uit flexplek halen', new Date(0,0,0,11,9,0), new Date(0,0,0,11,17,0) ]    
  ]);

    var options = {
        colors: ['#B20054', '#993D69', '#BD00FF', '#FFFE40', '#CCB814', '#998F3D', '#40B2FF'],
        timeline: { colorByRowLabel: true, rowLabelStyle: { fontSize: 9, color: '#603913' },
                barLabelStyle: {  fontSize: 9 }  }
      };

  chart.draw(dataTable, options);
like image 653
Bart Burg Avatar asked Oct 30 '22 17:10

Bart Burg


1 Answers

There is a really dirty hack you can use to color the X-axis.

The timeline's svg contains a number of <text> elements. These include the numbers on the X-axis.

If you find the <svg> element of the chart, and assign that to a variable called svg, you can do the following hack:

svg.find('[font-size="13"]').attr('fill', '#ffffff');

assuming you want to color the X-axis white.

This only works in your particular case because you have changed the rowLabelStyle. By default, the row labels also have font-size="13".

like image 196
Bart van Nierop Avatar answered Nov 09 '22 09:11

Bart van Nierop