0

私は SWT チャートを使用しており、積み上げ棒グラフは下の図のようになります。棒グラフは、サービスの応答時間を表します。濃い青のバーは応答時間の技術的な部分を表し、薄い青のバーは思考時間を表します。

ここに画像の説明を入力

私の質問は、思考時間だけでなく、水色のバーに合計応答時間を表示できるかどうかです。たとえば、3 行目の合計応答時間は 10952 ミリ秒 (技術的応答時間 + 思考時間) になりますが、10000 ミリ秒の思考時間のみが表示されます。これをSWT棒グラフに実装する方法を知っている人はいますか? よろしくお願いします。

4

1 に答える 1

1

OK、すべてのバーのテキストを描画する SWT ペイント リスナーを追加することで、問題を解決できるようになりました。

plotArea.addListener(SWT.Paint, new Listener() {

        /**
         * The x-axis offset
         */
        private int xAxisOffset = 8;

        /**
         * The y-axis offset.
         */
        private int yAxisOffset = 3;

        @Override
        public void handleEvent(final Event event) {
            GC gc = event.gc;

            ISeries[] series = chart.getSeriesSet().getSeries();

            for (double xAxis : series[0].getXSeries()) {

                double techTime = series[0].getYSeries()[(int) xAxis];
                double thinkTime = series[1].getYSeries()[(int) xAxis];

                int totalTime = (int) Math.round(techTime + thinkTime);
                int xCoord = chart.getAxisSet().getXAxis(0).getPixelCoordinate(xAxis) - this.xAxisOffset;
                int yCoord = chart.getAxisSet().getYAxis(0).getPixelCoordinate(totalTime / this.yAxisOffset);

                gc.drawText(totalTime + " ms", yCoord, xCoord, SWT.DRAW_TRANSPARENT);
            }
        }
});

その後、SWT 棒グラフは次のようになります。 ここに画像の説明を入力

さらに、濃い青のバーと水色のバーの値を別々に表示するために、マウスをホバーするとツールチップ テキストにそれぞれの値を表示するリスナーを追加しました。

plotArea.addListener(SWT.MouseHover, new Listener() {

        @Override
        public void handleEvent(final Event event) {
            IAxis xAxis = chart.getAxisSet().getXAxis(0);
            IAxis yAxis = chart.getAxisSet().getYAxis(0);

            int x = (int) Math.round(xAxis.getDataCoordinate(event.y));
            double y = yAxis.getDataCoordinate(event.x);

            ISeries[] series = chart.getSeriesSet().getSeries();

            double currentY = 0.0;
            ISeries currentSeries = null;

            /* over all series */
            for (ISeries serie : series) {
                double[] yS = serie.getYSeries();

                if (x < yS.length && x >= 0) {
                    currentY += yS[x];
                    currentSeries = serie;

                    if (currentY > y) {
                        y = yS[x];
                        break;
                    }
                }
            }

            if (currentY >= y) {
                plotArea.setToolTipText(currentSeries.getDescription() + ": " + Math.round(y) + " ms");
            } else {
                plotArea.setToolTipText(null);
            }
        }
});
于 2015-11-21T14:19:33.887 に答える