Could it be that the AmCharts Drillup feature is not fully integrated with AngularJS?

UPDATE:

Check out this Plunker I created to better showcase the issue.

There seems to be an issue with the Back link label in the chart not functioning as expected.


I'm currently facing a challenge with the AmCharts Drillup function, which should allow users to navigate back to previously displayed chart content. While I've managed to get the Drilldown function working correctly, I'm struggling with getting the Drillup functionality to work in AngularJS.

Error in Console:

https://i.stack.imgur.com/E7Mlp.png

Origin of the Error:

.........................
// add back link
// let's add a label to go back to yearly data
event.chart.addLabel(
  70, 10, 
  "< Go back",
  undefined, 
  13, 
  undefined, 
  undefined, 
  undefined, 
  true, 
  'javascript:mostSoldDrillUp();');  <------- THIS IS THE LINK LABEL FOR DRILLUP
.................................

 function mostReferralsDrillUp() {
 ...........
 ...........
 }

Methods I have attempted:

  • I tried placing the AmChart JavaScript code inside a directive's link function, but encountered the error: Uncaught ReferenceError: mostSoldDrillUp is not defined at
    :1:1
    in the browser console.
  • I also attempted to place it within a controller, resulting in the same error.
  • Simply including the JavaScript file and defining the chart's id in a div within the HTML using ui-router yielded the same error.

    .state('home', {
            url: '/',
            templateUrl: './pages/home.html',
            controller: 'HomeCtrl'
        })
    
  • Finally, I omitted the controller from my route definition:

    .state('home', {
            url: '/',
            templateUrl: './pages/home.html',
            // controller: 'HomeCtrl'
        })
    

While this approach worked, I require a controller for other functionalities, rendering this method obsolete.

If anyone has encountered a similar issue or has a potential solution, your input would be greatly appreciated. Thank you.

Answer №1

AmCharts does not have knowledge of Angular's $scope, and when the label link is clicked, it executes resetChart in the global window scope instead of your controller's scope. There are a few ways to address this issue.

1) Define resetChart in the global/window scope to maintain the label within the chart. While not recommended if you want to adhere to Angular's best practices, it can still work.

//inside controller
window.resetChart = function() {
  chart.dataProvider = chartData;
  chart.titles[0].text = 'Yearly data';

  // Remove the "Go back" label
  chart.allLabels = [];

  chart.validateData();
  chart.animateAgain();
}

2) Attach the resetChart method to your controller's scope and use an external element to handle the chart reset, rather than relying on the chart label. This may not be as visually appealing, but it is cleaner than manipulating window.

home.html

<h1>HOME STATE</h1>
<button ng-show="isDrillDown" ng-click="resetChart()">Go back to yearly</button>
<div id="chartdiv"></div>

excerpt of script.js

chart.addListener("clickGraphItem", function(event) {
  if ('object' === typeof event.item.dataContext.months) {

    // Set the monthly data for the clicked month
    event.chart.dataProvider = event.item.dataContext.months;

    // Update the chart title
    event.chart.titles[0].text = event.item.dataContext.category + ' monthly data';

    // Validate the new data and animate the chart again
    event.chart.validateData();
    event.chart.animateAgain();
    $scope.isDrillDown = true;
  }
});

// Function to reset the chart back to yearly data
$scope.resetChart = function() {
  chart.dataProvider = chartData;
  chart.titles[0].text = 'Yearly data';

  // Remove the "Go back" label
  chart.allLabels = [];

  chart.validateData();
  chart.animateAgain();
  $scope.isDrillDown = false;
}

Make adjustments as necessary.

For a demonstration of the second method, see the updated plunker here.

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

Identify and forward to the mobile-friendly version of the site

I am currently working on a website that requires separate files for mobile view as the html layout poses challenges in making it responsive. My goal is to find code that can detect if the user is accessing the site from a mobile device, and automatically ...

The error message "MVC JS deletethisproduct is not defined at HTMLAnchorElement.onclick (VM457 Index:40)" indicates that there

Upon clicking the button, I encounter this error: "deletethisproduct is not defined at HTMLAnchorElement.onclick" While I understand that using onclick is not the ideal approach, I am employing it because I need to retrieve the product id from the mode ...

Upon refreshing, the user of the React JS application is redirected to a different page

My React JS app utilizes react-router-dom v6 to manage the routes. Everything was working fine until I integrated Firebase Firestore. Now, when I reload the seeker page, it redirects me to the home page instead of staying on the seeker page. This issue is ...

