Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
AakashMarasini
Frequent Visitor

Max Min Limit setup in custom visual

Hi Developers!

I am building a custom visual and added the Max Area height for x axis. Now i want to set the min and max value to it. I have tried putting those values in capabilities.json file and in setting.js file but didnot work.

In setting.js file, My code for maxAreaHeight. it shows error while adding max and min to it.

public maxAreaHeightX = new formattingSettings.Slider({
  name: "maxAreaHeightX",
  displayName: "Max Area Height",
  value: 20 
});

 

And the object for this in capabilities.json looks like as below:

"maxAreaHeightX": {
      "displayName": "Max Area Height",
      "type": {
        "integer": true 
      
      }
      
    }

 

 

AakashMarasini_0-1695969881973.png

 


I have set the max and min value of 30 and 10 respectively. But in the formatting slider the value is showing 0 to 100.Also In the slider, i want the value starting from 10 to 30.

let maxAreaHeightPercentageX = this.visualSettings.xAxis.maxAreaHeightX.value ;
maxAreaHeightPercentageX = Math.min(30, Math.max(10, maxAreaHeightPercentageX));

 

1 ACCEPTED SOLUTION
ewaghabi
Frequent Visitor

I don't know if you already got it, but I managed to do it with something like this (in your settings.ts file):

import powerbi from "powerbi-visuals-api";

...
class MyMaxValidator implements powerbi.visuals.MaxValidator<number> {
   type: powerbi.visuals.ValidatorType.Max;
   value: number;

   constructor(max: number) {
       this.value = max;
   }
}
class MyMinValidator implements powerbi.visuals.MinValidator<number> {
   type: powerbi.visuals.ValidatorType.Min;
   value: number;

   constructor(min: number) {
       this.value = min;
   }
}

...

public maxAreaHeightX = new formattingSettings.Slider({
  name: "maxAreaHeightX",
  displayName: "Max Area Height",
  value: 20,
  options: { maxValue: new MyMaxValidator(30), minValue: new MyMinValidator(10) }    
});

 

View solution in original post

3 REPLIES 3
enfarer
New Member

Easier way to do this is :

public maxAreaHeightX = new formattingSettings.Slider({
  name: "maxAreaHeightX",
  displayName: "Max Area Height",
  value: 20,
  options: {
     maxValue: {
        type: powerbi.visuals.ValidatorType.Max,
        value: 30
     },
     minValue: {
        type: powerbi.visuals.ValidatorType.Min,
        value: 10
     }
   }
});
AakashMarasini
Frequent Visitor

 @ewaghabi Thanks a lot! The issue was stayed unsolved. Now, it works with the above code.

Thanks Again!

ewaghabi
Frequent Visitor

I don't know if you already got it, but I managed to do it with something like this (in your settings.ts file):

import powerbi from "powerbi-visuals-api";

...
class MyMaxValidator implements powerbi.visuals.MaxValidator<number> {
   type: powerbi.visuals.ValidatorType.Max;
   value: number;

   constructor(max: number) {
       this.value = max;
   }
}
class MyMinValidator implements powerbi.visuals.MinValidator<number> {
   type: powerbi.visuals.ValidatorType.Min;
   value: number;

   constructor(min: number) {
       this.value = min;
   }
}

...

public maxAreaHeightX = new formattingSettings.Slider({
  name: "maxAreaHeightX",
  displayName: "Max Area Height",
  value: 20,
  options: { maxValue: new MyMaxValidator(30), minValue: new MyMinValidator(10) }    
});

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.

Top Solution Authors