I'm trying to add three new sections to the hover pop-up on a bar in google timeline charts.
I have tried using the google timeline help but cannot find a solution
The default is Title / Time / Duration, however I want to add Arena / Website
I have created the below code for this as an example.
<DIV>
<p><font face="verdana" size="6" color="Black">Thursday</font></p>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load("current", {packages:["timeline"]});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var container = document.getElementById('example5.1');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'Federation' });
dataTable.addColumn({ type: 'string', id: 'Event' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
dataTable.addRows([
[ 'WWE / NXT', 'AXXESS', new Date(0,0,0,18,0,0), new Date(0,0,0,22,0,0)],
[ 'WWN', 'Matt Riddles Bloodsport', new Date(0,0,0,15,0,0), new Date(0,0,0,18,0,0)],
[ 'WrestleCon', 'Wildkat Sports', new Date(0,0,0,18,0,0), new Date(0,0,0,21,0,0)],
[ 'WWN', 'Evolve', new Date(0,0,0,20,00,0), new Date(0,0,0,23,0,0)],
[ 'WrestleCon', 'WrestleCon Supershow', new Date(0,0,0,21,30,0), new Date(0,0,0,23,30,0)],
[ 'Knockout', 'Knockout in NOLA', new Date(0,0,0,17,00,0), new Date(0,0,0,20,00,0)],
[ 'ROH', 'RoH Supercard of Honor', new Date(0,0,0,19,30,0), new Date(0,0,0,22,30,0)],
[ 'WWN', 'Beyond Wrestling', new Date(0,0,0,20,55,0), new Date(0,0,0,23,55,0)]]);
var options = {
timeline: { colorByRowLabel: true },
tooltip: {isHtml: true},
legend: 'none',
backgroundColor: '#ffd'
};
chart.draw(dataTable, options);
}
</script>
<div id="example5.1" style="height: 300px;"></div>
</DIV>
you can add your own custom tooltip, see Customizing tooltips in the Timeline reference
the tooltip column will just be a string, either a simple value or html
see following working snippet,
here, a DataView is used to add the tooltip column.
this allows the tooltip to be built dynamically based on the data in the data table
also, the arena is added to the original data table, for easy reference,
but is excluded from the data view...
google.charts.load('current', {
packages: ['timeline']
}).then(function () {
var container = document.getElementById('example5.1');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'Federation' });
dataTable.addColumn({ type: 'string', id: 'Event' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
dataTable.addColumn({ type: 'string', id: 'Arena' });
dataTable.addRows([
['WWE / NXT', 'AXXESS', new Date(0,0,0,18,0,0), new Date(0,0,0,22,0,0), 'Arena A'],
['WWN', 'Matt Riddles Bloodsport', new Date(0,0,0,15,0,0), new Date(0,0,0,18,0,0), 'Arena B'],
['WrestleCon', 'Wildkat Sports', new Date(0,0,0,18,0,0), new Date(0,0,0,21,0,0), 'Arena C'],
['WWN', 'Evolve', new Date(0,0,0,20,00,0), new Date(0,0,0,23,0,0), 'Arena D'],
['WrestleCon', 'WrestleCon Supershow', new Date(0,0,0,21,30,0), new Date(0,0,0,23,30,0), 'Arena E'],
['Knockout', 'Knockout in NOLA', new Date(0,0,0,17,00,0), new Date(0,0,0,20,00,0), 'Arena F'],
['ROH', 'RoH Supercard of Honor', new Date(0,0,0,19,30,0), new Date(0,0,0,22,30,0), 'Arena G'],
['WWN', 'Beyond Wrestling', new Date(0,0,0,20,55,0), new Date(0,0,0,23,55,0), 'Arena H']]);
var options = {
timeline: { colorByRowLabel: true },
tooltip: {isHtml: true},
legend: 'none',
backgroundColor: '#ffd'
};
var formatTime = new google.visualization.DateFormat({
pattern: 'HH:mm:ss a'
});
var view = new google.visualization.DataView(dataTable);
view.setColumns([0, 1, {
role: 'tooltip',
type: 'string',
calc: function (dt, row) {
// build tooltip
var dateBegin = dt.getValue(row, 2);
var dateEnd = dt.getValue(row, 3);
var oneHour = (60 * 60 * 1000);
var duration = (dateEnd.getTime() - dateBegin.getTime()) / oneHour;
var tooltip = '<div><div class="ggl-tooltip"><span>';
tooltip += dt.getValue(row, 0) + ':</span> ' + dt.getValue(row, 1) + '</div>';
tooltip += '<div class="ggl-tooltip"><div>' + formatTime.formatValue(dateBegin) + ' - ';
tooltip += formatTime.formatValue(dateEnd) + '</div>';
tooltip += '<div><span>Duration: </span>' + duration.toFixed(0) + ' hours</div></div>';
tooltip += '<div class="ggl-tooltip"><span>Arena: </span>' + dt.getValue(row, 4) + '</div></div>';
return tooltip;
},
p: {html: true}
}, 2, 3]);
chart.draw(view.toDataTable(), options); // <-- use data view to draw chart
});
.ggl-tooltip {
background-color: #ffffff;
border: 1px solid #e0e0e0;
font-family: Arial, Helvetica;
font-size: 14px;
padding: 8px;
}
.ggl-tooltip span {
font-weight: bold;
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="example5.1"></div>
Related
I have images with scores associated with them streaming to my app. As the scores come in I've plotted them on a line chart using ng2-charts.
I want to customize the tooltip on the chart to display a smaller preview of the image that it came with. I've scoured around but haven't been able to figure out how to inject the custom html into the tooltip or if it is even possible without creating a custom chart.
Any advice on whether or not this is possible and how would be greatly appreciated.
This is in Ionic 4 with angular 6 and my modules versions are:
"ng2-charts": "^2.2.2",
"chart.js": "^2.8.0",
Not sure this is necessary for my question but here's how I set up the chart so far.
Markdown
<ion-content padding>
<div class="row" style="display: block;">
<div class="col-md-6">
<div style="display: block;">
<canvas baseChart width="1200" height="600"
[datasets]="lineChartData"
[labels]="lineChartLabels"
[options]="lineChartOptions"
[colors]="lineChartColors"
[legend]="lineChartLegend"
[chartType]="lineChartType"
(chartHover)="chartHovered($event)"
(chartClick)="chartClicked($event)"></canvas>
</div>
</div>
</div>
</ion-content>
Initializing the chart
// Initializing Chart settings
public lineChartLegend:boolean = true;
public lineChartType:string = 'line';
public lineChartData:ChartDataSets[] = [{ data: this.scoreArr, label: 'Image Scores' }];
public lineChartLabels:Label[] = [];
public lineChartOptions: (ChartOptions & { annotation: any }) = {
responsive: true,
scales: {
// We use this empty structure as a placeholder for dynamic theming.
xAxes: [{}],
yAxes: [
{
id: 'y-axis-0',
position: 'left',
}
]
},
annotation: {
annotations: [
{
type: 'line',
mode: 'vertical',
scaleID: 'x-axis-0',
value: 'March',
borderColor: 'orange',
borderWidth: 2,
label: {
enabled: true,
fontColor: 'orange',
content: 'LineAnno'
}
},
],
}
};
public lineChartColors:Color[] = [
{ // dark grey
backgroundColor: 'rgba(77,83,96,0.2)',
borderColor: 'rgba(77,83,96,1)',
pointBackgroundColor: 'rgba(77,83,96,1)',
pointBorderColor: '#fff',
pointHoverBackgroundColor: '#fff',
pointHoverBorderColor: 'rgba(77,83,96,1)'
}
];
To anyone who is curious. This is how. However, the tooltip doesn't go away when you stop hovering but I'll figure it out in a bit.
customTooltips = function(tooltip) {
//**************** This is what was messing me up
var tooltipEl = document.getElementById('chartjs-tooltipsdfljsdflkswdjf');
// Apparently grabbing my existing tooltipel was causing my issue
// if you make tooltipel null and just make your own following the
// chart.js docs this will work fine.
// ***************
if (!tooltipEl) {
console.log("tooltipel was null");
tooltipEl = document.createElement('div');
tooltipEl.id = 'chartjs-tooltip';
tooltipEl.innerHTML = "<table></table>"
document.body.appendChild(tooltipEl);
}
// Hide if no tooltip
if (tooltip.opacity === 0) {
tooltipEl.style.opacity = '0';
return;
}
tooltipEl.classList.remove('above','below','no-transform');
if (tooltip.yAlign) {
tooltipEl.classList.add(tooltip.yAlign);
} else {
tooltipEl.classList.add('no-transform');
}
function getBody(bodyItem) {
return bodyItem.lines;
}
// Set Text
if (tooltip.body) {
console.log("Bodys not null: ", tooltip.body);
var titleLines = tooltip.title || [];
var bodyLines = tooltip.body.map(getBody);
var innerHtml = '<thead>';
titleLines.forEach(function(title) {
innerHtml += '<tr><th>' + title + '</th></tr>';
innerHtml += '<tr><th><img src="https://www.mariowiki.com/images/thumb/2/2b/Marioptds.png/146px-Marioptds.png" style="width:42px;height:42px;border:0;"/></th></tr>';
});
innerHtml += '</thead><tbody>';
bodyLines.forEach(function(body, i) {
var colors = tooltip.labelColors[i];
var style = 'background:' + colors.backgroundColor;
style += '; border-color:' + colors.borderColor;
style += '; border-width: 2px';
var span = '<span class="chartjs-tooltip-key" style="' + style + '"></span>';
innerHtml += '<tr><td>' + span + body + '</td></tr>';
});
innerHtml += '</tbody>';
var tableRoot = tooltipEl.querySelector('table');
console.log('TableRoot: ' + tableRoot);
tableRoot.innerHTML = innerHtml;
}
// `this` will be the overall tooltip
var position = this._chart.canvas.getBoundingClientRect();
// Display, position, and set styles for font
tooltipEl.style.opacity = '1';
tooltipEl.style.position = 'absolute';
tooltipEl.style.left = position.left + window.pageXOffset + tooltip.caretX + 'px';
tooltipEl.style.top = position.top + window.pageYOffset + tooltip.caretY + 'px';
tooltipEl.style.fontFamily = tooltip._bodyFontFamily;
tooltipEl.style.fontSize = tooltip.bodyFontSize + 'px';
tooltipEl.style.fontStyle = tooltip._bodyFontStyle;
tooltipEl.style.padding = tooltip.yPadding + 'px ' + tooltip.xPadding + 'px';
tooltipEl.style.pointerEvents = 'none';
};
// Initializing Chart settings
public lineChartLegend:boolean = true;
public lineChartType:string = 'line';
public lineChartData:ChartDataSets[] = [{ data: this.scoreArr, label: 'Image Scores' }];
public lineChartLabels:Label[] = [];
public lineChartOptions: (ChartOptions & { annotation: any }) = {
responsive: true,
scales: {
// We use this empty structure as a placeholder for dynamic theming.
xAxes: [{}],
yAxes: [
{
id: 'y-axis-0',
position: 'left',
}
]
},
annotation: {
annotations: [
{
type: 'line',
mode: 'vertical',
scaleID: 'x-axis-0',
value: 'March',
borderColor: 'orange',
borderWidth: 2,
label: {
enabled: true,
fontColor: 'orange',
content: 'LineAnno'
}
},
],
},
tooltips: {
enabled: false,
mode: 'index',
position: 'nearest',
custom: this.customTooltips
}
};
public lineChartColors:Color[] = [
{ // dark grey
backgroundColor: 'rgba(77,83,96,0.2)',
borderColor: 'rgba(77,83,96,1)',
pointBackgroundColor: 'rgba(77,83,96,1)',
pointBorderColor: '#fff',
pointHoverBackgroundColor: '#fff',
pointHoverBorderColor: 'rgba(77,83,96,1)'
}
];
Can anybody help me how to set Combobox in DataGrid (dojox/grid) cells programmatically for each cell in column separately?
Structure parameter: cellType does its job, but all cells in column inherit defined type.
With formatter function we can return Combobox object but it has different behaviour then Combobox inserted with cellType.
I'm thinking also about onStartEdit function but I do not have idea how to implement that.
What I want to achieve is that if in cell is value which is text then I want to show combobox with all possibilities. In case of value as a number than I don't want to show combobox at all.
Sample code: (Dojo version 1.9.11)
require([
"dojo/data/ItemFileReadStore",
"dojo/store/Memory",
"dojox/grid/DataGrid",
"dojo/data/ObjectStore",
"dojo/dom",
"dojo/dom-construct",
"dijit/form/ComboBox",
"dojox/grid/cells/dijit",
"dojo/dom-style",
"dojo/domReady!"],
function(ItemFileReadStore, Memory, DataGrid, ObjectStore, dom, domConstruct, ComboBox, dijit, domStyle){
var dataArray = [];
var dataMemory = new Memory({data:dataArray});
var gridStruc = [];
gridStruc.push({name: 'Name', field: 'col1', width: '100px', editable: false});
gridStruc.push({name: 'Type', field: 'col2', width: '100px', editable: false});
gridStruc.push({name: 'Value (cellType)', field: 'col3', width: '100px', editable: true, cellType: 'dojox.grid.cells.ComboBox', options: ["Test1","Test2"]});
gridStruc.push({name: 'Value (formatter)', field: 'col4', width: '100px', editable: true, formatter: formatterCb});
var columnObj0 = {};
columnObj0["col1"] = "Voltage";
columnObj0["col2"] = "Number";
columnObj0["col3"] = "5";
columnObj0["col4"] = "5";
dataMemory.put(columnObj0);
var columnObj1 = {};
columnObj1["col1"] = "Type";
columnObj1["col2"] = "Text";
columnObj1["col3"] = "THT";
columnObj1["col4"] = "THT";
dataMemory.put(columnObj1);
var columnObj2 = {};
columnObj2["col1"] = "Num. Reflow";
columnObj2["col2"] = "Number";
columnObj2["col3"] = "3";
columnObj2["col4"] = "3";
dataMemory.put(columnObj2);
var columnObj3 = {};
columnObj3["col1"] = "Series";
columnObj3["col2"] = "Text";
columnObj3["col3"] = "CBK34";
columnObj3["col4"] = "CBK34";
dataMemory.put(columnObj3);
var dataStore = new ObjectStore({ objectStore: dataMemory});
grid = new DataGrid({
store: dataStore,
structure: gridStruc
},"gridDiv");
grid.startup();
function formatterCb(value, rowIndex, rowItem)
{
var storeItems=[];
storeItems.push({name: "Test1", value: "test1"});
storeItems.push({name: "Test2", value: "test2"});
var store = new ItemFileReadStore({data: {identifier:"name", items: storeItems}});
var w = new ComboBox({
label: "Use Input",
store: store,
value: value
});
w._destroyOnRemove = true;
return w;
}
});
I think defining formatter function may help.
Take a look at this example from documentation
function formatCell(value){
//perform your logic here
}
var layout = [
{
name: 'Cell1',
field: 'id'
},
{
name: 'Cell2',
field: 'date',
formatter: formatCell
}
];
In your case it will be here:
gridStruc.push({name: 'Name', formatter: formatCell, field: 'col1', width: '100px', editable: false});
I have no idea why do you use array.push, but it doesn't matter in this case.
Also check this tutorial, there is an example how to put widget in cell. It may be helpful.
I am new to SAPUI5 and I have assignment to display row index (consecutive numbering) in table (sap.ui.table.Table). For Example, I have this data in table:
Dente Al
Friese Andy
Mann Anita
and so on..
I want it to have column with row index, (preferably that will count from 1 to 3 even if rows are filtered/sorted):
1 Dente Al
2 Friese Andy
3 Mann Anita
Is there any UI component or some rendering callback or similar that will help me solve this problem in SAPUI5 manner?
Here is the code example:
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
</head>
<script id="sap-ui-bootstrap"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_belize" data-sap-ui-libs="sap.m,sap.ui.layout,sap.ui.commons,sap.ui.table"
data-sap-ui-compatVersion="edge" data-sap-ui-preload="async"
data-sap-ui-resourceroots='{
"sap.ui.demo.wt": "./"
}'>
</script>
<script>
sap.ui.getCore().attachInit(function() {
//Define some sample data
var aData = [
{lastName: "Dente", name: "Al"},
{lastName: "Friese", name: "Andy"},
{lastName: "Mann", name: "Anita"},
{lastName: "Schutt", name: "Doris"},
{lastName: "Open", name: "Doris"},
{lastName: "Dewit", name: "Kenya"}
];
//Create an instance of the table control
var oTable2 = new sap.ui.table.Table({
visibleRowCount: 7,
firstVisibleRow: 3
});
//Define the columns and the control templates to be used
oTable2.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Last Name"}),
template: new sap.ui.commons.TextView().bindProperty("text", "lastName"),
width: "200px"
}));
oTable2.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "First Name"}),
template: new sap.ui.commons.TextField().bindProperty("value", "name"),
width: "200px"
}));
//Create a model and bind the table rows to this model
var oModel2 = new sap.ui.model.json.JSONModel();
oModel2.setData({modelData: aData});
oTable2.setModel(oModel2);
oTable2.bindRows("/modelData");
//Initially sort the table
oTable2.sort(oTable2.getColumns()[0]);
//Bring the table onto the UI
oTable2.placeAt("content");
});
</script>
<body class="sapUiBody" id="content">
</body>
</html>
Another Solution (besides one answered):
This solution is based on modifying table rows directly. Although modifying model is preferable, our current project circumstances might not allow model editing:
Add Index column:
oTable2.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Index"}),
template: new sap.ui.commons.TextView({
text: "12"
}),
width: "200px"
}));
After binding was successful (or in onAfterRendering event in controller), use following code:
for (var i = 0, len = oTable2.getRows().length; i < len; i++){
var row = oTable2.getRows()[i];
var firstControl = row.getCells()[0];
firstControl.setText(row.getIndex()+1);
};
If you are using controller/jsview, make sure to give id to your table with createId method in jsview and to get component in controller by using byId method.
This can be done without having to add a "rowIndex" property to the model, but instead by using a formatter function which gets the index from the BindingContext path (which in this example would look like "/modelData/x" where x is the index of the item in the model).
Please see the modified code below. Note the use of the formatRowNumber function.
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta charset="utf-8"/>
</head>
<script id="sap-ui-bootstrap"
src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-theme="sap_belize" data-sap-ui-libs="sap.m,sap.ui.layout,sap.ui.commons,sap.ui.table"
data-sap-ui-compatVersion="edge" data-sap-ui-preload="async"
data-sap-ui-resourceroots='{
"sap.ui.demo.wt": "./"
}'>
</script>
<script>
sap.ui.getCore().attachInit(function() {
//Define some sample data
var formatRowNumber = function(val) {
if(!this.getBindingContext()) return null;
var index = this.getBindingContext().getPath().split("/")[2];
// (an example of path value here is "/modelData/0")
return parseInt(index) + 1;
};
var aData = [
{lastName: "Dente", name: "Al"},
{lastName: "Friese", name: "Andy"},
{lastName: "Mann", name: "Anita"},
{lastName: "Schutt", name: "Doris"},
{lastName: "Open", name: "Doris"},
{lastName: "Dewit", name: "Kenya"}
];
//Create an instance of the table control
var oTable2 = new sap.ui.table.Table({
visibleRowCount: 7,
firstVisibleRow: 3
});
//Define the columns and the control templates to be used
oTable2.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Index"}),
template: new sap.ui.commons.TextView().bindProperty("text", {path: '', formatter:formatRowNumber}),
width: "200px"
}));
oTable2.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Last Name"}),
template: new sap.ui.commons.TextView().bindProperty("text", "lastName"),
width: "200px"
}));
oTable2.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "First Name"}),
template: new sap.ui.commons.TextField().bindProperty("value", "name"),
width: "200px"
}));
//Create a model and bind the table rows to this model
var oModel2 = new sap.ui.model.json.JSONModel();
oModel2.setData({modelData: aData});
oTable2.setModel(oModel2);
oTable2.bindRows("/modelData");
//Initially sort the table
oTable2.sort(oTable2.getColumns()[0]);
//Bring the table onto the UI
oTable2.placeAt("content");
});
</script>
<body class="sapUiBody" id="content">
</body>
</html>
See the screenshot below:
Please find the updated function code hope this helps
sap.ui.getCore().attachInit(function() {
//Define some sample data
var aData = [
{lastName: "Dente", name: "Al"},
{lastName: "Friese", name: "Andy"},
{lastName: "Mann", name: "Anita"},
{lastName: "Schutt", name: "Doris"},
{lastName: "Open", name: "Doris"},
{lastName: "Dewit", name: "Kenya"}
];
//Create an instance of the table control
var oTable2 = new sap.ui.table.Table({
visibleRowCount: 7,
firstVisibleRow: 3
});
oTable2.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Index"}),
template: new sap.ui.commons.TextView().bindProperty("text", "rowIndex"),
width: "200px"
}));
//Define the columns and the control templates to be used
oTable2.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Last Name"}),
template: new sap.ui.commons.TextView().bindProperty("text", "lastName"),
width: "200px"
}));
oTable2.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "First Name"}),
template: new sap.ui.commons.TextField().bindProperty("value", "name"),
width: "200px"
}));
function fnAppenData(count,data, objName){
return Array.apply(null, Array(count)).map(function(obj, i) {
var obj = data[i];
var name = data[i][objName];
data[i][objName] = (i + 1) + " " + name;
data[i]["rowIndex"] = (i + 1);
var returndata = data[i];
return returndata;
//return {name: names[i % names.length] + i};
});
}
//Create a model and bind the table rows to this model
var oModel2 = new sap.ui.model.json.JSONModel(fnAppenData(aData.length, aData, "lastName"));
oModel2.setData({modelData: aData});
oTable2.setModel(oModel2);
oTable2.bindRows("/modelData");
//Initially sort the table
oTable2.sort(oTable2.getColumns()[0]);
//Bring the table onto the UI
oTable2.placeAt("content");
});
sample output:
I have a Google Visualization Column Chart from a query that works fine. I can set the a columns with a style role after the query by using the code snippet below. It adds a new column to the query data and sets the role as "Style". This colors each of the column chart bars accordingly. But I want to be able to use one of my query columns "C" for example as the color code and not have to add it afterward. I can't seem to get this to work. Any ideas? I posted more of my code below the snippet so you can see where I'm coming from. Thanks so much guys for any help you can give. Brandon
var data = response.getDataTable();
data.addColumn({type: "string", role: "style" });
data.setCell(0,2,'red');
data.setCell(1,2,'orange');
data.setCell(2,2,'green');
data.setCell(3,2,'yellow');
// More code above this, but I ommited it.
function drawDashboard() {
var query = new google.visualization.Query(
'URL');
query.setQuery('SELECT A, B, C');
query.send(handleQueryResponse);
}
function handleQueryResponse(response) {
if (response.isError()) {
alert('Error in query: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
data.addColumn({type: "string", role: "style" });
data.setCell(0,2,'red');
data.setCell(1,2,'orange');
data.setCell(2,2,'green');
data.setCell(3,2,'yellow');
// Create a dashboard.
var dashboard = new google.visualization.Dashboard(
document.getElementById('dashboard_div'));
// Create a range slider, passing some options
var scoreSlider = new google.visualization.ControlWrapper({
controlType: 'NumberRangeFilter',
containerId: 'filter_div',
options: {
filterColumnLabel: 'Class AVG'
}
});
var ClassFilter = new google.visualization.ControlWrapper({
controlType: 'CategoryFilter',
containerId: 'Classfilter_div',
options: {
'filterColumnLabel': 'Teacher Name','ui': { 'labelStacking': 'veClasscal','allowTyping': true,'allowMultiple': true
}
}});
// Create a Column Bar chart, passing some options
var columnChart = new google.visualization.ChartWrapper({
chartType: 'ColumnChart',
containerId: 'chart_div',
options: {
title: 'Math Proficiency by Class',
height: 320,
width: 500,
chartArea:{left:"10%",top:"10%",width:"80%",height:"60%"},
hAxis: {textStyle: {fontSize:14}, title: 'Teacher Name', titleTextStyle: {fontSize:14}, textStyle: {fontSize:14}},
vAxis: {minValue: 0, maxValue: 100, title: 'Math Proficiency AVG', titleTextStyle: {fontSize:14}, textStyle: {fontSize:14}},
legend: {position: 'none'},
animation: {duration:1500, easing:'out'},
colors: ['#a4c2f4','#3c78d8']
},
view: {columns: [0, 1, 2]}
});
// Define a table
var table = new google.visualization.ChartWrapper({
chartType: 'Table',
dataTable: data,
containerId: 'table_div',
options: {
width: '400px'
},
view: {columns: [0, 1,]}
});
// Establish dependencies, declaring that 'filter' drives 'ColumnChart',
// so that the column chart will only display entries that are let through
// given the chosen slider range.
dashboard.bind([scoreSlider], [table, columnChart]);
dashboard.bind([ClassFilter], [table, columnChart]);
// Draw the dashboard.
dashboard.draw(data);
}// More code below this, but I ommited it.
I'm not sure how you would add this to a column in the query but...
using a DataView with a calculated column should work...
Assumes the value you want to test is in the second column -- index 1
var data = response.getDataTable();
var view = new google.visualization.DataView(data);
view.setColumns([0, 1, {
type: "string",
role: "style",
calc: function (dataTable, rowIndex) {
if (dataTable.getValue(rowIndex, 1) < 0.69) {
return 'color: red;';
} else if ((dataTable.getValue(rowIndex, 1) >= 0.69) && (dataTable.getValue(rowIndex, 1) <= 0.79)) {
return 'color: yellow;';
} else {
return 'color: green;';
}
}
}]);
I'm stuck. I can't get my checkbox functional. I would like to toggle two layers with a checkbox. The two layers should be on when loaded (check box checked) and then turned off when unchecked. Simple, I know, but I can't get it functional despite looking at lots of working examples and checking all the posts. Most of the stuff I found were how it worked with KML and fusion tables. I have something working kinda that works for a button but this doesn't work well for check boxes.
Here is the code for the drop down box with the check boxes.
tileNEX = new google.maps.ImageMapType({
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity:0.50,
name : 'NEXRAD',
isPng: true
});
goes = new google.maps.ImageMapType({
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/goes-ir-4km-900913/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity:0.50,
name : 'GOES NA Vis',
isPng: true
});
//create the check box items
var radarOptions = {
gmap: map,
title: "This allows for selection/toggling on/off Radar layer",
id: "radarCheck",
label: "Radar",
action: function(){
if (map.overlayMapTypes.length==0) {
map.overlayMapTypes.push(null); // create empty overlay entry
map.overlayMapTypes.setAt("1",tileNEX);
}
else {
map.overlayMapTypes.clear();
}
}
}
var check1 = new checkBox(radarOptions);
var radarAnimate = {
gmap: map,
title: "This allows for selection/toggling on/off Animated Radar",
id: "radarAnimate",
label: "Animate Radar",
action: function(){
alert('Function is coming soon');
}
}
var check2 = new checkBox(radarAnimate);
var satOptions = {
gmap: map,
title: "This allows for selection/toggling on/off Satelite layer",
id: "satCheck",
label: "Satellite",
action: function(){
if (map.overlayMapTypes.length==0) {
map.overlayMapTypes.push(null); // create empty overlay entry
map.overlayMapTypes.setAt("1",goes);
}
else {
map.overlayMapTypes.clear();
}
}
}
var check3 = new checkBox(satOptions);
//create the input box items
//possibly add a separator between controls
var sep = new separator();
//put them all together to create the drop down
var ddDivOptions = {
items: [sep, check1, check2, check3],
id: "myddOptsDiv"
}
//alert(ddDivOptions.items[1]);
var dropDownDiv = new dropDownOptionsDiv(ddDivOptions);
var dropDownOptions = {
gmap: map,
name: 'Options',
id: 'ddControl',
title: 'A custom drop down select with mixed elements',
position: google.maps.ControlPosition.TOP_RIGHT,
dropDown: dropDownDiv
}
var dropDown1 = new dropDownControl(dropDownOptions);
FULL CODE
LINK TO MAP