Page 1 of 1

Tooltip on legend populated during run time

Posted: Fri Mar 13, 2015 1:06 pm
by 17469962
Hi,

I have a legend that is populated dynamically during run time. Due to length restrictions I am truncating the legend length to 30 chars and then to have a tooltip which when mouse pointer is brought upon will give out the entire text of the legend.
this is my initChart method

Code: Select all

private void initTChart(String title, cop_TimePeriod timePeriod) {
        d_tChart = new TChart();
        d_tChart.setText(title);
//        ThemesList.applyTheme(d_tChart.getChart(), 1);
        d_tChart.getPanel().getGradient().setVisible(true);
        d_tChart.getWalls().setVisible(true);
        d_tChart.getAspect().setView3D(false);

        d_tChart.getAxes().getBottom().getLabels().setDateTimeFormat("HH:mm");
        d_tChart.getLegend().setCheckBoxes(true);

        d_tChart.getAxes().getLeft().getTitle().setCaption("Cost");
        d_tChart.getAxes().getBottom().getTitle().setCaption("Time");

        d_tChart.getAxes().getBottom().setMinMax(timePeriod.getStart().getTime(), timePeriod.getEnd().getTime());
        d_tChart.getAxes().getBottom().scroll(3, false);

        d_tChart.getAspect().setView3D(false);
        d_tChart.getAspect().setSmoothingMode(true);
        d_tChart.getHeader().setVisible(true);
        d_tChart.getHeader().getFont().setColor(com.steema.teechart.drawing.Color.NAVY);
//        d_tChart.setText("FastLine: null points support");

        d_tChart.getPanel().getGradient().setEndColor(com.steema.teechart.drawing.Color.fromArgb(254,21,60,89));
        //chart1.getPanel().getGradient().setMiddleColor(Color.fromArgb(254,255,255,255));
        d_tChart.getPanel().getGradient().setStartColor(com.steema.teechart.drawing.Color.fromArgb(254,255,255,255));
        d_tChart.getPanel().getGradient().setUseMiddle(false);
        d_tChart.getPanel().getGradient().setVisible(true);

        d_tChart.getWalls().getBack().setTransparent(false);
        d_tChart.getWalls().getBack().getGradient().setVisible(true);
        d_tChart.getWalls().getBack().getGradient().setUseMiddle(false);
        d_tChart.getWalls().getBack().getGradient().setStartColor(com.steema.teechart.drawing.Color.fromArgb(234, 234, 234));
        d_tChart.getWalls().getBack().getGradient().setEndColor(com.steema.teechart.drawing.Color.WHITE);
        editButton = new JButton("Edit...");
    }
in my dataload method i am doing the following

Code: Select all

 markstip1 = new com.steema.teechart.tools.MarksTip(d_tChart.getChart());

        d_tChart.addChartPaintListener(new ChartPaintListener() {

            public void axesPainting(ChartDrawEvent arg0) {}

            public void chartPainted(ChartDrawEvent arg0) {
                markstip1.chart.getToolTip().setText(text);
            }

            public void chartPainting(ChartDrawEvent arg0) {}
            public void seriesPainting(ChartDrawEvent arg0) {}
            public void seriesPainted(ChartDrawEvent arg0) {}
        });

        d_tChart.addMouseMotionListener(new MouseMotionListener() {

            public void mouseDragged(MouseEvent e) {}

            public void mouseMoved(MouseEvent e) {
                int clickedIndex = d_tChart.getLegend().clicked(e.getX(),e.getY());
                if (clickedIndex > -1)
                {
                    text = d_tChart.getSeries(clickedIndex).titleOrName();
                    d_tChart.repaint();
                }
            }
        });

        d_tChart.getLegend().setAlignment(LegendAlignment.BOTTOM);
        d_tChart.repaint();
i am not sure what is wrong but the tooltip is not popping when i move the mouse pointer on the legend

Re: Tooltip on legend populated during run time

Posted: Tue Mar 17, 2015 11:43 am
by yeray
Hello,

Excuse us for the delayed reply here.
Have you tried using an Annotation Tool instead of a MarksTip Tool?

Re: Tooltip on legend populated during run time

Posted: Wed Mar 18, 2015 11:49 am
by 17469962
Thanks for reaching out, I am not sure if using Annotation would serve the purpose, I tried looking out examples but could not find any. Can you provide some example as to how annotation works to populate the legend text dynamically.

Re: Tooltip on legend populated during run time

Posted: Wed Mar 18, 2015 2:15 pm
by yeray
Hello,
roop wrote:Can you provide some example as to how annotation works to populate the legend text dynamically.
Not to populate the Legend but to show the complete string. Ie:

Code: Select all

        tChart1.getAspect().setView3D(false);
        
        final ArrayList<String> titles = new ArrayList<>();
        for (int i=0; i<3; i++) {
            Line line = new Line(tChart1.getChart());
            line.fillSampleValues();
            
            titles.add("This is a long title for the series " + i);
            line.setTitle(titles.get(i).substring(0, 20) + "...");
        }
        
        final Annotation annot1 = new Annotation(tChart1.getChart());
        annot1.setActive(false);
        
        tChart1.addMouseMotionListener(new MouseMotionAdapter() {

            @Override
            public void mouseMoved(MouseEvent e) {
                int seriesIndex = tChart1.getLegend().clicked(e.getX(), e.getY());
                if (seriesIndex > -1) {
                    annot1.setText(titles.get(seriesIndex));
                    annot1.getShape().setCustomPosition(true);
                    int tmpX = e.getX();
                    int tmpWidth = annot1.getWidth();
                    if (tmpX+tmpWidth > tChart1.getWidth()) {
                        tmpX = tChart1.getWidth()-tmpWidth-2;
                    }
                    annot1.setLeft(tmpX);
                    annot1.setTop(e.getY());
                    annot1.setActive(true);
                }
                else
                    annot1.setActive(false);
            }
        });

Re: Tooltip on legend populated during run time

Posted: Wed Mar 18, 2015 4:12 pm
by 17469962
That worked...thank you