Modify color of a specific column in highchart using the default color palette

Changing the color of a single column in highcharts has been a challenge for me. Even though I can change it for the entire series, figuring out how to do it for just one column has proven difficult. Here is how my series is created:

var dates = [];
var scores = [];
vm.data.values.forEach(function (item) {
    dates.push(datefilter(item.date, 'yyyy-MM'));

    if (item.isCurrent) {
        scores.push({
            y: item.score || 0,
            marker: {
                fillColor: '#FF0000',
                lineWidth: 5,
                lineColor: "#FF0000"
                }
            });
    }
    else {
        scores.push(item.score || 0);
    }
});

vm.chartConfig = {
            options: {
                chart: {
                    type: 'column'
                },
                plotOptions: {
                    series: {
                        cursor: 'pointer'
                        },
                        marker: {
                            lineWidth: 1,
                            symbol: 'circle'
                        }
                    }
                }
            },
            title: {
                text: "Scores"
            },
            xAxis: {
                categories: dates
            },
            yAxis: {
                title: {
                    text: null
                }
            },
            series: [
                {
                    name: 'Scores',
                    data: scores,
                    color: "#249858"
                }
            ]
        };
    };

The HTML code of the component is as follows:

<highchart config="vm.chartConfig"></highchart>

Despite my efforts, I have only managed to see one color that I set in the chartConfig object. The custom color set during the creation of series data in the loop does not seem to apply. Any guidance or a link to a Plunker demo would be greatly appreciated.

Answer №1

After encountering a similar issue, I discovered that the color I was trying to set was in the wrong places.

OLD

if (item.isCurrent) {
    scores.push({
        y: item.score || 0,
        marker: {
            fillColor: '#FF0000',
            lineWidth: 5,
            lineColor: "#FF0000"
            }
        });
}
else {
    scores.push(item.score || 0);
}

Replacing it with NEW CODE

if (item.isCurrent) {
    scores.push({
        y: item.score || 0,
        marker: {
            fillColor: '#FF0000',
            lineWidth: 5,
            lineColor: "#FF0000"
            }, 
        color: '#FF0000'
        });
}
else {
    scores.push(item.score || 0);
}

This adjustment resolved the issue for me.

NOTE: I incorporated the marker color because I am working on rendering both line and column charts. The color attribute affects the column chart while the marker attribute impacts the line chart.

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

Creating an Angular service that checks if data is available in local storage before calling an API method can be achieved by implementing a

I am currently working on developing an Angular service that can seamlessly switch between making actual API calls and utilizing local storage within a single method invocation. component.ts this.userService.getAllUsers().subscribe(data => { conso ...

Ways to access JSON data in JavaScript

I'm experiencing difficulty accessing the JSON data provided below. My approach involves utilizing the JavaScript AJAX success function, and when attempting alerts with the following code, $.ajax({ type:'GET', url:myURL, success : function ...

Analyzing latency in node.js through numerous requests

Is there a way to send multiple requests in a loop, and measure the time of each request? In PHP I'd do: require 'vendor/autoload.php'; use GuzzleHttp\Client; $client = new Client(); for ($i = 0; $i < 100; $i++) { $start = mic ...

Obtain the inner DIV's ID by clicking on it and using JavaScript

I am trying to extract the ID of the inner DIV using JavaScript. You can view the fiddle http://jsfiddle.net/5yn2hLv9/8/. When I click on First Tab/Second Tab..., the ID of the tab should be fetched in the JavaScript function getInnerDivId(). Any suggestio ...

What is the best way to respond to a hashchange event within AngularJs?

I am new to AngularJs and I am trying to update the page on hashchange events. Currently, I have this code which I know is not the proper way to do it: <!DOCTYPE html> <html> <head> <style> #hashdrop { display:block; ...

What is the process of transitioning from jQuery to plain JS for converting selectors and event capturing?

Looking for assistance in converting this code to vanilla JavaScript: document.addEventListener("DOMContentLoaded", function() { document.querySelector("textarea").addEventListener("keydown", function(event) { var textarea = this; ...

Encountering the issue "then function not found" while working with angular js

I am attempting to retrieve data from a file using $http. I have created a factory and obtained the result in a controller. I am trying to define both success and error methods, but I keep encountering the following error accountDetailService.callAccountD ...

Sending data from an external input field to a form using AngularJS programmatically with element name

I am facing a challenge where I need to include an Input element in a Form, even though the Input is located outside of the form. While I have managed to add the input using form.$addControl(outerInput), it is not producing the desired outcome as shown in ...

Transferring ajax data to a variable on a Node.js server

I am currently facing an issue with an ajax get request that involves passing data from an input into a variable and using it in a query. The situation is being handled within index.handlebars page: <!DOCTYPE html> <html> <head> ...

Capturing a part of the screen using JavaScript for screen recording

I'm exploring the possibility of implementing a JavaScript screen recorder that captures a video feed rather than the entire screen. I'm wondering if it's achievable using getDisplayMedia or if there's a specific library for this purpos ...

`Cannot press when using custom cursor in JS?`

Hey there! I'm currently working on implementing a custom cursor for specific elements on my website. However, I've encountered a little hiccup - once the custom cursor is in place, I'm no longer able to click on any elements. Does anyone ha ...

Styling elements with values from an object array

I have been working on a code snippet to extract checked checkboxes and match their names with an object array in order to retrieve certain values. You can find a sample fiddle here. Now, I am wondering how I can utilize these extracted values to dynamica ...

What steps are required to insert additional tags into select2?

I've successfully retrieved the tags from my API, but I'm facing an issue with adding new tags. Here's the code snippet I've been using: $(function(){ var user_email = localStorage.getItem('email'); var api = ...

AJAX is delivering a unique random hash instead of the expected text

I am in the process of developing a live notification script, and I have encountered an issue. Instead of receiving plain text from the external file, the script is returning a random hash... Here is the function responsible for fetching data from test.ph ...

Exploring Multilingual Autocomplete or: Best Practices for Managing Multiple Languages in Web Applications

I'm currently developing a website and I have a mysql-table named 'items' with the following structure: item_id | item (The second column is used to identify the item_id.) In a file called language1.php, I have an array that stores the it ...

Tips for incorporating CSS classes into a React component

Currently, I am iterating through an array of data to create a list. My goal is to add a CSS class when a specific list item is clicked. Using Iteration for List Creation let sportsList = allSports.sportList.map((sport) => { return ( <SportItem i ...

After an Ajax request, the functionality of Javascript/Jquery ceases to work

After successfully submitting a form via ajax for the first time, the subsequent submissions seem to break all javascript functionality on the page. Additionally, the form is unable to submit with ajax again. Below is the code snippet for the ajax call: ...

When I log out and hit the back button, the PHP page continues to display without any changes

After logging out of my PHP session and being redirected to the login page, I am facing an issue where pressing the back button shows me the previous page without requiring a login. How can I fix this problem? Thank you in advance. index.php <form sty ...

The ArrowHelper in THREE.js seems to be ignoring the natural rotation provided by Euler angles

Can someone help me with setting intrinsic rotations to a THREE.ArrowHelper in THREE.js? I'm trying to work with Tait-Bryan euler angles for 3D rotations. In the snippet below, I define a unit vector for the x-axis as THREE.Vector3(1, 0, 0). Then, I ...

Determine selected option in Radio Button

FORM : <form id="approvalPenambahanUserInt" name="approvalPenambahanUserInt" action="" method="post"> <div class="form-group"> <div class="col-sm-12"> <label for= ...