AMCharts 4 - Map stroke uneven when applied to single countries The Next CEO of Stack OverflowValue of selected country amchartsamCharts center mapAmchart dynamically load maps with scrollTo colored the particular country using amcharts using country nameAMcharts Map in angular jsHow to make a world map with clickable countries in AMcharts?Page is reloading when using 'LinkToObject' in amChart MapHover group of countries instead of single one on Amcharts 4AmCharts maps - how to get only 2 first letters of country name?Exclude countries dynamically amCharts
Won the lottery - how do I keep the money?
sp_blitzCache results Memory grants
Indicator light circuit
Why don't programming languages automatically manage the synchronous/asynchronous problem?
What's the best way to handle refactoring a big file?
Is micro rebar a better way to reinforce concrete than rebar?
Is 'diverse range' a pleonastic phrase?
How do I transpose the 1st and -1th levels of an arbitrarily nested array?
Sending manuscript to multiple publishers
Why do remote companies require working in the US?
Complex fractions
Does it take more energy to get to Venus or to Mars?
What happens if you roll doubles 3 times then land on "Go to jail?"
How do we know the LHC results are robust?
Unreliable Magic - Is it worth it?
How does the Z80 determine which peripheral sent an interrupt?
What does convergence in distribution "in the Gromov–Hausdorff" sense mean?
How do I reset passwords on multiple websites easily?
What benefits would be gained by using human laborers instead of drones in deep sea mining?
Inappropriate reference requests from Journal reviewers
Bold, vivid family
Can I equip Skullclamp on a creature I am sacrificing?
MessageLevel in QGIS3
Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?
AMCharts 4 - Map stroke uneven when applied to single countries
The Next CEO of Stack OverflowValue of selected country amchartsamCharts center mapAmchart dynamically load maps with scrollTo colored the particular country using amcharts using country nameAMcharts Map in angular jsHow to make a world map with clickable countries in AMcharts?Page is reloading when using 'LinkToObject' in amChart MapHover group of countries instead of single one on Amcharts 4AmCharts maps - how to get only 2 first letters of country name?Exclude countries dynamically amCharts
As you can see in the above image. I've applied a stroke to the USA. However the top of the mainland stroke is clearly thinner than the rest of the stroke. My config is below:
polygonTemplate.stroke = am4core.color('#2c2626')
polygonTemplate.strokeWidth = 0
polygonTemplate.nonScalingStroke = true
And then I have an adaptor to stroke the active country,
polygonTemplate.adapter.add('strokeWidth', (stroke, target) =>
if (target.dataItem && target.dataItem.dataContext && this.selectedCountry)
if (target.dataItem.dataContext.id === this.selectedCountry.id)
return 2
return stroke
)
From what I can find from examples online, this is the right way to apply a stroke. Is there a way I can make this stroke even all around the country? It happens on most countries but there are a few where it's not as bad..
EDIT: Thanks to Sam for his help, I now have an even stroke. But it seems I've got to press on a new country twice for it to take the active state - once to toggle the old country to inactive, then once again to add the active state. GIF below
maps amcharts
add a comment |
As you can see in the above image. I've applied a stroke to the USA. However the top of the mainland stroke is clearly thinner than the rest of the stroke. My config is below:
polygonTemplate.stroke = am4core.color('#2c2626')
polygonTemplate.strokeWidth = 0
polygonTemplate.nonScalingStroke = true
And then I have an adaptor to stroke the active country,
polygonTemplate.adapter.add('strokeWidth', (stroke, target) =>
if (target.dataItem && target.dataItem.dataContext && this.selectedCountry)
if (target.dataItem.dataContext.id === this.selectedCountry.id)
return 2
return stroke
)
From what I can find from examples online, this is the right way to apply a stroke. Is there a way I can make this stroke even all around the country? It happens on most countries but there are a few where it's not as bad..
EDIT: Thanks to Sam for his help, I now have an even stroke. But it seems I've got to press on a new country twice for it to take the active state - once to toggle the old country to inactive, then once again to add the active state. GIF below
maps amcharts
add a comment |
As you can see in the above image. I've applied a stroke to the USA. However the top of the mainland stroke is clearly thinner than the rest of the stroke. My config is below:
polygonTemplate.stroke = am4core.color('#2c2626')
polygonTemplate.strokeWidth = 0
polygonTemplate.nonScalingStroke = true
And then I have an adaptor to stroke the active country,
polygonTemplate.adapter.add('strokeWidth', (stroke, target) =>
if (target.dataItem && target.dataItem.dataContext && this.selectedCountry)
if (target.dataItem.dataContext.id === this.selectedCountry.id)
return 2
return stroke
)
From what I can find from examples online, this is the right way to apply a stroke. Is there a way I can make this stroke even all around the country? It happens on most countries but there are a few where it's not as bad..
EDIT: Thanks to Sam for his help, I now have an even stroke. But it seems I've got to press on a new country twice for it to take the active state - once to toggle the old country to inactive, then once again to add the active state. GIF below
maps amcharts
As you can see in the above image. I've applied a stroke to the USA. However the top of the mainland stroke is clearly thinner than the rest of the stroke. My config is below:
polygonTemplate.stroke = am4core.color('#2c2626')
polygonTemplate.strokeWidth = 0
polygonTemplate.nonScalingStroke = true
And then I have an adaptor to stroke the active country,
polygonTemplate.adapter.add('strokeWidth', (stroke, target) =>
if (target.dataItem && target.dataItem.dataContext && this.selectedCountry)
if (target.dataItem.dataContext.id === this.selectedCountry.id)
return 2
return stroke
)
From what I can find from examples online, this is the right way to apply a stroke. Is there a way I can make this stroke even all around the country? It happens on most countries but there are a few where it's not as bad..
EDIT: Thanks to Sam for his help, I now have an even stroke. But it seems I've got to press on a new country twice for it to take the active state - once to toggle the old country to inactive, then once again to add the active state. GIF below
maps amcharts
maps amcharts
edited Mar 8 at 16:23
Josh Undefined
asked Mar 7 at 15:14
Josh UndefinedJosh Undefined
60911119
60911119
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The Problem is, that the bordering countries are overlapping the stroke of your selected country. I increased the strokeWidth
to 10 and set the fillOpacity
to 0.6. You can clearly see that in the following picture or in that code pen.
Also setting the zIndex
in an adapter doesn't change anything for me.
But you can use states:
Create an active (or a custom) state with the properties you want to use. You can also use zIndex
there. Now set that state to every country you want to highlight.
var polygonTemplate = polygonSeries.mapPolygons.template;
polygonTemplate.tooltipText = "name";
polygonTemplate.fillOpacity = 0.6;
polygonTemplate.stroke = am4core.color('#2c2626');
polygonTemplate.strokeWidth = 0;
polygonTemplate.zIndex = 0;
polygonTemplate.nonScalingStroke = true;
// Create active state
var activeState = polygonTemplate.states.create("active");
activeState.properties.strokeWidth = 10;
activeState.properties.zIndex = 1;
// Create an event to toggle "active" statestate
polygonTemplate.events.on("hit", function(ev)
ev.target.isActive = !ev.target.isActive;
console.log(ev.target.dataItem.dataContext.id);
);
chart.events.once('inited', event =>
polygonSeries.mapPolygons.values.find(i => i.dataItem.dataContext.id === 'US').isActive = true;
);
Here is the result:
This code pen shows the states example. Hope that helps.
EDIT:
To use double click to toggle the active state you can just replace the hit
event with the doublehit
event (docs). But you maybe want to disable zoom on double click now. That's possible with the following lines (docs):
chart.seriesContainer.events.disableType("doublehit");
chart.chartContainer.background.events.disableType("doublehit");
I created this code pen to show you an example.
Hey thanks for this. It seems to be working, however i need to press countries twice for the active state to trigger. Any thoughts?
– Josh Undefined
Mar 8 at 11:59
You can just replace thehit
event withdoublehit
. I updated my answer according to that and included a code pen.
– Samuel Philipp
Mar 8 at 15:02
Ah I'm sorry Sam, perhaps I was not clear - I've edited my OP to include a gif of what is happening. But basically it seems like I've got to click once to toggle off the active state from one country, then click again to add it to the new country.
– Josh Undefined
Mar 8 at 16:21
Nevermind! It was my only computed function in vue which was destroying the active prop AMcharts makes :)
– Josh Undefined
Mar 8 at 16:35
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047122%2famcharts-4-map-stroke-uneven-when-applied-to-single-countries%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Problem is, that the bordering countries are overlapping the stroke of your selected country. I increased the strokeWidth
to 10 and set the fillOpacity
to 0.6. You can clearly see that in the following picture or in that code pen.
Also setting the zIndex
in an adapter doesn't change anything for me.
But you can use states:
Create an active (or a custom) state with the properties you want to use. You can also use zIndex
there. Now set that state to every country you want to highlight.
var polygonTemplate = polygonSeries.mapPolygons.template;
polygonTemplate.tooltipText = "name";
polygonTemplate.fillOpacity = 0.6;
polygonTemplate.stroke = am4core.color('#2c2626');
polygonTemplate.strokeWidth = 0;
polygonTemplate.zIndex = 0;
polygonTemplate.nonScalingStroke = true;
// Create active state
var activeState = polygonTemplate.states.create("active");
activeState.properties.strokeWidth = 10;
activeState.properties.zIndex = 1;
// Create an event to toggle "active" statestate
polygonTemplate.events.on("hit", function(ev)
ev.target.isActive = !ev.target.isActive;
console.log(ev.target.dataItem.dataContext.id);
);
chart.events.once('inited', event =>
polygonSeries.mapPolygons.values.find(i => i.dataItem.dataContext.id === 'US').isActive = true;
);
Here is the result:
This code pen shows the states example. Hope that helps.
EDIT:
To use double click to toggle the active state you can just replace the hit
event with the doublehit
event (docs). But you maybe want to disable zoom on double click now. That's possible with the following lines (docs):
chart.seriesContainer.events.disableType("doublehit");
chart.chartContainer.background.events.disableType("doublehit");
I created this code pen to show you an example.
Hey thanks for this. It seems to be working, however i need to press countries twice for the active state to trigger. Any thoughts?
– Josh Undefined
Mar 8 at 11:59
You can just replace thehit
event withdoublehit
. I updated my answer according to that and included a code pen.
– Samuel Philipp
Mar 8 at 15:02
Ah I'm sorry Sam, perhaps I was not clear - I've edited my OP to include a gif of what is happening. But basically it seems like I've got to click once to toggle off the active state from one country, then click again to add it to the new country.
– Josh Undefined
Mar 8 at 16:21
Nevermind! It was my only computed function in vue which was destroying the active prop AMcharts makes :)
– Josh Undefined
Mar 8 at 16:35
add a comment |
The Problem is, that the bordering countries are overlapping the stroke of your selected country. I increased the strokeWidth
to 10 and set the fillOpacity
to 0.6. You can clearly see that in the following picture or in that code pen.
Also setting the zIndex
in an adapter doesn't change anything for me.
But you can use states:
Create an active (or a custom) state with the properties you want to use. You can also use zIndex
there. Now set that state to every country you want to highlight.
var polygonTemplate = polygonSeries.mapPolygons.template;
polygonTemplate.tooltipText = "name";
polygonTemplate.fillOpacity = 0.6;
polygonTemplate.stroke = am4core.color('#2c2626');
polygonTemplate.strokeWidth = 0;
polygonTemplate.zIndex = 0;
polygonTemplate.nonScalingStroke = true;
// Create active state
var activeState = polygonTemplate.states.create("active");
activeState.properties.strokeWidth = 10;
activeState.properties.zIndex = 1;
// Create an event to toggle "active" statestate
polygonTemplate.events.on("hit", function(ev)
ev.target.isActive = !ev.target.isActive;
console.log(ev.target.dataItem.dataContext.id);
);
chart.events.once('inited', event =>
polygonSeries.mapPolygons.values.find(i => i.dataItem.dataContext.id === 'US').isActive = true;
);
Here is the result:
This code pen shows the states example. Hope that helps.
EDIT:
To use double click to toggle the active state you can just replace the hit
event with the doublehit
event (docs). But you maybe want to disable zoom on double click now. That's possible with the following lines (docs):
chart.seriesContainer.events.disableType("doublehit");
chart.chartContainer.background.events.disableType("doublehit");
I created this code pen to show you an example.
Hey thanks for this. It seems to be working, however i need to press countries twice for the active state to trigger. Any thoughts?
– Josh Undefined
Mar 8 at 11:59
You can just replace thehit
event withdoublehit
. I updated my answer according to that and included a code pen.
– Samuel Philipp
Mar 8 at 15:02
Ah I'm sorry Sam, perhaps I was not clear - I've edited my OP to include a gif of what is happening. But basically it seems like I've got to click once to toggle off the active state from one country, then click again to add it to the new country.
– Josh Undefined
Mar 8 at 16:21
Nevermind! It was my only computed function in vue which was destroying the active prop AMcharts makes :)
– Josh Undefined
Mar 8 at 16:35
add a comment |
The Problem is, that the bordering countries are overlapping the stroke of your selected country. I increased the strokeWidth
to 10 and set the fillOpacity
to 0.6. You can clearly see that in the following picture or in that code pen.
Also setting the zIndex
in an adapter doesn't change anything for me.
But you can use states:
Create an active (or a custom) state with the properties you want to use. You can also use zIndex
there. Now set that state to every country you want to highlight.
var polygonTemplate = polygonSeries.mapPolygons.template;
polygonTemplate.tooltipText = "name";
polygonTemplate.fillOpacity = 0.6;
polygonTemplate.stroke = am4core.color('#2c2626');
polygonTemplate.strokeWidth = 0;
polygonTemplate.zIndex = 0;
polygonTemplate.nonScalingStroke = true;
// Create active state
var activeState = polygonTemplate.states.create("active");
activeState.properties.strokeWidth = 10;
activeState.properties.zIndex = 1;
// Create an event to toggle "active" statestate
polygonTemplate.events.on("hit", function(ev)
ev.target.isActive = !ev.target.isActive;
console.log(ev.target.dataItem.dataContext.id);
);
chart.events.once('inited', event =>
polygonSeries.mapPolygons.values.find(i => i.dataItem.dataContext.id === 'US').isActive = true;
);
Here is the result:
This code pen shows the states example. Hope that helps.
EDIT:
To use double click to toggle the active state you can just replace the hit
event with the doublehit
event (docs). But you maybe want to disable zoom on double click now. That's possible with the following lines (docs):
chart.seriesContainer.events.disableType("doublehit");
chart.chartContainer.background.events.disableType("doublehit");
I created this code pen to show you an example.
The Problem is, that the bordering countries are overlapping the stroke of your selected country. I increased the strokeWidth
to 10 and set the fillOpacity
to 0.6. You can clearly see that in the following picture or in that code pen.
Also setting the zIndex
in an adapter doesn't change anything for me.
But you can use states:
Create an active (or a custom) state with the properties you want to use. You can also use zIndex
there. Now set that state to every country you want to highlight.
var polygonTemplate = polygonSeries.mapPolygons.template;
polygonTemplate.tooltipText = "name";
polygonTemplate.fillOpacity = 0.6;
polygonTemplate.stroke = am4core.color('#2c2626');
polygonTemplate.strokeWidth = 0;
polygonTemplate.zIndex = 0;
polygonTemplate.nonScalingStroke = true;
// Create active state
var activeState = polygonTemplate.states.create("active");
activeState.properties.strokeWidth = 10;
activeState.properties.zIndex = 1;
// Create an event to toggle "active" statestate
polygonTemplate.events.on("hit", function(ev)
ev.target.isActive = !ev.target.isActive;
console.log(ev.target.dataItem.dataContext.id);
);
chart.events.once('inited', event =>
polygonSeries.mapPolygons.values.find(i => i.dataItem.dataContext.id === 'US').isActive = true;
);
Here is the result:
This code pen shows the states example. Hope that helps.
EDIT:
To use double click to toggle the active state you can just replace the hit
event with the doublehit
event (docs). But you maybe want to disable zoom on double click now. That's possible with the following lines (docs):
chart.seriesContainer.events.disableType("doublehit");
chart.chartContainer.background.events.disableType("doublehit");
I created this code pen to show you an example.
edited Mar 8 at 15:01
answered Mar 8 at 8:57
Samuel PhilippSamuel Philipp
3,2591627
3,2591627
Hey thanks for this. It seems to be working, however i need to press countries twice for the active state to trigger. Any thoughts?
– Josh Undefined
Mar 8 at 11:59
You can just replace thehit
event withdoublehit
. I updated my answer according to that and included a code pen.
– Samuel Philipp
Mar 8 at 15:02
Ah I'm sorry Sam, perhaps I was not clear - I've edited my OP to include a gif of what is happening. But basically it seems like I've got to click once to toggle off the active state from one country, then click again to add it to the new country.
– Josh Undefined
Mar 8 at 16:21
Nevermind! It was my only computed function in vue which was destroying the active prop AMcharts makes :)
– Josh Undefined
Mar 8 at 16:35
add a comment |
Hey thanks for this. It seems to be working, however i need to press countries twice for the active state to trigger. Any thoughts?
– Josh Undefined
Mar 8 at 11:59
You can just replace thehit
event withdoublehit
. I updated my answer according to that and included a code pen.
– Samuel Philipp
Mar 8 at 15:02
Ah I'm sorry Sam, perhaps I was not clear - I've edited my OP to include a gif of what is happening. But basically it seems like I've got to click once to toggle off the active state from one country, then click again to add it to the new country.
– Josh Undefined
Mar 8 at 16:21
Nevermind! It was my only computed function in vue which was destroying the active prop AMcharts makes :)
– Josh Undefined
Mar 8 at 16:35
Hey thanks for this. It seems to be working, however i need to press countries twice for the active state to trigger. Any thoughts?
– Josh Undefined
Mar 8 at 11:59
Hey thanks for this. It seems to be working, however i need to press countries twice for the active state to trigger. Any thoughts?
– Josh Undefined
Mar 8 at 11:59
You can just replace the
hit
event with doublehit
. I updated my answer according to that and included a code pen.– Samuel Philipp
Mar 8 at 15:02
You can just replace the
hit
event with doublehit
. I updated my answer according to that and included a code pen.– Samuel Philipp
Mar 8 at 15:02
Ah I'm sorry Sam, perhaps I was not clear - I've edited my OP to include a gif of what is happening. But basically it seems like I've got to click once to toggle off the active state from one country, then click again to add it to the new country.
– Josh Undefined
Mar 8 at 16:21
Ah I'm sorry Sam, perhaps I was not clear - I've edited my OP to include a gif of what is happening. But basically it seems like I've got to click once to toggle off the active state from one country, then click again to add it to the new country.
– Josh Undefined
Mar 8 at 16:21
Nevermind! It was my only computed function in vue which was destroying the active prop AMcharts makes :)
– Josh Undefined
Mar 8 at 16:35
Nevermind! It was my only computed function in vue which was destroying the active prop AMcharts makes :)
– Josh Undefined
Mar 8 at 16:35
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047122%2famcharts-4-map-stroke-uneven-when-applied-to-single-countries%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown