Skip to content

Compound.Line

Generates a Line compound SVG Visual

DaxLib.SVG.Compound.Line( x, y, width, height, paddingX, paddingY, axisRef, measureRef, lineColor )
Parameter Type Required Description
x INT64 The x position of the compound
y INT64 The y position of the compound
width INT64 The width of the compound
height INT64 The height of the compound
paddingX DOUBLE The horizontal padding percentage (0.0-1.0, e.g., 0.1 = 10% padding)
paddingY DOUBLE The vertical padding percentage (0.0-1.0, e.g., 0.1 = 10% padding)
axisRef ANYREF EXPR The column that the measure will be evaluated against
measureRef NUMERIC EXPR The measure to evaluate
lineColor STRING The Hex color of the line (e.g., "#01B8AA")

STRING An SVG line chart element that visualizes the measure across the specified axis.

DaxLib.SVG.SVG(
    500,
    100,
    BLANK(),
    DaxLib.SVG.Compound.Line(
        0,                  // x
        0,                  // y
        500,                // width
        100,                // height
        0.05,               // paddingX
        0.04,               // paddingY
        Dates[Date],        // xAxis
        [Total Cost],       // measureVal
        DaxLib.SVG.Colour.Theme(
            "Power BI",
            25
        )                   // lineColour
    ),
    BLANK()
)
function 'DaxLib.SVG.Compound.Line' =
    (
        x: INT64,
        y: INT64,
        width: INT64,
        height: INT64,
        paddingX: DOUBLE,
        paddingY: DOUBLE,
        axisRef: ANYREF EXPR,
        measureRef: NUMERIC EXPR,
        lineColor: STRING
    ) =>

        // Apply padding to dimensions
        VAR _X =            x + ( width * ( COALESCE( paddingX, 0 ) / 2) )
        VAR _Y =            y + ( height * ( COALESCE( paddingY, 0 ) / 2) )
        VAR _Width =        width * ( 1 - COALESCE( paddingX, 0 ) )
        VAR _Height =       height * ( 1 - COALESCE( paddingY, 0 ) )

        // Check if Axis is numeric
        VAR axisSample =    MAX( axisRef )
        VAR axisIsNumeric = ISNUMERIC( axisSample ) || ISDATETIME( axisSample )

        // For totals
        // Materialize axis + value once (avoid repeated measure evaluation)
        VAR _Values =
            ADDCOLUMNS(
                VALUES( axisRef ),
                "@Value", measureRef
            )

        VAR _DataNonBlank =
            FILTER( _Values, NOT ISBLANK( [@Value] ) )

        VAR _Data =
            ADDCOLUMNS(
                _DataNonBlank,
                "@AxisIndex",
                    IF(
                        axisIsNumeric,
                        axisRef,
                        RANK( DENSE, CALCULATETABLE( VALUES( axisRef ), ALLSELECTED() ) )
                    )
            )

        // Define axis scales       
        VAR _XMin =     MINX( _Data, [@AxisIndex] )
        VAR _XMax =     MAXX( _Data, [@AxisIndex] )
        VAR _RawYMin =  MINX( _Data, [@Value] )
        VAR _YMin =     IF( _RawYMin > 0, 0, _RawYMin )
        VAR _YMax =     MAXX( _Data, [@Value] )
        VAR _XWidth =   _X + _Width
        VAR _YHeight =  _Y + _Height

        //Points
        VAR _Points = 
            CONCATENATEX(
                _Data,
                IF( 
                    NOT ISBLANK( [@Value] ), 
                    COMBINEVALUES( 
                        ",", 
                        DaxLib.SVG.Scale.Normalize( [@AxisIndex], _XMin, _XMax, _X, _XWidth ), 
                        DaxLib.SVG.Scale.Normalize( [@Value], _YMin, _YMax, _YHeight, _Y )
                    )
                ),
                " ",
                [@AxisIndex],
                ASC
            )

        // Line Element
        VAR _LineElement =
            DaxLib.SVG.Element.Polyline(
                _Points,        // points
                DaxLib.SVG.Attr.Shapes(
                    "none",     // fill
                    BLANK(),    // fillOpacity
                    BLANK(),    // fillRule
                    IF( NOT ISBLANK( lineColor ), lineColor, "#01B8AA" ), // stroke
                    1,          // stroke
                    BLANK(),    // strokeOpacity
                    BLANK()     // opacity
                ),
                BLANK()         // transforms
            )

        // Single Point Element
        VAR _SinglePointElement =
            DaxLib.SVG.Element.Circle(
                DaxLib.SVG.Scale.Normalize( MAXX( _Data, [@AxisIndex] ), _XMin, _XMax, _X, _XWidth ), // cx
                DaxLib.SVG.Scale.Normalize( MAXX( _Data, [@Value] ), _YMin, _YMax, _YHeight, _Y ), // cy
                2,              // r
                DaxLib.SVG.Attr.Shapes(
                    lineColor,  // fill
                    BLANK(),    // fillOpacity
                    BLANK(),    // fillRule
                    BLANK(),    // stroke
                    BLANK(),    // strokeWidth
                    BLANK(),    // strokeOpacity
                    BLANK()     // opacity
                ),
                BLANK()         // transforms
            )

        // Combined elements
        VAR _CombinedElement = 
            IF(
                COUNTROWS( _Data ) = 1,
                _SinglePointElement,
                _LineElement
            )

        RETURN

            IF( NOT ISEMPTY( _Data ), _CombinedElement )

Comments