Forum Discussion
Custom Visual - Accepting the Data Modelling Date Format
- 6 years ago
Hi mattapq - fundamentally, you just need to install powerbi-visuals-utils-formattingutils to your project and using valueFormatter but it's also going to depend on you've chosen to implement your code. For instance, if you're using v3 of the visuals SDK vs. 1/2, or whether you're using D3 to do your chart, or something else.
D3 v3 (which is supported by the older SDKs) can handle the format strings as standard but some stuff changed in v4/5 and the v3 SKD recommends that version. The implementation of axis tick formatting is a little different for those, so I just want to make sure I provide you with more targeted advice, if possible. I can definitely help with D3 but if it's something else I might need to do a bit of digging.
If you're able to share anything code-wise, I can take a look for you and provide something that will hopefully get you on the path to your desired solution.
Cheers,
Daniel
That library was the missing piece of the puzzle. Thanks, dm-p !
For anyone that stumbles into this post with this problem or a similar one, I'm using d3 5.7.2 and version 2.5.0 of the Power BI API. I just had to do the following:
1. Install the powerbi-visuals-utils-formattingutils library
2. Create a formatter and set its "format" property to the format we pulled from the categories source, i.e.
myFormatter = valueFormatter.create({format: dataViews[0].categorical.categories[0].source.format});
3. Format your value:
formattedDate = formatter.format(myDate);
4. Use this new formatted date as the x-axis label value instead of the date itself.