1

Is it possible to update the text inside the treemap plot using restyle function? I know it's possible via 'react' function, but this function will redraw the entire diagram (I don't want this to happen). This what I have so far: https://codepen.io/elv1s42/pen/yLydprX

var labels = ["P1", "P2", "P3", "P4"]; 
var parents = ["", "P1", "P1", "P2"];
var data = [{
      type: "treemap",
      labels: labels,
      parents: parents,
      marker: { colors: ['green', 'blue', 'red', 'yellow']},
      text: ['text1', 'text2', 'text3<br>text3', 'text4'],
      textinfo: "label text"
    }];
var layout = {};
Plotly.newPlot('myDiv', data, layout)
function changeText(){
    var upd = { 
      marker: {colors: ['white', 'orange', 'green', 'red']},
      //text: ['t1', 't2', 't3', 't4'] // how to update the text?
    };
    Plotly.restyle('myDiv', upd);
}
<head>
    <!-- Load plotly.js into the DOM -->
    <script src='https://cdn.plot.ly/plotly-latest.min.js'></script>
</head>

<body>
  <button onclick='changeText()'>Change my plot!</button>
    <div id='myDiv'><!-- Plotly chart will be drawn inside this DIV --></div>
</body>

1 Answer 1

2

I don't like answering my own questions, but the issue was resolved by https://github.com/etpinard from GitHub here: https://github.com/plotly/plotly.js/issues/4535

So the working solution is to use nested arrays for the text field:

function changeText(){
    var upd = { 
      marker: {colors: ['white', 'orange', 'green', 'red']},
      text: [['t1', 't2', 't3', 't4']] // how to update the text?
    };
    Plotly.restyle('myDiv', upd);
}

The CodePen example from the question is fixed now.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.