Tooltip on legend populated during run time

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
roop
Newbie
Newbie
Posts: 7
Joined: Wed Aug 06, 2014 12:00 am

Tooltip on legend populated during run time

Post by roop » Fri Mar 13, 2015 1:06 pm

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

Yeray
Site Admin
Site Admin
Posts: 9509
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Tooltip on legend populated during run time

Post by Yeray » Tue Mar 17, 2015 11:43 am

Hello,

Excuse us for the delayed reply here.
Have you tried using an Annotation Tool instead of a MarksTip Tool?
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

roop
Newbie
Newbie
Posts: 7
Joined: Wed Aug 06, 2014 12:00 am

Re: Tooltip on legend populated during run time

Post by roop » Wed Mar 18, 2015 11:49 am

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.

Yeray
Site Admin
Site Admin
Posts: 9509
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Tooltip on legend populated during run time

Post by Yeray » Wed Mar 18, 2015 2:15 pm

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);
            }
        });
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

roop
Newbie
Newbie
Posts: 7
Joined: Wed Aug 06, 2014 12:00 am

Re: Tooltip on legend populated during run time

Post by roop » Wed Mar 18, 2015 4:12 pm

That worked...thank you

Post Reply