Can React-Native-HighCharts be used to load tooltips with external data?

Good Morning,

I have a question regarding reading an external variable that contains a list in the settings of a HighCharts chart for React-Native. Specifically, I am using the "react-native-highcharts" component.

In my code snippet below, I am trying to access data from an API and display it on a line chart. However, I am encountering an issue with the 'exData' variable being undefined when attempting to load its values into the tooltip of the chart.

Is there a way to achieve this functionality? Essentially, I want to display tooltips on the chart with values from a separate list ('list2') corresponding to each point on the graph instead of the actual data points from 'line1'.

For example, if the user clicks on position 4 where the value of the line is 6, I would like the tooltip to show the corresponding text 'Teste 4' from 'list2'.

Currently, the setting suggests that 'list2' is empty. How should I proceed to implement tooltips in this manner?

Please find the modified JavaScript snippet below:

javascript
const tooltips = ['Teste 1','Teste 2','Teste 3','Teste 4','Teste 5','Teste 6','Teste 7','Teste 8','Teste 9','Teste 10','Teste 11','Teste 12'];

var conf = {
    chart: {
        type: 'spline',
    },
    title: {
        text: 'Live random data'
    },
    tooltip: {
        formatter: function () {
            return this.y > 0 ? this.series.name : tooltips[0];
        }
    },
    navigation: {
        buttonOptions: {
            enabled: false
        }
    },
    colors: ['#DA6AFF'],
    xAxis: {
        categories: ['J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D'] 
    },
    credits: {
        enabled: false
    },
    series: [{
        name: 'Random data',
        data: this.state.dataAcionamentos, 
        marker: {
            enabled: false,
        },
    }]
};

const options = {
    global: {
        useUTC: false
    },
    lang: {
        decimalPoint: ',',
        thousandsSep: '.'
    }
};

Answer №1

Success!

Here is my unique solution for contribution.

To begin with, I establish two arrays for the two Series:


for (i in myObj) {

   var Label1 = 'Test 1';
   valueP = myObj[i].value;

   dataList1.push({
       name: Label1,
       y: ValueP
   });

   valueAux1 = myObj[i].value;
   valueAux2 = myObj[i].unit;

   dataList2.push({
       name: valueAux2,
       y: valueAux1
   });
}

The outcomes:


dataList1 = 
[
   { name: 'Test 1', y: 61.41 },
   { name: 'Test 1', y: 51.35 },
   { name: 'Test 1', y: 41.00 },
   { name: 'Test 1', y: 31.29 },
   { name: 'Test 1', y: 21.23 },
   { name: 'Test 1', y: 11.16 },
   { name: 'Test 1', y: 16.19 },
   { name: 'Test 1', y: 26.87 },
   { name: 'Test 1', y: 36.65 },
   { name: 'Test 1', y: 31.44 },
]

dataList2 = 
[
   { name: '1h', y: 61.41 },
   { name: '2h 30m', y: 41.35 },
   { name: '2h 30m', y: 51.00 },
   { name: '22h 30m', y: 36.29 },
   { name: '4h 30m', y: 31.23 },
   { name: '12h 30m', y: 21.16 },
   { name: '4h 30m', y: 18.19 },
   { name: '6h 30m', y: 46.87 },
   { name: '7h 30m', y: 37.65 },
   { name: '9h 30m', y: 30.44 },
]

Next, I configure the graph:


