我们可以更改所选点的样式吗?

时间:2019-04-16 11:31:25

标签: javascript plotly

在plotly.js生成的该箱图中,选择点之后,未选择的点的不透明度为0.2。

是否可以更改选定点和未选定点的样式?

var trace1 = {
  y: [0, 1, 2, 3, 4, 5, 6],
  type: 'box',
  selectedpoints : [1,2,5],
  boxpoints: 'all'
};

var data = [trace1];

var layout = {};

Plotly.newPlot('myDiv', data, layout);
<head>
<!-- Plotly.js -->
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<!-- Plotly chart will be drawn inside this DIV -->
<div id="myDiv"></div>
<script>
/* JAVASCRIPT CODE GOES HERE */
</script>
</body>

1 个答案:

答案 0 :(得分:1)

如果您查看reference,则可以看到存在“选定”和“未选定”标记的属性,这些属性使您可以更改其样式:

var trace1 = {
  y: [0, 1, 2, 3, 4, 5, 6],
  type: 'box',
  selectedpoints: [1, 2, 5],
  boxpoints: 'all',
  selected: {
    marker: {
      color: '#ff0000',
      opacity: 0.8
    }
  },
  unselected: {
    marker: {
      color: '#00ff00',
      opacity: 0.5
    }
  }
};

var data = [trace1];

var layout = {};

Plotly.newPlot('myDiv', data, layout);
<head>
  <!-- Plotly.js -->
  <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>

<body>
  <!-- Plotly chart will be drawn inside this DIV -->
  <div id="myDiv"></div>
  <script>
    /* JAVASCRIPT CODE GOES HERE */
  </script>
</body>