Plotly indicator: Show both, relative and absolute difference

Viewed 199

Is it possible to show both, the relative and absolute difference in the delta tag of a Plotly indicator?

My current workaround is like this:

Workaround

type: "indicator",
mode: "number+delta",
value: 450,
title: {
      text: "Reference: 500 (-10%)"
},
delta: { reference: 500, position: "right" }

However, it would be nice, to have both information in the colored delta tag.

Edit:

I went into plotly-finance.js and replaced the line (inside the drawDelta()-function)

return (value > 0 ? trace.delta.increasing.symbol : trace.delta.decreasing.symbol) + numberFmt(value);

with

return (value > 0 ? trace.delta.increasing.symbol : trace.delta.decreasing.symbol) + deltaFmtRel(cd[0].relativeDelta) + " (" + deltaFmtAbs(cd[0].delta)+ ")";

and added functions

var deltaFmtAbs = function(v) { 
            var tmpAx = deltaAx;
            tmpAx.tickformat = '';
            return Axes.tickText(tmpAx, v).text;
        };

var deltaFmtRel = function(v) { 
            var tmpAx = deltaAx;
            tmpAx.tickformat = '2%';
            return Axes.tickText(tmpAx, v).text;
        };

The result looks like this: Workaround 2

Of course, you can't have any indicators without the delta-tags, if you do it that way.

0 Answers
Related