Forum Discussion
Embedded a pie chart in a matrix
- 1 year ago
Hello,
I had to do something similar for a customer,
I used SVG approach, this is the code I used if it could help you 🙂
Values_Donut =
// ----------- PARAMETERS -----------
// Define chart properties
VAR _Radius = 50
VAR _DonutWidth = 10// Calculate measures for each category
VAR Total = COUNT(Revis[RevisionDescription (groups)])
VAR _MeasureOne = CALCULATE(COUNT(Revis[RevisionDescription (groups)]), Revis[RevisionDescription (groups)] = "First mention")
VAR _MeasureTwo = CALCULATE(COUNT(Revis[RevisionDescription (groups)]), Revis[RevisionDescription (groups)] = "Broadly unchanged wording & ...")
VAR _MeasureThree = CALCULATE(COUNT(Revis[RevisionDescription (groups)]), Revis[RevisionDescription (groups)] = "Significant redrafting")// Define colors
VAR _FirstColour = "#8a7200"
VAR _SecondColour = "#ab1d65"
VAR _ThirdColour = "#54761f"// ----------- CALCULATE ANGLES -----------
VAR _Total = _MeasureOne + _MeasureTwo + _MeasureThreeVAR _AngleOne = IF(NOT ISBLANK(_Total), DIVIDE(_MeasureOne, _Total, 0) * 100, 0)
VAR _AngleTwo = IF(NOT ISBLANK(_Total), DIVIDE(_MeasureTwo, _Total, 0) * 100, 0)
VAR _AngleThree = IF(NOT ISBLANK(_Total), DIVIDE(_MeasureThree, _Total, 0) * 100, 0)// Calculate stroke offsets
VAR _OffsetTwo = 100 - _AngleOne + 25
VAR _OffsetThree = 100 - (_AngleOne + _AngleTwo) + 25I put the return in a second answer 🙂
- 1 year ago
RETURN
IF(
ISINSCOPE(Revis[Condition Date Format]),
"data:image/svg+xml;utf8," &
"<svg width=""100%"" height=""100%"" xmlns=""http://www.w3.org/2000/svg"" viewBox=""0 0 " & _Radius & " " & _Radius & """ class=""donut"">" &
"<circle class=""segment"" cx=""" & _Radius / 2 & """ cy=""" & _Radius / 2 & """ r=""15.91549430918954"" fill=""transparent"" stroke=""" & _FirstColour & """ stroke-width=""" & _DonutWidth & """ stroke-dasharray=""" & _AngleOne & " " & 100 - _AngleOne & """ stroke-dashoffset=""25""></circle>" &
"<circle class=""segment"" cx=""" & _Radius / 2 & """ cy=""" & _Radius / 2 & """ r=""15.91549430918954"" fill=""transparent"" stroke=""" & _SecondColour & """ stroke-width=""" & _DonutWidth & """ stroke-dasharray=""" & _AngleTwo & " " & 100 - _AngleTwo & """ stroke-dashoffset=""" & _OffsetTwo & """></circle>" &
"<circle class=""segment"" cx=""" & _Radius / 2 & """ cy=""" & _Radius / 2 & """ r=""15.91549430918954"" fill=""transparent"" stroke=""" & _ThirdColour & """ stroke-width=""" & _DonutWidth & """ stroke-dasharray=""" & _AngleThree & " " & 100 - _AngleThree & """ stroke-dashoffset=""" & _OffsetThree & """></circle>" &
"</svg>",
"data:image/svg+xml;utf8, <svg height=""200"" width=""200"" xmlns=""http://www.w3.org/2000/svg"">
<text x=""50"" y=""100"" fill=""black"" font-family=""Calibri"" font-size=""48"">" & Total & "</text>
</svg>"
)
Hello,
I had to do something similar for a customer,
I used SVG approach, this is the code I used if it could help you 🙂
Values_Donut =
// ----------- PARAMETERS -----------
// Define chart properties
VAR _Radius = 50
VAR _DonutWidth = 10
// Calculate measures for each category
VAR Total = COUNT(Revis[RevisionDescription (groups)])
VAR _MeasureOne = CALCULATE(COUNT(Revis[RevisionDescription (groups)]), Revis[RevisionDescription (groups)] = "First mention")
VAR _MeasureTwo = CALCULATE(COUNT(Revis[RevisionDescription (groups)]), Revis[RevisionDescription (groups)] = "Broadly unchanged wording & ...")
VAR _MeasureThree = CALCULATE(COUNT(Revis[RevisionDescription (groups)]), Revis[RevisionDescription (groups)] = "Significant redrafting")
// Define colors
VAR _FirstColour = "#8a7200"
VAR _SecondColour = "#ab1d65"
VAR _ThirdColour = "#54761f"
// ----------- CALCULATE ANGLES -----------
VAR _Total = _MeasureOne + _MeasureTwo + _MeasureThree
VAR _AngleOne = IF(NOT ISBLANK(_Total), DIVIDE(_MeasureOne, _Total, 0) * 100, 0)
VAR _AngleTwo = IF(NOT ISBLANK(_Total), DIVIDE(_MeasureTwo, _Total, 0) * 100, 0)
VAR _AngleThree = IF(NOT ISBLANK(_Total), DIVIDE(_MeasureThree, _Total, 0) * 100, 0)
// Calculate stroke offsets
VAR _OffsetTwo = 100 - _AngleOne + 25
VAR _OffsetThree = 100 - (_AngleOne + _AngleTwo) + 25
I put the return in a second answer 🙂
RETURN
IF(
ISINSCOPE(Revis[Condition Date Format]),
"data:image/svg+xml;utf8," &
"<svg width=""100%"" height=""100%"" xmlns=""http://www.w3.org/2000/svg"" viewBox=""0 0 " & _Radius & " " & _Radius & """ class=""donut"">" &
"<circle class=""segment"" cx=""" & _Radius / 2 & """ cy=""" & _Radius / 2 & """ r=""15.91549430918954"" fill=""transparent"" stroke=""" & _FirstColour & """ stroke-width=""" & _DonutWidth & """ stroke-dasharray=""" & _AngleOne & " " & 100 - _AngleOne & """ stroke-dashoffset=""25""></circle>" &
"<circle class=""segment"" cx=""" & _Radius / 2 & """ cy=""" & _Radius / 2 & """ r=""15.91549430918954"" fill=""transparent"" stroke=""" & _SecondColour & """ stroke-width=""" & _DonutWidth & """ stroke-dasharray=""" & _AngleTwo & " " & 100 - _AngleTwo & """ stroke-dashoffset=""" & _OffsetTwo & """></circle>" &
"<circle class=""segment"" cx=""" & _Radius / 2 & """ cy=""" & _Radius / 2 & """ r=""15.91549430918954"" fill=""transparent"" stroke=""" & _ThirdColour & """ stroke-width=""" & _DonutWidth & """ stroke-dasharray=""" & _AngleThree & " " & 100 - _AngleThree & """ stroke-dashoffset=""" & _OffsetThree & """></circle>" &
"</svg>",
"data:image/svg+xml;utf8, <svg height=""200"" width=""200"" xmlns=""http://www.w3.org/2000/svg"">
<text x=""50"" y=""100"" fill=""black"" font-family=""Calibri"" font-size=""48"">" & Total & "</text>
</svg>"
)