Learn how to find and filter elements in arrays that do not include a particular value using React

In my collection of recipes, I have the ability to filter out the ones that include specific ingredients. However, when I attempt to reverse this process by using .some method, it only checks the first item in the array. Here is an example of my data stru ...

Issue with dynamic code detected by Sys.Application.add_init

I am facing a challenge with an older application that I recently took over ownership of. My efforts to successfully run it have been partially fruitful, as I am encountering some strange behavior that seems to be related to Internet Explorer 11. Interesti ...

The HTML background color is refusing to change

I've been struggling to tweak the background color of a specific page. I attempted setting the HTML as the background color, using !important, but unfortunately, it didn't yield the desired result. The same goes for trying to set the background c ...

I'm experiencing an issue where Angular Directives are not rendering properly when fetched from a JSON

I've been working on creating a front end that pulls content from a WordPress CMS. I've successfully used the WP REST API plugin to retrieve JSON data from my WordPress site and display the HTML content using 'ng-bind-html'. However, I ...

Dynamically extract key values from JSON data and display them on an HTML page with checkboxes for selection. Generate a new JSON object containing

I am facing the challenge of parsing an unknown JSON with uncertain key-value pairs. As I do not have prior knowledge of the keys to access, my goal is to traverse through every key in the JSON and display all keys and their corresponding values on the scr ...

Strategies for injecting data into VueJS components after the page has fully loaded

My project utilizes Vue.js and Nuxt.js, and within the settings page, users can modify their personal settings. This single page allows users to navigate between tabs. <template> <div class="account-wrapper"> // Code content he ...

Is there a way to determine the distance in miles and feet between various sets of latitude and longitude coordinates?

I am working with an array of latitude and longitude coordinates and I am looking to use JavaScript or Typescript to calculate the distance in miles and feet between these points. const latsLngs = [ { lat: 40.78340415946297, lng: -73.971427388 ...

Arranging by upcoming birthday dates

Creating a birthday reminder app has been my latest project, where I store names and birthdays in JSON format. My goal is to display the names sorted based on whose birthday is approaching next. Initially, I considered calculating the time until each pers ...

"multer's single file upload functionality is not functioning properly, but the array upload

Currently, I am facing an issue while using react js to upload a single file. Interestingly, the multer.single() method seems to fail, whereas the multer.array() method works perfectly fine. What could be causing this problem? //Node.js const upload = mult ...

Guide for dynamically populating Jqgrid Dropdown depending on another dropdown's data选择如何根

On my screen, I have two dropdowns. One is a standard Razor dropdown and the other is a Jqgrid dropdown. The code for the Razor dropdown looks like this: <div class="col-md-4"> <label for="" class="control-label">Loan Currency</ ...

What is the best way to retrieve all dates that are older than 30 days using JavaScript?

I have the following code snippet as a reference and I'm attempting to retrieve a list of dates from 30 days before. What do I need to change? Date.prototype.addDays = function(days) { var newDate = new Date(this.valueOf()) newDate.s ...

What is the best way to delete an added element once a DIV has been toggled with JQuery?

I'm facing an issue where I need to add an element to a DIV that has a toggle function. However, every time I click the toggle again after adding the element, the same element is appended once more, resulting in duplicate elements. Upon observation, ...

Double Calling of Angular Subscription

I am currently working with a series of observables that operate in the following sequence: getStyles() --> getPrices() Whenever a config.id is present in the configs array, getStyles() retrieves a style Object for it. This style Object is then passed to ...

Having issues with your Spring Boot POST request functionality?

I have been working on developing a Spring Boot REST application with AngularJS. Everything seems to be loading properly, all JS and CSS files are included. However, I am experiencing an issue where GET requests work fine, but POST requests fail and do no ...

Testing the speed of the client's side

In my quest to create an application that allows users to conduct a speedtest on their WiFi network, I have encountered some challenges. While standalone speedtest apps like Speedtest.net and Google exist, server-based speed test modules from NPM are not s ...

Having some trouble creating a ping command in discord.js that displays latency; encountered this error message

I encountered an issue while trying to create a ping command that displays latency. I am unsure why this error is showing up, here is the specific error message - TypeError: Cannot read properties of undefined (reading 'ping') at Object.execu ...

Modifying the Position of the Search Box within DataTables by Manipulating DOM Elements

As a newcomer to the jQuery datatables plugin, I am still learning how to use it effectively. I have connected the plugin to my tables using the following code: $(document).ready(function() $('#table_id').dataTable({ }); }); ...