`Is it possible to display the x and y axis upon clicking on Angular JS Charts?`

Currently, I am attempting to retrieve the values for the x and y axis when clicking on the chart area. Here is what I have so far:

HTML:

<script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="72131c15071e13005c180132435c" rel="noopener noreferrer">[email protected]</a>" src="http://code.angularjs.org/1.2.2/angular.js" data-semver="1.2.2"></script>
<script data-require="d3@*" data-semver="3.3.11" src="//cdnjs.cloudflare.com/ajax/libs/d3/3.3.11/d3.js"></script>
<script type="text/javascript" src="https://rawgit.com/chinmaymk/angular-charts/bower/dist/angular-charts.min.js"></script>

<div ac-chart="'area'" ac-data="barData" ac-config="config" id='chart2' class='chart'  style="width: 100%"></div>

JS:

$scope.config = {
                        title: 'Customer Distribution',
                        tooltips: true,
                        labels: false,
                        mouseover: function () {
                        },
                        mouseout: function () {
                        },
                        click: function (d) {
                            console.log(d);
                            console.log(angular.toJson(d));
                        },
                        isAnimate: true,
                        waitForHeightAndWidth: false,
                        legend: {
                            display: true,
                            position: 'right',
                            htmlEnabled: false

                        }
                    };


                    var sin = [];

                    if (angular.equals(bin, "UNIT")) {
                        angular.forEach(data, function (item) {
                            var y = [];
                            y.push(item.customerListSize);
                            sin.push({x: item.value, y: y});
                        });
                    } else {
                        angular.forEach(data, function (item) {
                            var y = [];
                            y.push(item.totalBinSize);
                            sin.push({x: item.binName, y: y});
                        });
                    }

                    $scope.barData = {
                        series: [featureType],
                        data: sin
                    };

The charts are displaying correctly, however, I would like to enhance the functionality of the click event. I need to obtain the x and y values of the chart when clicked in order to update the tooltip and call another method using those values. Can someone please advise me on how to retrieve the values upon click? When I tried printing the console on click, it only displays the screen position.

Answer №1

Here's a helpful tip:

click: function(d) {
  console.log(d);
},

When you use d, it represents the datum of the object that was clicked on.

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 there a way to determine if every number in one array is the square of a number in another array?

Define a function comp(a, b) (also called compSame(a, b) in Clojure) that determines whether two arrays a and b have the same elements with the same multiplicities. In this case, "same" means that every element in array b is the square of an element in arr ...

The npm package for @azure/storage-blob doesn't seem to play nice with the Azure Blob storage modules for IoT Edge

Currently, I am developing an edge module using Node.js to interact with Azure Blob storage modules on IoT Edge platform. To achieve this, I am following the documentation available at https://www.npmjs.com/package/@azure/storage-blob. The npm package ut ...

Encountered an issue with instafeed.js due to CORS policy restrictions

Trying to implement an API that provides JSON data for use in a function. Required Imports: Importing Jquery, instafeed.min.js, and the API (instant-tokens.com). <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js& ...

ASP.NET "Data" Error: Trouble Parsing JSON Data on the Front-End

I am currently facing an issue with the configurations on my asmx page. The code is set up like this: using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Script.Serialization; using Syst ...

`Vue function is unable to find the definition of a variable`

I am struggling with utilizing a variable in a vue 3 application that has been emitted by a component called Mags. The variable is functioning properly in the importMags function, however, I am unable to access it within the handleSubmit function. It consi ...

What is the difference in memory usage for JavaScript objects between Node.js and Chrome?

It's puzzling to me why the size of the heap is twice as large as expected. I meticulously constructed a binary tree with perfection. I suspect v8 recognizes that each node consists of 3 fields. function buildTree(depth) { if (depth === 0) return n ...

Guide to Appending "Z" to a Date String Using Moment.js in JavaScript and Node.js

I am struggling to format my date to include the "Z" letter at the end. Despite numerous attempts, I have been unsuccessful. The desired format is "YYYY-MM-DDT00:00:00.000Z," but currently it does not include the Z How can I add the Z using moment? It&ap ...

The CORS policy has blocked access to XMLHttpRequest at 'http://localhost:8080/' from the origin 'http://localhost:3000'

There seems to be an issue with the CORS policy blocking access to XMLHttpRequest when trying to send a post request from NuxtJS frontend to a Node server hosted on localhost:3000. Despite using CORS in the app, the error persists, preventing insertion of ...

What could be the reason for receiving an "undefined" response in my API ajax

I'm encountering an issue while attempting to call my API using a search term from a submit form. I keep getting an error that says "cannot read properties of undefined." I'm unsure why there is no data being returned when I send the ajax request ...

Displaying numbers individually with commas in a Django template

I am facing an issue where the number being typed into a text field does not have commas separating the thousands For example, if the user types 500000, it displays as 500000 instead of 500,000 This issue is present in the models section of the code: so_ ...

Save user sessions in a database using node.js, express, and mongoose-auth

I have a question about authentication and sessions in node.js. So, I've set up authentication using express.js and mongoose-auth with mongodb: app.use(express.cookieParser()); app.use(express.session({ secret: 'esoognom'})); app.use(auth. ...

"Adjust the placement of a personalized marker on a Google Map using google-map-react

I have incorporated google-map-react into my React project and I have designed custom markers. The markers are displayed at the correct location but from the top left corner: https://i.sstatic.net/e6lGN.png The red dot indicates the exact location. Howe ...

Utilizing jQuery to Determine Character Count

I've tried everything on the site, but nothing seems to be working. I'm attempting to create a function that triggers when the character count in a div exceeds a certain number, but it's not functioning as expected. Any assistance would be g ...

The HTML button triggers a function to execute on a different webpage when clicked

I'm facing a straightforward issue that I can't seem to figure out due to my limited experience with Angular and web development. The problem revolves around two components, namely home and dashboard. In the home.component.html file, there's ...

The functionality of JQuery's `.on("click"... is sporadically functioning

I have a code block that dynamically generates elements and includes event handling. However, the event handling sometimes works and other times it doesn't. I'm not sure how to debug this issue. Can someone help me figure out what might be causin ...

Substitute all instances of null bytes

I need to remove null bytes from a string. However, after replacing the null bytes \u0000 in the string let data = {"tet":HelloWorld.\u0000\u0000\u0000\u0000"} let test = JSON.parse(data).tet.replace("\u0000", ""); I always ...

Guide to inserting a Link or "a" tag into the dropdown menu choices in React

Currently, I find myself tackling a project involving REACT that is slightly outside my comfort zone. My goal is to create a straightforward dropdown menu that can alter the URL seamlessly. Below is the code snippet: function Front() { const [selectedO ...

Combining synchronous and asynchronous code in JavaScript with Node.js and MongoDB

Check out this code snippet: var re = new RegExp("<a href=\"(news[^?|\"]+).*?>([^<]+)</a>", "g"); var match; while (match = re.exec(body)){ var href = match[1]; var title = match[2]; console.log(href); db.news.fin ...

Issue encountered: Next.js version 14, Tesseract.js Error: Module not found .../.next/worker-script/node/index.js'

While working with nextjs 14 and trying to extract text from an image using the tesseract.js node module, I encountered an error where the module was not found. The specific error message I received is as follows: Error: Cannot find module '...(projec ...

What is the best way to bring JavaScript code from one component to another in React?

I am currently working on a mini shop app using VueJS without a backend, focusing on adding items to the shopping cart only. Within Component One (Nmdgrey.vue), I have boots along with an "Add to Cart" button. <button @click="addToCart">Add to cart ...