Plotly.jsを使って棒グラフのカテゴリラベル(xticks)をクリックするとイベントを取得できますか?私は実際のバーでクリックイベントを得ることが可能ですが、私はバーの下のカテゴリラベルでクリックイベントを探しています。下の画像では、「キリン」のクリックイベントを探しています。 事前に助けてくれてありがとう。 Plotly.js - 棒グラフのカテゴリラベルのイベントをクリック
0
A
答えて
0
現在、カテゴリラベルにはクリックイベントはありません。このコメントには
0
https://github.com/plotly/plotly.js/issues/65#issuecomment-350672387
今のあなたの要求を満たすためにネイティブな方法がありませんので、私は、回避策を与えます。
これは角度のコードです(ただし、バニラJSに簡単に適合できます)。
import * as d3 from 'd3';
export class AngularCustomComponent {
// contructor and other methods here..
plotlyClickEvents() {
/**
* Distinguish between single and double click
* @see http://bl.ocks.org/ropeladder/83915942ac42f17c087a82001418f2ee
*/
function clickcancel() {
let dispatcher = d3.dispatch('click', 'dblclick');
function cc(selection) {
let down, tolerance = 5, last, wait = null, args;
// euclidean distance
function dist(a, b) {
return Math.sqrt(Math.pow(a[0] - b[0], 2) + Math.pow(a[1] - b[1], 2));
}
selection.on('mousedown', function() {
down = d3.mouse(document.body);
last = +new Date();
args = arguments;
});
selection.on('mouseup', function() {
if (dist(down, d3.mouse(document.body)) > tolerance) {
return;
}
else {
if (wait) {
window.clearTimeout(wait);
wait = null;
dispatcher.apply("dblclick", this, args);
}
else {
wait = window.setTimeout((function() {
return function() {
dispatcher.apply("click", this, args);
wait = null;
};
})(), 300);
}
}
});
};
// Copies a variable number of methods from source to target.
let d3rebind = function(target, source, method) {
let i = 1, n = arguments.length;
while (++i < n) target[method] = d3_rebind(target, source, source[method]);
return target;
};
// Method is assumed to be a standard D3 getter-setter:
// If passed with no arguments, gets the value.
// If passed with arguments, sets the value and returns the target.
function d3_rebind(target, source, method) {
return function() {
let value = method.apply(source, arguments);
return value === source ? target : value;
};
}
return d3rebind(cc, dispatcher, 'on');
}
return clickcancel();
}
onBarChartXAxisClick() {
let self = this;
let item = null;
d3.select("#your-parent-element-identifier").
select('.cartesianlayer')
.select('.xaxislayer-above')
.selectAll('.xtick > *').each(function(e) {
// @see https://hstefanski.wordpress.com/2015/10/25/responding-to-d3-events-in-typescript/
// but `d3.select(d3.event.currentTarget)` does not work in this case.
// To workaround see https://stackoverflow.com/a/40314241
item = d3.select(this);
// @NOTE: the element of the x-axis is a <text> and does not have the
// attribute "pointer-events". Without this attribute is not possibile
// to listen for mouse events, and for that we have to add it.
item.attr('pointer-events', 'all');
const cc = self.plotlyClickEvents();
item.call(cc);
cc.on('click', (d, index) => {
// Do something
});
});
}
}
関連する問題
- 1. plotly.js棒グラフを表示するにはbarをクリックするとonclickイベントが必要
- 2. g.raphael棒グラフ(クリック可能な棒グラフ)
- 3. Plotly.js - 横棒グラフをプロットして反転する
- 4. 棒グラフをクリックした後にng2-chart棒グラフのbarの値を取得
- 5. Chart.js棒グラフの棒グラフ
- 6. ggplot2棒グラフの棒グラフ
- 7. CorePlot棒グラフの棒グラフ
- 8. 円グラフのイベントをクリック - mpandroid
- 9. seabornグラフでカテゴリラベルを並べ替える
- 10. Plotly.js barchartに線グラフを追加すると棒が消えます
- 11. plotly.js棒グラフでツールチップを逆転しようとしています
- 12. 棒グラフと棒グラフとの関係
- 13. MSSQLベースの棒グラフと棒グラフ
- 14. d3.js棒グラフは、こちらをクリックしてくださいイベント
- 15. 横棒グラフD3の棒ラベル
- 16. 棒グラフと積み重ね棒グラフを1つのグラフmorris.js
- 17. Plotly.js円グラフの値の書式
- 18. plottable.jsで棒グラフを棒グラフで表示
- 19. Plotly.jsクリックでポイントを作成
- 20. dimple.jsの棒グラフ
- 21. Chart.jsの棒グラフ
- 22. パンダプロットの棒グラフ(
- 23. データフレームの棒グラフ
- 24. 棒グラフのラベル
- 25. コアプロット:棒グラフの各棒グラフの色を設定する
- 26. ChartJS 2.6 - 棒グラフの棒グラフの色をプログラムで変更する
- 27. ChartJS:棒グラフでクリックしたときのラベルの値を取得
- 28. 棒グラフ
- 29. 棒グラフと線グラフ
- 30. 棒グラフをカスタマイズする - 棒グラフをグラフの下の表と整列させる