We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Tooltip crosshair fixed position

Thread ID:

Created:

Updated:

Platform:

Replies:

144840 May 24,2019 07:15 PM UTC May 27,2019 09:57 AM UTC JavaScript - EJ 2 1
loading
Tags: Chart
Marco Giorgi
Asked On May 24, 2019 07:15 PM UTC

Is there a way to give the tooltip of the crosshair/trackball a fixed position, like it is by default in the stock chart?

I have this:


But I'd like to have this (aligned on the top-left of the chart area):



Here is how I've set the crosshair in my chart:

chart = new ej.charts.Chart({
                       rows: [{ height: '30%' }, { height: '70%' }],
                       chartArea: { border: { width: 0 } },
                       //Initializing Primary X Axis
                       primaryXAxis: {
                           valueType: 'DateTime',
                           labelFormat: 'yyyy-MM-dd',
                           edgeLabelPlacement: 'Shift',
                           majorGridLines: { width: 0 },
                           crosshairTooltip: { enable: true },
                       },
                       .......
                      //Initializing Tooltip and Crosshair
                       tooltip: { enable: true, shared: true },
                       crosshair: { enable: true, lineType: 'Both', line: { width: 1, color: '#cccccc' }, dashArray: '5, 5' }


Baby Palanidurai [Syncfusion]
Replied On May 27, 2019 09:57 AM UTC

Hi Marco, 
 
Greetings from Syncfusion. 
 
We have analyzed your query. Yes, we have a way to show the tooltip in a fixed position like a stock chart. By using annotation and tooltipRender event, we can customize the text and position of the tooltip. We have prepared a sample based on your requirement. In that, Initially, we have added annotation content as empty. In tooltip render event we can get the args.text values for all series when hovering on the chart. Concatenate all text and set this string to the annotation content using the setAnnotationValue method of the annotation.  Also, we have hidden the default tooltip element. Now tooltip is working fine as expected. 
 
Code Snippet: 
annotations: [{ content: '<div id="annotation"></div>', coordinateUnits: 'Pixel', region: 'Chart', x: '15%', y: '25%' }], 
tooltipRender: function (args) { 
if(args.text.length > 0){ 
    if(count < 4){ 
       tooltipArray += args.text + '<br/>'; 
       count++; 
} 
 if(count === 4){ 
          count = 0; 
             chart.setAnnotationValue(0, '<div id="annotation" style="line-height: 18px;font-size:13px;background: #fff; opacity:0.9; color: #464e56; ' + 
                  ' box-shadow:0 0 8px 0 rgba(70,78,86,.25); padding: 7px 10px; border-radius: 3px">' + tooltipArray + '</div>'); 
            tooltipArray = []; 
                                                } 
                        } 
args.text = ''; 
                                     
        }, 
 
Screenshot: 
 
 
 
Hope this helps. 
 
Regards, 
Baby. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon