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. Image for the cookie policy date

Tooltip crosshair fixed position

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' }


1 Reply

BP Baby Palanidurai Syncfusion Team 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. 


Loader.
Live Chat Icon For mobile
Up arrow icon