How to change properties of tooltip text? - charts

I am new to google charts, trying to make calendar chart.
I am using this :
`google.charts.load('current', {'packages':['calendar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('date' , 'date');
dataTable.addColumn('number', 'num');
dataTable.addColumn({ type: 'string', role:'tooltip'});
dataTable.addRows([
[ new Date(2017, 11, 20), 150,'Hello'],
[ new Date(2017, 11, 21), 130,'Hello']
]);
var chart = new google.visualization.Calendar(document.getElementById('tooltip_action'));
var options = {
title: "Calendar Chart",
colors: ['#e0440e'],
height: 350
};
chart.draw(dataTable, options);
`
It is working fine. But when I move cursor to 20/12/2017 and 21/12/2017 it is showing 'Hello' in very small text and small size.
And when I move cursor to other dates it is showing in bigger.
I want to change height and width of this text.
How to change properties of this tooltip text ???

you can use html tooltips, then use a css class to style them
set the following option...
tooltip: {
isHtml: true
}
and column property --> p: {html: true}
dataTable.addColumn({ type: 'string', role:'tooltip', p: {html: true}});
see following working snippet...
google.charts.load('current', {
packages: ['calendar']
}).then(function () {
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('date' , 'date');
dataTable.addColumn('number', 'num');
dataTable.addColumn({ type: 'string', role:'tooltip', p: {html: true}});
dataTable.addRows([
[ new Date(2017, 11, 20), 150,'<div class="tooltip">Hello</div>'],
[ new Date(2017, 11, 21), 130,'<div class="tooltip">Hello</div>']
]);
var chart = new google.visualization.Calendar(document.getElementById('tooltip_action'));
var options = {
title: "Calendar Chart",
colors: ['#e0440e'],
height: 350,
tooltip: {
isHtml: true
}
};
chart.draw(dataTable, options);
});
body {
overflow: auto;
}
#tooltip_action {
width: 1000px;
}
.tooltip {
font-size: 24px;
padding: 12px;
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="tooltip_action"></div>

Related

Annotation on Google Bar Chart

I am trying to add annotations to a bar chart but it doesn't work. When I use the package 'corechart' it works but I want to use the package 'bar'. This is my code :
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('timeofday', 'Hour');
data.addColumn('number', 'Value');
data.addColumn({type:'string', role:'annotation'})
data.addRows([
[[00, 00], 200, 'one'],
[[01, 00], 230, 'two'],
[[02, 00], 400, 'three'],
]);
var options = {
hAxis: {
title: 'Hour',
format: 'hh:mm',
},
vAxis: {
title: 'Value'
},
backgroundColor: '#e3f2fd',
legend: 'none',
height: 450,
width: 3000,
colors: ['#00ACC1'],
alwaysOutside: true,
textStyle: {
fontSize: 17,
auraColor: 'none',
color: '#FFFFFF'
} ,
};
var chart = new
google.charts.Bar(document.getElementById('chart_div'));
chart.draw(data, google.charts.Bar.convertOptions(options));
}
Everything works perfectly, just the annotations are missing.
Thank you!

Google Charts: Data label with suffix

I am just starting with using google charts. I have a question. I would like to add data labels to my columns, in fact I have succeeded in this. However, I would like to add a suffix to these labels (percentages %). I have tried to use NumberFormat, but then no chart appears. What am I doing wrong?
<script type="text/javascript" src="https://www.google.com/jsapi"></script><script type="text/javascript">
google.load('visualization', '1', { 'packages': ['corechart'] } );
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['Kenmerk', 'Belangrijkheid', { role: 'style' } ],
['Uitstellen', 10, 'color: gray'],
['bijwerkingen', 20, 'color: yellow'],
['behandelingen', 30, 'color: red'],
['Schema', 40, 'color: blue']
]);
var view = new google.visualization.DataView(data);
view.setColumns([0, 1,
{ calc: "stringify",
sourceColumn: 1,
type: "string",
role: "annotation" },
2]);
// Set chart options
var options = {
width: 800,
height: 600,
title: 'Uitslag',
vAxis: { title: 'belangrijkheid van elk kenmerk in percentages uitgedrukt', format: '#\'%\'', maxValue: '100', minValue: '0'},
legend: { position: 'none'},
bar: { groupWidth: '75%' },
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.ColumnChart(document.getElementById("columnchart_values"));
chart.draw(view, options);
}
</script></p>
<div id="columnchart_values" style="width: 800px; height: 600px;">
</div>

Material design google charts change color column

