Change default locale date d3 v4 - d3.js

I want to change the language to spanish in d3 dates.
to do this in D3 v3 you can use
var format = {
"decimal": ".",
"thousands": "",
"days": ["Domingo", "Lunes", .....]}
var localeFormatter = d3.locale(format)
but now in D3 v4 d3.locale is gone. and
d3.timeFormatDefaultLocale(format)
seems to do nothing i dont know if is a bug or what.
I dont want to format the time like this link D3 time-format.
i want the language to change.
i have tried
d3.local(format)
d3.timeFormatDefaultLocale(format)
d3.timeFormatLocale(format)
¿Can some one help me on this?...

In D3 v4, you should use
d3.formatDefaultLocale(format)

Looks like you need to do:
d3.timeFormatDefaultLocale(format);
Before you declare your scales, else D3 will take English as default.

Related

D3 How to pass text value from data to variable

I got a great answer yesterday helping me set up a conditional rule that allows me to display the points on my scatter chart as images or dots based on a variable 'displaytype'
Here's the link to the answer: D3 conditionally append image OR circle element based on variable
I'm porting my solution into Power BI and the dataset will contain a field 'display_type' which will be either 'image' or 'dot'
So I'm trying to update my variable and link it to the data but the if statement doesn't seem to recognise the output from the function.
eg
The Current variable is:
var displaytype = "image" // or "dot"
I'm trying to change that to:
var displaytype = function(d) {
return d.display_type
};
or
var displaytype = function(d) {
return data[0].display_type
};
However, the result has no impact to the display whatsoever so I guess I'm missing something (probably simple) ?
Any help much appreciated as always

Adapt old geo to D3 v5, how to express a queue of Promise?

I am adapting an old version D3 map visualization to modern D3v5: first step, to D3v4, is running with this source, but to the final step I need to convert Promises, from old queue,
d3.queue().defer(d3.json,"file.json").(ready);
to the modern v5 style... How to express in v5 style? Seems that is something as
var brMap = d3.json("file.json");
Promise.all([brMap]).then(ready)
but is not working.
PS: where the v5 simple examples?
Thanks #GerardoFurtado and #altocumulus, the answer was on his comments, here merging all.
There are some globals (perhaps not a best practice)
var g;
In "after page load" context run
svg = d3.select("etc..")
g = svg.append("g")
// ...
d3.json("file.json").then(ready);
where the function ready() is something as
function ready(shp) {
var data1 = topojson.feature(shp, shp.item1);
//... draw map appenging features to global g
}
See the final result of the solution here.

d3 + adding text labels + formatting

this is my fiddle, which I am building with from this example
what is the best way to convert the text lables from 0.08 to 8% format.
This is my attempt, but is there a better/other way?
.text(function(d) { return Math.floor(d.frequency*100)+"%"; });
The most common way to do it (let's call it the "d3 way") is to use the d3 formatting functions:
var format = d3.format("%");
Here is the Fiddle: https://jsfiddle.net/cr91xf1t/
You can play with several built in formats, or even create your own. Have a look here: http://bl.ocks.org/zanarmstrong/05c1e95bf7aa16c4768e

cant draw belgium on dc.js choropleth map

I'm having trouble drawing belgium with a dc.js choropleth map.
I've read it can be a projection problem in another stackoverflow response (map json works on Geojson.io but it doesnt work on dc.js choropleth map), but I can't find the right parameters to write.
I would really appreciate any help with this issue.
Big thanks in advance !
Here is the geojson data I used:
https://github.com/Datafable/rolling-blackout-belgium/blob/master/data/geospatial/municipalities-belgium.geojson
And here is my code:
d3.json("data/municipalities-belgium.geojson", function (geojson) {
mapChart
.dimension(provinceDimension)
.group(provinceGroup)
.width(400)
.height(400)
.transitionDuration(1000)
.projection(d3.geo.mercator()
// .parallels([49, 52])
// .origin([0,40])
// .translate([200,900])
// .scale(150000000)
)
.overlayGeoJson(geojson.features, 'somename', function(d) {
return d.properties.shn;
})
;
dc.renderAll();
});
(The result is a blue square 400x400 that seems to select shn=BE391141)
Even if you put a scale, you don't get anything drawn?
As for the overlay, the name of the dimension has to be the name of the province you want to set the color of. How is provinceDimension defined? does it use shn as the key?
As an aside, your geojson contains lots of stuff you don't need (eg uk), having it only for the belgium provinces would make it much smaller.
There is something wrong in the dataset.

Kendo scatter chart not showing proper date format

I am using a kendo scatter chart with pan and zoom option and locale setting. I have set locale as bg-BG and when I zoom in or zoom out the date/ time format not working correctly.
For example for bg-BG Month'year format is coming properly which is proper.
When I zoom in the format changes to month/day format which is not correct as per locale.
Zoom in again the format changes to HH:mm which is again wrong according to lcale format,
Here is the fiddle with the issue
I set locale in this way
kendo.culture('bg-BG');
If the kendo chart does not fit tomlocale then it should not work for first time itself.
Any help is appreaciated. Thanks in advance
If kendo shows you wrong date formats you can chceck date patterns for your language like this:
kendo.culture('bg-BG');
console.log(kendo.culture());
And then if you wanna explicitly set date patterns in your chart do it like so:
...
categoryAxis: {
labels: {
dateFormats: {
minutes: culture.calendar.patterns.T,
hours: culture.calendar.patterns.g,
days: culture.calendar.patterns.d,
weeks: culture.calendar.patterns.d,
months: "MM" + culture.calendar['/'] + "yyyy",
years: "yyyy"
},
},
....

Resources