The annotation feature in Highcharter is reportedly malfunctioning when applied to the date x-axis in

I've been attempting to include annotations in my highcharter chart, but for some reason, it's not working and is displaying [object][object] instead.

Below is the data:

structure(list(variable = structure(c(15522, 15553, 15584, 15614, 
15645, 15675, 15706, 15737, 15765, 15796), class = "Date"), value = c(417376, 
423563, 430290, 455643, 451542, 422419, 429472, 451694, 454900, 
456844)), row.names = c(NA, 10L), .Names = c("variable", "value"
), class = "data.frame")

The code I'm using is to add annotation specifically for the last value on the graph, potentially within a rectangle box.

currmonth <- max(pricedata$variable)
pricedata$value <- round(pricedata$value)
highchart(type = "chart") %>% 
  hc_chart(backgroundColor = "white",zoomType = 'x') %>%
  hc_add_series_times_values(pricedata$variable, pricedata$value, name = "Price") %>%
  hc_annotations(list(xValue = currmonth, title = list(text = 'Annotated chart!')))

Here is the visual representation of the chart:

https://i.sstatic.net/2ZkAl.png

You'll notice that the annotation appears as [object][object] in the top left corner.

UPDATE: After trying out the solution provided, unfortunately, it did not work.

https://i.sstatic.net/Lma8d.png

https://i.sstatic.net/AMgi8.png

https://i.sstatic.net/KBNGn.png

Answer №1

Inspired by the example provided at this link, and guided by the informative tutorial available here, it is indeed possible to achieve similar results.

Starting with the creation of the chart through the use of the hchart function is recommended.

library(tidyverse) # for pull and last
library(highcharter)

currmonth <- max(data$variable)
lastvalue <- data %>% pull(value) %>% last()

hc <- hchart(data, "line", hcaes(variable, value)) 

After creating the chart, the next step is to add annotations resembling the provided examples:

hc %>% 
  hc_annotations(
      list(
          labelOptions = list(y = 50, x = 0),
          labels = list(
            list(
              point = list(
                x = highcharter::datetime_to_timestamp(currmonth),
                y = lastvalue,
                xAxis = 0,
                yAxis = 0
              ),
              text = scales::dollar(lastvalue)
              )
            )
          )
      )

https://i.sstatic.net/rxMlk.png

Although highchartsJS requires a significant amount of nested lists, this approach effectively adds annotations in highcharter (for now).

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

Tips for manipulating the DOM: Pushing existing elements when new ones are dynamically created with JavaScript