var conf = {
   chart: {
       type: 'column',
   },
   title: {
       text: null
   },
   navigation: {
       buttonOptions: {
           enabled: false
       }
   },
   colors: 
       ['#DA6AFF', 'rgb(76, 43, 228)']
   ,
   title: {
       text: null
   },
   yAxis: {
       title: {
           useHTML: true,
           text: null
       }
   },
   xAxis: {
       categories: [1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
   },
   credits: {
       enabled: false
   },
   series: [{
       type: 'column', 
       name: 'Bar Chart',
       data: dataList1, 
       marker: {
           enabled: false,
       },
       tooltip: {
           pointFormat: '<b>{this.series.data.y}</b>'
       },
   },{
       type: 'line', 
       name: 'Line 1',
       data: dataList2, 
       marker: {
           enabled: false,
       },
       tooltip: {
           pointFormat: '<b>{this.series.data.name}</b>'
       },
   }]
};

const options = {
   global: {
       useUTC: false
   },
   lang: {
       decimalPoint: ',',
       thousandsSep: '.'
   }
};

In this way, the bar chart displays the value {this.series.data.y} in the tooltip and the line graph shows the value {this.series.data.name}.

For instance:

  • Clicking on position "4" of the bar reveals the value of "31.29" in the Tooltip.
  • Clicking on position "4" of the line reveals the value of "22h 30m" in the Tooltip.

Answer №2

Kindly review the example provided here. If you have defined the configuration in this way:

var conf = {
  chart: {
    tooltipArr: exData,
  },
  series: [{
    tooltip: {
      pointFormatter: function() {
        var toolTip = this.series.chart.options.chart.tooltipArr;
        return toolTip[this.x];
      }
    }
  }]
}

In your case, accessing the tooltip data using:

var toolTip = this.series.chart.options.chart.tooltipArr;

may lead to encountering undefined values. For customizing tooltips based on received values, it is advisable to use the formatter function. You can track the x and y values with this.x or this.y.

If you already know what to display in tooltips, consider declaring a constant outside the conf object and accessing it within the tooltip formatter function similar to how the package author does.

const tooltips = ['Tooltip1', 'Tooltip2'];

var conf = {
  chart: {
    type: 'spline',
  },
  title: {
    text: 'Live random data'
  },
  tooltip: {
    formatter: function () {
      return this.y > 0 ? this.series.name : tooltips[0];
    }
  },
  series: [{
    name: 'Random data'
  }]
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible for Nuxtjs/apollo to make apollo wait for other requests before initiating the query?

Is there a way to have Apollo wait for the result of one request to a third party before making either of two queries? Or should I manually add the appropriate query to Apollo after receiving the results? ...

Working with DOT in URLs using AngularJS UI-Router

I am currently facing an issue while trying to authenticate users using the Google API. The problem arises when the return data in the parameters contain a DOT within the token, causing the server to break as it requests a page that does not exist. However ...

Prevent anchor link click and drag functionality on an HTML page / Swipe through a container containing links

Is there a way to prevent clicking and dragging on a link in a webpage? When you click the left mouse button on a link and drag it, you can unintentionally move the link or open a new tab. I am looking for a way to disable this behavior using JavaScript o ...

Automatic popup updates when submitting a form in a Chrome extension

Looking to develop a chrome extension popup window that, when clicked, will present a form for users to input their name and college. The goal is to save this data in chrome storage and then replace the popup with a new window displaying a greeting message ...

Bootstrap wysiwyg5 editor validation: Ensuring accuracy in your content creation

Currently, I have integrated the Bootstrap wysiwyg5 editor into a form. One of the fields in this form, specifically the text area, is mandatory and cannot be left empty. I am facing a challenge in validating whether the user has entered any content into t ...

Implement a button transformation upon successful completion of a MySQLi update using AJAX

When displaying multiple database results with buttons that can be turned on or off inside a div, I am looking to implement AJAX to toggle the button state between ON and OFF upon clicking, and then update the button without refreshing or reloading the ent ...

Sass: Setting a maximum width relative to the parent element's width

I have a resizable container with two buttons inside, one of which has dynamic text. Within my scss file, I am aiming to implement a condition where if the width of the container is less than 200, then the max width of the dynamic button should be 135px, ...

Is it possible to create Vue apps using TypeScript with just Babel?

Is there a way to compile and construct my TypeScript Vue application using only Babel? After extensively utilizing vue-cli-service, I've come to the point where I require a more minimal setup, eliminating the need for webpack or any other similar too ...

Can someone assist me in displaying the items in this array?

System.out.println("Here is the list by Category Type."); System.out.println("Please enter the category you are looking" + " for."); String search = user_input.next(); System.out.println("Here is what we found for that category: "); ...

What could be causing npm to not recognize my module in the "require" statement?

Currently, I am in the process of developing an npm module and conducting tests before making it available to the public. The method I am following is outlined in a blog post found at this link. However, I am encountering difficulties when trying to requir ...

Contrasting the process of generating DOM elements by using createElement, setting properties, etc., versus constructing a string of elements and then appending them

I am curious about the distinction between these two methods for creating HTML elements. I cannot seem to find any difference. I simply want to understand if there are any variations based on performance or any other factors. The first technique involves ...

jQuery - Password Validation

I need help using jQuery to validate two password fields against each other. Below is the code snippet I am currently using: jQuery('#settingsForm').validate( rules : { npassword : { }, pass_check : { equ ...

Retrieve a specific couchDB document using an external parameter

I have a couchDB database that contains various documents. These documents need to be accessed through my web application, where users can input specific words to retrieve the corresponding document from the database. This is my _design document { "_id ...

What is the best way to display a string state value in a React component?

I need assistance with displaying a state value that is in string format. Despite my efforts, I have not been successful in finding a solution and am feeling quite frustrated. Can anyone provide some guidance? ...

Modify the current link's <li> class

I am facing an issue with the code below which is supposed to change the class of li based on whether the browser URL matches the href attribute within that li. The current problem I am encountering is that the code changes the class for all li elements, ...

JavaScript code for iframe auto resizing is not functioning properly on Firefox browser

I have implemented a script to automatically resize the height and width of an iframe based on its content. <script language="JavaScript"> function autoResize(id){ var newheight; var newwidth; if(document.getElementById){ newh ...

Iterating through an array and setting variables according to asynchronous code

I have created a function to loop through an array, call a promise, and update a variable based on the result. The code seems to be functioning correctly, but I am wondering if there is a more optimal way to write it. Any suggestions are appreciated. Tha ...

Exploring CountUp functionality with Vue framework

I'm still getting the hang of Vue and recently completed my first project following a tutorial. This project is my first solo endeavor. Currently, I am working on a basic page to display the scores between two teams. The scores are retrieved from an ...

Angular checkboxes not triggering ng-click event

Within my Angular application, there is a form that includes checkbox inputs: <div ng-repeat="partner in type.partners"> <label class="checkbox-inline"> <input type="checkbox" value="partner" ng-checked="report.participa ...

Securing uploaded documents and limiting access to approved individuals

Currently, I am utilizing Multer for file uploads and I am contemplating the ideal approach to secure access to these files post-upload. In my system, there are two user roles: admin and regular user. Users can only upload photos while only admins have ac ...