I use a column chart. When clicking at one of the rows in the diagram my listener trigger an event:
google.visualization.events.addListener(chart, 'select', renderList);
I am only able to retrieve the number 2456 and not 6. Number 6 is the value of my first column. I have two columns in my table. Can someone please help me with this? I've been struggling for quite some time.
This is the instantiation of the chart:
<script type="text/javascript">
$("select").change(function () {
drawChart();
});
function drawChart() {
var inputData = {
rooms: $("#Rooms").val(), area: $("#Areas").val(), apartmentType: $("#ApartmentType").val(),
queue: $("#Queue").val(), year: $("#Years").val()
}
$.ajax({
url: '#Url.Action("AllocatedApartments", "Statistics")',
dataType: 'json',
data: inputData,
type: 'POST',
success: function (data) {
tdata = new google.visualization.DataTable();
tdata.addColumn('number', 'Antal bostäder');
tdata.addColumn('number', 'Kötid');
$.each(data.GroupedList, function (key, value) {
tdata.addRow([value.QueueTime, value.Count])
});
var options = {
title: 'Förmedlade bostäder',
backgroundColor: "F1F1F1",
colors: ['73a948'],
legend: { "position": "none" },
vAxis: { title: 'Antal förmedlade bostäder', titleTextStyle: { color: 'gray' } },
hAxis: { title: 'Kötidsintervall (antal år)', titleTextStyle: { color: 'gray' } }
};
chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(tdata, options);
google.visualization.events.addListener(chart, 'select', renderList);
}
});
}
</script>
In the function renderList I want to fetch the label of the row selected:
function renderList() {
var selection = chart.getSelection();
var value = tdata.getValue(selection.row, selection.column );
alert(value)
$.ajax({
url: '#Url.Action("RenderApartmentList", "Statistics")',
dataType: 'json',
type: 'POST',
data: inputData,
success: function (data) {
var html = Mustache.to_html(template, data)
$("#myPartialViewContainer").html(html);
},
error: function (xhr) {
alert("Ett fel uppstod, var god försök igen om en liten stund.")
}
});
}
For this part of code
function renderList() {
var selection = chart.getSelection();
var value = tdata.getValue(selection.row, selection.column );
alert(value)
...
you have to receive error in console log:
Uncaught Error: Invalid row index undefined. Should be in the range [0-53].
getSelection() returns an array. So you have to change that to:
function renderList() {
var selection = chart.getSelection();
var value = tdata.getValue(selection[0].row, selection[0].column );
See google docs about Column chart: getSelection() Array of selection elements
And Extended description of getSelection()
Related
I Have tried all the links but no one works with my code
I am trying to add a button to google chart hover tooltip
this is my code
result is data that im bringing to chart
my data need to be grouped all works fine but how i can add a button in
bottom of my tooltip
see the image
`<script>
google.charts.load('current', {packages: ['corechart']});
function drawChart() {
// Define the chart to be drawn.
var data = google.visualization.arrayToDataTable(result, true);
var groupData = google.visualization.data.group(
data,
[1, 0, 2], // group on both columns, age group first
[{
column: 1,
aggregation: google.visualization.data.count,
type: 'number'
}]
);
var view = new google.visualization.DataView(groupData);
// init column arrays
// use age group as first column
var viewColumns = [0];
var aggColumns = [];
// build view & agg columns for each gender
groupData.getDistinctValues(1).forEach(function (surveyName, index) {
// add view column for each gender
viewColumns.push({
calc: function (dt, row) {
if (dt.getValue(row, 1) === surveyName) {
return dt.getValue(row, 2);
}
return null;
},
label: surveyName,
type: 'number'
});
// add agg column
aggColumns.push({
aggregation: google.visualization.data.sum,
column: index + 1,
label: surveyName,
type: 'number'
});
});
// set view columns
view.setColumns(viewColumns);
// agg view by age group
var aggData = google.visualization.data.group(
view,
[0],
aggColumns
);
var options = {
title: '',
titleTextStyle: {
color: '#98D015',
fontName: 'Baloo Paaji 2',
fontSize: '25',
margin: 10,
},
titlePosition: 'center',
colors: ['#B42987','3E5F27','#A58C21','#7030A0','#C59EE2','#243254','#F8CBAD','#00B0F0','#B4C7E7','#FFC000'],
theme: 'material',
legend: {
maxLines: 2,
position: 'bottom'
},
chartArea: {top: 20 , width: '80%', height: '60%'},
tooltip: {
isHtml: true,
trigger: 'both'
},
};
// Instantiate and draw the chart.
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(aggData, options);
}
google.charts.setOnLoadCallback(drawChart);
`
this is what i am trying to achieve
enter image description here
Good Morning.
To work with wfs layer is it better to use leaflet or openlayers?
I have a code with openlayers that returns WFS from the geoserver. But I'm not able to show the attributes in popup. can anybody help me?
Thanks
You can try ol-ext ol/Overlay/PopupFeature to display feature attributes in a popup.
See example: https://viglino.github.io/ol-ext/examples/popup/map.popup.feature.html
Following the example of https://viglino.github.io/ol-ext/examples/popup/map.popup.feature.html, I have this code where my WFS layer contains the id and name attributes, however, it doesn't show anything in the popup
var vectorSource = new ol.source.Vector({
format: new ol.format.GeoJSON(),
url: function(extent) {
return 'http://localhost:8080/geoserver/teste/wfs?service=WFS&' +
version=1.1.0&request=GetFeature&typename=teste:MYLAYER&' +
'outputFormat=application/json&srsname=EPSG:4326&' +
'bbox=' + extent.join(',') + ',EPSG:4326';
},
strategy: ol.loadingstrategy.bbox
});
var vector = new ol.layer.Vector({
source: vectorSource,
style: new ol.style.Style({
stroke: new ol.style.Stroke({
color: 'rgba(0, 0, 255, 1.0)',
width: 2
})
})
});
var layers = [
new ol.layer.Tile({source: new ol.source.OSM()}),
vector,
];
var map = new ol.Map({
layers: layers,
interactions: ol.interaction.defaults({ altShiftDragRotate:false, pinchRotate:false }),
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([-46.444137, -23.713596]),
zoom: 12
})
});
var select = new ol.interaction.Select({
hitTolerance: 5,
multi: true,
condition: ol.events.condition.singleClick
});
map.addInteraction(select);
var popup = new ol.Overlay.PopupFeature({
popupClass: 'default anim',
select: select,
canFix: true,
template: {
title:
function(f) {
return f.get('nome')+' ('+f.get('id')+')';
},
attributes: // [ 'id', 'nome' ]
{
'nome': { title: 'Nome' },
'id': { title: 'Id' },
}
}
});
map.addOverlay (popup);
This is the popup code. I have 3 layers: layer1, layer2 and layer3.
For layer1, ID I want to show as ID. For layer2, I want to show ID as CODE and for other layers I don't want to show ID attribute.
How should I change the template? Thanks
var popup = new ol.Overlay.PopupFeature({
popupClass: 'default anim',
select: select_interaction,
canFix: true,
template: {
title:
function(f) {
return f.get('NAME')+' ('+f.get('ID')+')';
},
attributes:
{
'ID': { title: 'ID' },
// with prefix and suffix
'POP': {
title: 'População', // attribute's title
before: '', // something to add before
format: ol.Overlay.PopupFeature.localString(), // format as local string
after: ' hab.' // something to add after
},
}
}
});
#user12538529
You have to create a function and return the template for each case:
// Create templates
var templateID = { ... };
var templateCODE = { ... };
// Popup with a template function
var popup = new ol.Overlay.PopupFeature({
popupClass: 'default anim',
select: select_interaction,
canFix: true,
template: function(feature) {
var prop = feature.getProperties();
// Test if has property ID
if (prop.hasOwnProperty('ID')) return templateID;
// or property CODE
else if (prop.hasOwnProperty('CODE')) return templateCODE;
}
});
I have a problem with migrating the plugin from tinymce 4 to tinymka 5. The console tells me "Uncaught (in promise) TypeError: btn.active is not a function"
I can not find an equivalent for tinymce 5. Can someone replace it?
Code below:
tinymce.PluginManager.add('phonelink', function(editor, url) {
// Add a button that opens a window
var linkText = "";
var linkTitle = "";
var link = "";
// tinymce.DOM.loadCSS(url + '/css/phonelink.css');
editor.ui.registry.addButton('phonelink2', {
text: 'asddas',
icon: 'image-options',
onSetup: updateOnSelect,
onAction: onClickPhoneButton
});
// Adds a menu item to the tools menu
editor.ui.registry.addMenuItem('phonelink', {
text: 'asddas',
icon: 'image-options',
context: 'tools',
onAction: onClickPhoneButton,
onSetup: updateOnSelect
});
function onClickPhoneButton(){
editor.windowManager.open({
title: '123213123',
body: {
type: 'panel',
items: [
{type: 'input', name: 'phone', label: 'Teléfono', value: link},
{type: 'input', name: 'showtext', label: 'Texto a mostrar', value: linkText},
{type: 'input', name: 'title', label: 'Título', value: linkTitle}
]
},
buttons: [
{
text: 'Close',
type: 'cancel',
onclick: 'close'
},
{
type: 'submit',
name: 'submitButton',
text: 'Stwórz',
primary: true
}
],
onAction: function(e) {
alert('Toggle menu item clicked');
},
onSubmit: function(e) {
var data = e.getData();
var hrefLink = '<a title="' + data .title + '" href="tel:+34' + data .phone + '">' + data .showtext + '</a>';
if(link !== ''){
editor.setContent(hrefLink);
}else{
editor.insertContent(hrefLink);
}
e.close();
}
});
}
function updateOnSelect() {
var btn = this;
const editorEventCallback = function (e) {
var node = editor.selection.getNode();
var isTelLink = node.href !== undefined && node.href.indexOf('tel:+') !== -1
btn.active(isTelLink);
if(isTelLink){
link = node.href;
link = link.replace("tel:+34", "");
linkTitle = node.title;
linkText = node.text;
}
};
editor.on('NodeChange', editorEventCallback);
return function (btn) {
editor.off('NodeChange', editorEventCallback);
}
}
});
I searched the documentation for a replacement, but found nothing.
TinyMCE 5 no longer passes the button and menu instance via this. Instead it passes an API instance as the first parameter, so you'll want to change your updateOnSelect function to something like this:
function updateOnSelect(api) {
const editorEventCallback = function (e) {
var node = editor.selection.getNode();
var isTelLink = node.href !== undefined && node.href.indexOf('tel:+') !== -1
api.setActive(isTelLink);
if(isTelLink){
link = node.href;
link = link.replace("tel:+34", "");
linkTitle = node.title;
linkText = node.text;
}
};
editor.on('NodeChange', editorEventCallback);
return function (btn) {
editor.off('NodeChange', editorEventCallback);
}
}
You'll note var btn = this has been removed and that the API to set an item as active is setActive instead of active. This can be found in the documentation here: https://www.tiny.cloud/docs/ui-components/typesoftoolbarbuttons/#togglebutton and https://www.tiny.cloud/docs/ui-components/menuitems/#togglemenuitems (see the API section in both links).
In the above, you may have noticed both reference "Toggle" items. That's another change in TinyMCE 5, as different types of buttons/menu items have a separate registration API. So you'll also need to swap to using editor.ui.registry.addToggleButton and editor.ui.registry.addToggleMenuItem. More details about that can be found here if needed: https://www.tiny.cloud/docs/migration-from-4x/#customtoolbarbuttons
Here's an example fiddle showing the changes mentioned above: https://fiddle.tiny.cloud/B5haab.
Hopefully that helps!
I'm a newbie of javascript, trying to build an interactive map online, where some events should be triggered by clicking on markers and some just by hovering them.
Managed to have the click part working, but, because of Markercluster plugin, I'm not sure where to use onEachFeature function for having the tooltip opened by hover a single marker.
Anyone please can tell me what I'm doing wrong?
var geoJsonFeature = {
type: 'FeatureCollection',
features:
[
{
type: 'Feature',
properties: {
title: 'Title',
page: 'some.html',
'marker-color': '#000000',
zoom: 7
},
geometry: {
type: 'Point',
coordinates: [12.583745,55.6750803]
}
},
...
};
// access to mapbox api
L.mapbox.accessToken ='...';
var map = L.mapbox.map('map', 'example1234').setView([34, -37], 3);
function getTitle(marker) {
return marker.feature.properties.title;
};
function getPage(marker) {
return marker.feature.properties.page;
};
var markerGroup = new L.MarkerClusterGroup({showCoverageOnHover:false});
var geoJsonLayer = L.geoJson(geoJsonFeature, {
onEachFeature: function (feature, layer) {
var popupContent = getTitle(marker);
layer.bindPopup(popupContent);
}
});
markerGroup.addLayer(geoJsonLayer);
map.addLayer(markerGroup);
markerGroup.on('click', function(ev) {
var marker = ev.layer;
marker.on('click', function(ev) {
if(map.getZoom() > marker.feature.properties.zoom) {
map.setView(ev.latlng, map.getZoom());
}
else {
map.setView(ev.latlng, marker.feature.properties.zoom);
}
});
});
});
geoJsonLayer.on('mouseover', function(e) {
e.layer.openPopup();
});
geoJsonLayer.on('mouseout', function(e) {
e.layer.closePopup();
});
You need to use the onEachFeature option to get the individual markers and bind handlers to the mouseover and mouseout events:
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.title);
layer.on("mouseover", function () {
layer.openPopup();
});
layer.on("mouseout", function () {
layer.closePopup();
});
}
Here's a working example on Plunker: http://plnkr.co/edit/hfjOWv3uCBFawDGqR3Ue?p=preview
Note: i'm not using ClusterMarker in this example but it should work just fine when using ClusterMarker
I am currently having problem in using the jQuery API for
TextboxList
what i want is that to access the selected value in the Json array form, now the documentation suggest to use:
$('#form_tags_input').textboxlist();
but when i use it in the jQuery function on button click to get values using [getValues]
method it said undefined.
here is the javascript:
<script type="text/javascript">
$(function () {
// Standard initialization
var t = new $.TextboxList('#SentTo', { unique: true, plugins: { autocomplete: { minlength: 2, onlyFromValues: true}} });
//t.addEvent('bitBoxAdd', ContactAdded);
//t.addEvent('bitBoxRemove', ContactRemoved);
t.getContainer().addClass('textboxlist-loading');
$.ajax({
url: '/Home/GetContacts',
dataType: 'json',
success: function (r) {
t.plugins['autocomplete'].setValues(r);
t.getContainer().removeClass('textboxlist-loading');
}
});
});
function GetValues() {
var tblist = $('#SentTo').textboxlist();
alert(tblist.getValues());
return false;
}
function ContactAdded(e) {
//alert(e);
//GetValues();
return false;
}
function ContactRemoved(e) {
//alert(e);
}
i am using GetValues() function on button click to getvalues.
A help would be much appreciated.
Thanks.
Try to made TextboxLists "t" variable global
The changed code is:
$(function () {
// Standard initialization
t = new $.TextboxList('#SentTo', { unique: true, plugins: { autocomplete: { minlength: 2, onlyFromValues: true}} });
//t.addEvent('bitBoxAdd', ContactAdded);
//t.addEvent('bitBoxRemove', ContactRemoved);
t.getContainer().addClass('textboxlist-loading');
$.ajax({
url: '/Home/GetContacts',
dataType: 'json',
success: function (r) {
t.plugins['autocomplete'].setValues(r);
t.getContainer().removeClass('textboxlist-loading');
}
});
});
function GetValues() {
alert(t.getValues());
return false;
}