When I select country on map, how can I get a value of this country and pass it to variable? Thanks a lot! I used amcharts.com
Or it can be another solution? I you know how to choose country on map, i'll be very grateful!
You can use "clickMapObject" event to catch all the information about clicked object. I.e.:
map.addListener("clickMapObject", function (event) {
alert( 'Clicked ID: ' + event.mapObject.id + ' (' + event.mapObject.title + ')' );
});
Here's a working example:
http://jsfiddle.net/amcharts/k67gB/light/
Please note that in order for this event to fire the country needs to be clickable. This means that either "autoZoom" needs to be enabled or all areas need to be set as "selectable":
var map = AmCharts.makeChart("mapdiv",{
...
"areasSettings": {
"autoZoom": true
}
});
Or
var map = AmCharts.makeChart("mapdiv",{
...
"areasSettings": {
"selectable": true
}
});
Related
I'm trying to get login user detail. I need to put data to state and used the same state for further processing it takes time to put data to state and use this data. nearly it takes 2- 3 sec to use the state with that data.
I solved this issue if we use setTimeOut() function with 3 sec so that we it updates data in this time. if we don't use setTimeOut() and use state wright after updating it then it will provide initial data of the state.
complete_date = date + ":" + month + ":" + year;
var query = firebase.database().ref('attendence/'+ complete_date +"/").orderByKey();
email_match=false;
entry_time =null,
l_id = null,
query.on("value",(data)=>
{
data.forEach(function(childs)
{
l_id = childs.key;
// __ to check if the user already loged in before.
var att_query = firebase.database().ref('attendence/'+ complete_date +"/"+ l_id).orderByKey();
att_query.once("value",(data)=>
{
if(email == data.child('email').val())
{
email_match = true;
entry_time = data.child('timeEntry').val();
}
}); //
}); //
this.setState({ last_id:l_id });
this.setState({ emailMatchState:email_match });
this.setState({alreayLogedState : entry_time});
}); // _____end of query.on("value",(data)=>
setTimeout(() =>
{
console.log("-----------------------------------");
console.log("already logged :",this.state.alreayLogedState," email match :",this.state.emailMatchState , " result : ", this.state.result , " last_id :",st.last_id);
console.log("-----------------------------------");
},3000);
I need to use state after updating without the use of setTimeout() for faster working of the application.
The second argument for setState is a callback to execute when all updates are done
this.setState({ last_id:l_id }, () => console.log(this.state.last_id))
setState takes an optional second argument that gets called after the updates to the state object have taken place.
example:
let callback = () => {
// do something
}
this.setState({
keyToUpdate: valueToUpdate
}, callback)
Additional reading about the use of this callback:
https://medium.learnreact.com/setstate-takes-a-callback-1f71ad5d2296?gi=18aa91e88437
Also, unless something is happening in between the seperate calls, these:
this.setState({ last_id:l_id });
this.setState({ emailMatchState:email_match });
this.setState({alreayLogedState : entry_time});
can be simplified to this:
this.setState({
last_id:l_id,
emailMatchState: email_match,
alreayLogedState: entry_time
}); //optionally add callback
So I have a little bit of form validation going on and I am running into an issue. When I first load the web app up and try adding a value and submitting with my button it doesn't allow me and gives me the error I want to see. However, when I add a value setState occurs and then my value is pushed to UI and I try to add another blank value it works and my conditional logic of checking for an empty string before doesn't not go through what am I doing wrong?
addItem() {
let todo = this.state.input;
let todos = this.state.todos;
let id = this.state.id;
if (this.state.input == '') {
alert("enter a value");
document.getElementById('error').style.color = 'red';
document.getElementById('error').innerHTML = 'Please enter something first';
}
else {
this.setState({
todos: todos.concat(todo),
id: id + 1,
}, () => {
document.getElementById('test').value = '';
})
console.log(this.state.id);
}
}
You are checking this.state.input but no where in that code are you setting the input value on the state.
Try adding this where it makes sense in your application:
this.setState({ input: 'some value' });
Also, I recommend you use the state to define the application UI. So instead of using document.getElementById('error') or document.getElementById('test').value, have the UI reflect what you have in your state.
See here for more info: https://reactjs.org/docs/forms.html
Instead of manipulating the DOM directly:
document.getElementById('test').value = '';
you'll want to use React:
this.setState({ input: '' });
A good ground rule for React is to not manipulate the DOM directly through calls like element.value = value or element.style.color = 'red'. This is what React (& setState) is for. Read more about this on reactjs.org.
Before you look for the solution of your issue, I noticed that you are directly updating the DOM
Examples
document.getElementById('error').style.color = 'red';
document.getElementById('error').innerHTML = 'Please enter something first';
document.getElementById('test').value = '';
Unless you have special use case or dealing with external plugins this isn't recommended, when dealing with React you should update using the virtual DOM. https://www.codecademy.com/articles/react-virtual-dom
Pseudo code sample
constructor(props) {
this.state = {
// retain previous states in here removed for example simplicity
errorString: ''
}
}
addItem() {
let todo = this.state.input;
let todos = this.state.todos;
let id = this.state.id;
if (this.state.input == '') {
alert("enter a value");
this.setState({
errorString: 'Please enter something first'
});
}
else {
this.setState({
todos: todos.concat(todo),
id: id + 1,
input: '',
});
}
}
// notice the "error" and "test" id this could be omitted I just added this for your reference since you mentioned those in your example.
render() {
return (
<div>
{(this.state.errorString !== '') ? <div id="error" style={{color: 'red'}}>{this.state.errorString}</div> : null}
<input id="test" value={this.state.input} />
</div>
}
Every time you invoke setState React will call render with the updated state this is the summary of what is happening but there are lot of things going behind setState including the involvement of Virtual DOM.
could you please tell me why I am getting undefined value .When I click on chart ? I make one bar chart and try to get it value .In other words try to get selected item and it’s value .
In give fiddle it gives correct value
http://jsfiddle.net/b4n9z19v/
But when I make directive and try to get it value it is giving me undefined why ?
here is code
http://plnkr.co/edit/FtDfeyd6fjHL3RNwzyCn?p=preview
$scope.chartObj = new Highcharts.Chart($scope.chartData);
$element.bind('click', function (event) {
// do your code
alert( $scope.chartData.chart.type);
alert('Category: ' + this.category + ', value: ' + this.y);
});
Why don't you add click event to the chart object, in a similar way as you did for data.json? Like this:
$scope.chartData.plotOptions.series.point.events.click = function (event) {
// do your code
alert( $scope.chartData.chart.type);
alert('Category: ' + this.category + ', value: ' + this.y);
};
See plunker: http://plnkr.co/edit/WA4TcDuoer3ix08T15QM?p=preview
I have this in my Angular app:
myApp.value(mySetting, mySettingValue);
Is it possible to $watch() mySetting for changes? I've tried but can't get it to work.
This doesn't seem to do the trick:
$rootScope.$watch(function() {
return mySetting;
, function(newSettingValue) {
console.log(Date.now() + ' ' + newSettingValue);
});
You missed to true property as a 3rd parameter inside your $watch, adding true will keep deep watch on object
Code
$rootScope.$watch(function() {
return mySetting;
, function(newSettingValue) {
console.log(Date.now() + ' ' + newSettingValue);
}, true);
Example Plunkr
My example :
var object = {
msg: 'context obj'
};
var object2 = {
msg: 'other context obj2'
};
_.extend(Object.prototype, Backbone.Events);
object.on("alert:boom", function() {
console.log("run " + this.msg);
}, object2);
object.on("all", function(eventName) {
console.log('all');
});
object.trigger("alert:boom");
object.trigger("alert:riri"); //Why called ALL ????
How to check whether that object has an event ?
I hope for your help.
It's unclear if your question is "How to check whether that object has an event ?" or "//Why called ALL ????" -- #AlexacderImra has answered the last one.
It is not recommended you check internal variables but it is very unlikely this will chage - the event array is _events so you can do:
if (myObject._events['myeventname'])
To check for a particular event, or:
if (myObject._events.length)
To check if there are any events.
It would be best to wrap that functionality in a function so that in the event it changes in future versions of Backbone you only have to update the logic in one place.
all is one of built-in Backbone events.
Callbacks bound to the special **all** event will be triggered when any event occurs, and are passed the name of the event as the first argument.
So if you want to want to know when any event occurs, do like:
Object.on('all', function(eventName) {
console.log('event [' + eventName + '] triggered');
});
Use JSON.stringify, check inside it.
JSON.stringify(object)