When using Google charts, usually you can change the colors of individual columns by using the "role: style" function, but when I attempt it with the new material design charts I only get blue columns.
google.charts.load('current', {'packages':['bar']});
google.charts.setOnLoadCallback(drawStuff);
function drawStuff() {
var data = new google.visualization.arrayToDataTable([
['', '', { role: 'style' } ],
["Strongly disagree", 0, 'color: black'],
["Disagree", 0, 'color: #000000'],
["Neutral", 6, 'color: #212121'],
["Agree", 45, 'color: #212121'],
['Stongly agree', 98, 'color: black']
]);
var options = {
title: 'Instructor presented the subject matter clearly',
width: 900,
legend: { position: 'none' },
chart: { subtitle: 'General physics 221 CSUSB winter 2017' },
axes: {
},
bar: { groupWidth: "90%" }
};
var chart = new google.charts.Bar(document.getElementById('top_x_div'));
// Convert the Classic options to Material options.
chart.draw(data, google.charts.Bar.convertOptions(options));
};
You can try with netx code:
google.charts.load('current', {packages: ['corechart', 'bar']});
google.charts.setOnLoadCallback(drawColColors);
function drawColColors() {
var data = new google.visualization.arrayToDataTable([
['', '', { role: 'style' } ],
["Strongly disagree", 12, 'brown'],
["Disagree", 30, 'gray'],
["Neutral", 26, 'blue'],
["Agree", 45, 'color: #F05921'],
['Stongly agree', 58, 'black']
]);
var options = {
title: 'Instructor presented the subject matter clearly',
width: 900,
legend: { position: 'none' },
chart: { subtitle: 'General physics 221 CSUSB winter 2017' },
axes: {
},
bar: { groupWidth: "90%" }
};
//var chart = new google.charts.Bar(document.getElementById('chart_div'));
// Convert the Classic options to Material options.
//chart.draw(data, google.charts.Bar.convertOptions(options));
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(data, options);
};
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

Google Charts change axis line and text color

My google bar chart options variable is:
var Baroptions = {
legend: {position: 'none'},
hAxis: {
textPosition: 'none',
gridlines: {
color: "#FFFFFF"
},
baselineColor: '#FFFFFF'
},
bars: 'horizontal',
animation:{
duration: 500,
easing: 'out',
}
};
But axis line and text are still being displayed.
I need to remove that 0 and 50k text.
Regards
instead of --> textPosition: 'none'
try...
textStyle: {
color: "#FFFFFF"
},
see following working snippet...
google.charts.load('current', {
callback: drawChart,
packages: ['bar']
});
function drawChart() {
var chart = new google.charts.Bar(document.getElementById('chart_div'));
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('string', '');
dataTable.addColumn('number', 'Value');
dataTable.addRows([
['18-25', 25],
['26-35', 46],
['36-45', 30],
['46-55', 10],
['55 Above', 7]
]);
var Baroptions = {
legend: {position: 'none'},
hAxis: {
textStyle: {
color: "#FFFFFF"
},
gridlines: {
color: "#FFFFFF"
},
baselineColor: '#FFFFFF'
},
bars: 'horizontal'
};
chart.draw(dataTable, google.charts.Bar.convertOptions(Baroptions));
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>
also, not sure from the question, but if using a material chart as in the above example
animation.* is among the several options that don't work on material charts

Google Combo Chart with multiple series, how to add custom HTML Tooltip

I've Google combo chart and like to add a Tooltip. The icCube documention has an example how to add a HTML tooltip but this will not work for series, only the last item in the serie gets the tooltip. I found an answer how to do this, see this post.
But how can I achieve this in icCube?
for google charts, you can reference the Data Format of the specific chart
for most, the tooltip follows the series column
to have multiple series, each with it's own custom html tooltip,
add a column after each series column
NOTE: for custom html tooltips to work, the following must be in place...
the column must have property --> html: true
dataTable.addColumn({type: 'string', role: 'tooltip', p: {html: true}});
and the configuration options must include...
tooltip: {isHtml: true}
see following working snippet, the tooltip columns are loaded initially as null
then the tooltip is built based on the values in the series columns
google.charts.load('current', {
callback: function () {
var container = document.getElementById('chart_div');
var chart = new google.visualization.ComboChart(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({type: 'string', label: 'Year'});
// series 0
dataTable.addColumn({type: 'number', label: 'Category A'});
dataTable.addColumn({type: 'string', role: 'tooltip', p: {html: true}});
// series 1
dataTable.addColumn({type: 'number', label: 'Category B'});
dataTable.addColumn({type: 'string', role: 'tooltip', p: {html: true}});
// series 2
dataTable.addColumn({type: 'number', label: 'Category C'});
dataTable.addColumn({type: 'string', role: 'tooltip', p: {html: true}});
dataTable.addRows([
['2014', 1000, null, 2000, null, 3000, null],
['2015', 2000, null, 4000, null, 6000, null],
['2016', 3000, null, 6000, null, 9000, null],
]);
for (var i = 0; i < dataTable.getNumberOfRows(); i++) {
dataTable.setValue(i, 2, getTooltip(i, 1));
dataTable.setValue(i, 4, getTooltip(i, 3));
dataTable.setValue(i, 6, getTooltip(i, 5));
}
function getTooltip(rowIndex, columnIndex) {
return '<div class="ggl-tooltip"><span>' +
dataTable.getValue(rowIndex, 0) + ': </span>' +
dataTable.getFormattedValue(rowIndex, columnIndex) + '</div>';
}
chart.draw(dataTable, {
legend: {
position: 'bottom'
},
pointSize: 4,
seriesType: 'area',
series: {
2: {
pointSize: 12,
pointShape: {
type: 'star',
sides: 5,
dent: 0.6
},
type: 'scatter'
}
},
tooltip: {isHtml: true}
});
},
packages: ['corechart']
});
.ggl-tooltip {
border: 1px solid #E0E0E0;
font-family: Arial, Helvetica;
font-size: 10pt;
padding: 12px 12px 12px 12px;
}
.ggl-tooltip span {
font-weight: bold;
}
<script src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>