I have a pre-existing DOM element (let's say a div) and I am using JavaScript, specifically React, to create a new element - another div which serves as a sidebar. The goal is for the sidebar to seamlessly shift the previous element without overlappin ...

Using HTML and JavaScript, we can set two different color values - one for the background and one for the h1 title

I am trying to save two values, one for the h1 tag and one for the body background. I want the user to select color 1 and color 2. When I press the third button, all changes should be applied and the colors should change. I have attempted this but with no ...

Block users from viewing the image displayed within a JavaScript canvas

On my server, I have a path to an image that is accessed by a JavaScript to load the image onto a canvas. The script then proceeds to hide certain parts of the image using black layers. The issue arises when a user can easily view my JavaScript code, extr ...

Is it possible to create dynamic meta tags in Angular that will appear in a Twitter-style card preview?

My project involves building a dynamic website using a Java app that serves up a REST-ish JSON API along with an Angular9 front end. A key requirement is the ability to share specific URLs from the app on platforms like Twitter and Slack, which support Twi ...

Utilize esbuild to monitor for any modifications, recompile the code, and automatically restart the express server

In my endeavor to develop a basic SSR-powered project using express + react, I find the need to monitor frontend and backend scripts concurrently in the development process. The primary objective is to utilize express routes in directing to react page com ...

Utilize underscore's groupBy function to categorize and organize server data

I am currently utilizing Angular.js in conjunction with Underscore.js This is how my controller is structured: var facultyControllers = angular.module('facultyControllers', []); facultyControllers.controller('FacultyListCtrl', [' ...

JavaScript function to evaluate true conditions

I am encountering an issue while calling sub functions connected to if statements within my main function. Even though the sub functions are supposed to return true or false, the expected alerts are not appearing. if (functionAAA()){ alert("111 ...

When the defineModel macro is used in Vue.js, it does not automatically update the state

Click the link below for a sample of what I am attempting to do with Vue: <a href="https://play.vuejs.org/#eNqVU8Fu2zAM/RVBl6RA5mDozXMCbEU3bNjaYd1RF8+mE2Wy7ElymsHwv4+UbMUrghY9BJHER/Lx8bnn79s2OXbAU57CwsjWMQuua7dCy7ptjGM3e6lKVpmmZoW+UsIiAnu3A3eU1rCiVDmyI ...

Prevent clicking on form until setInterval has been cleared using React useEffect

Here is a link to a sandbox replicating the behavior: sandbox demo I have integrated a hook in a React component to act as a countdown for answering a question. React.useEffect(() => { const timer = setInterval(() => { setTimeLeft((n ...

Playing sound using jQuery when the body of the page is replaced

I am facing an issue with my website where I have implemented a jQuery full body refresh every 30 seconds. However, I want to add a short sound to play every time the page refreshes. Despite trying various methods, the sound works on my computer browsers ( ...

Dealing with incorrect user authentication in a login system using MySql and NodeJs

I am currently using the following controller to handle the login system for my app. It is functioning correctly in all scenarios except when an incorrect username is inputted. To address this issue, I have implemented the following conditional statement: ...

What is the goal of JSON.parse(JSON.stringify(x))?

During my recent project work, I stumbled upon the following code snippet: let newParams = JSON.parse(JSON.stringify(initialParams)); I'm curious - what exactly does this code achieve? ...

Display tables based on selected changes with dynamically changing options

My HTML structure displays rows with active and inactive statuses based on a select change, and it's currently functioning correctly. However, the project requirements have changed, allowing for more status options besides just active and inactive. I ...

Utilizing NodeJS to Refine JSON Data

I am working with a JSON array that consists of multiple objects. My goal is to retrieve objects that have a specific value, such as returning [ service_wog: { count: 48, popular: false, code: 33, price: 20, id: ...

`The Art of Binding() with Objects Created on the Fly`

Currently facing challenges with rebinding something using a dynamically created object from prepend. Despite trying several methods, I am only able to unbind. Seeking assistance. $(document).ready(function(){ $(".newdir").click(function(){ $(".d-exp ...

The Joi Validation feature is ineffective when used with the schema provided below

{ "email": "{{$randomExampleEmail}}", "dateofbirth": "2000-01-09", "personal_document":{ "document_front":"url", "document_back":"url", ...

An incorrect object was removed from the array

Having an issue where the wrong item is getting deleted from an array in my component's state. Here is a simplified version of my parent Component: export default class BankList extends Component { state = { banks: [new Bank("Name1"), new ...

Issue with Vue/Nuxt 3: Unable to modify properties of null when setting 'textContent'

I am currently facing an issue with a function that is designed to switch words every few seconds. The functionality itself is working fine, but I keep encountering the following error intermittently in the VSC console: TypeError: Cannot set properties o ...

Updating an element in jQuery using the .each() method

HTML code: var values=[5, 10, 15, 20, 25, 30] $.each(values, function(position, number) { setTimeout(function() { $('#contentBox').text(number); }, position * 5000 ); }); I am attempting to update the content of the contentBox d ...

Guide on downloading the complete Vue.js to-do list with JsPdf

I am new to this field and attempting to create a small project using Vue.js. I want to provide users with the option to download their Vue.js to-do list. I have imported the jspdf library and Html2canvas. Here is the current output, but this is the desire ...