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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Sdg8481
Helper I
Helper I

SVG Bar Chart within a table

Hi, from searching on the internet i found this brilliant code for adding a barchart into a standard table.

 

However, i can see that ChartScale is hardcoded (at 10,000), however all of my values in the table vastly differ and are independent of each other, therefore a fixed scale doesn't work.

 

How can i adapt the code below so that the Chart Scale is relative to the Maximum value for each row ('Area|Attribute') in the table. Apologies in advance, i'm a complete DAX novice.

 

Dynamic Chart = 
var BaseURL = "https://chart.googleapis.com/chart?"
var ChartType = "cht=bvs"
var ChartScale = "&chds=0,10000"
var ChartSize = "&chs=150x150"
var SeriesColour = "&chco=000000"
var ChartData = "&chd=t:" & CONCATENATEX('D - Current Year Data By Week (for Trend)','D - Current Year Data By Week (for Trend)'[zValue (week) as Measure], ",", 'D - Current Year Data By Week (for Trend)'[Reporting Thursday])
return IF(HASONEVALUE('D - Current Year Data By Week (for Trend)'[Key1: Area|Attribute]), BaseURL & ChartType & ChartScale & ChartSize & SeriesColour & ChartData)
 

Thanks

Stu

1 ACCEPTED SOLUTION

That probably means that internally the SVG defaults the chart scale to 100 if no value is given.

 

In that case you need to provide a dynamic chart scale based on your largest number.

 

Say, your numbers a and b are 4300 and 3500.  Then your chart scale should be a "1"  followed by 

 

(int(LOG10(max(number a,number b))+1) "0"  strings.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

what happens if you use 

 

var chartScale = ""

 

instead?

Hi, thank you that definately helps, especially for when the numbers are relatively small. However, when BOTH numbers start to get large there appears no difference in the bar size.

 

As you can see in the example below, it all seems to work, but when both numbers are above 100, but still have a big difference between them the bar sizes show equal ... when clearly there is a difference.

 

Link to image

 

Yours hopefully

Stuart

That probably means that internally the SVG defaults the chart scale to 100 if no value is given.

 

In that case you need to provide a dynamic chart scale based on your largest number.

 

Say, your numbers a and b are 4300 and 3500.  Then your chart scale should be a "1"  followed by 

 

(int(LOG10(max(number a,number b))+1) "0"  strings.

Thank you that really helped. Your idea of getting the maximum did the trick. Thank you

Helpful resources

Announcements
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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.