Jump to content
  • 0

Stacked Area Chart Colors


Benades

Question

Hi, I managed to change a Stacked Column Chart colors by adding a header and setting a style to it:

<style>
rect.highcharts-point.highcharts-color-0{
fill: #006B3C;
}
rect.highcharts-point.highcharts-color-1{
fill: #682861;
}
rect.highcharts-point.highcharts-color-2{
fill: #CD9B06;
}
</style>

screenshot-c1dcn529.caspio.com-2021_07_07-15_17_04.png.a1feaeda0e463e2035d031ad0db48e75.png

Now I need to do the same with a Stacked Area Chart but cannot find the same heading to apply the color to (highcharts-color-0):

Capture12.thumb.PNG.5a04f66e7d9995ea9b37cbecfaa9f405.PNG

screenshot-c1dcn529.caspio.com-2021_07_07-15_15_15.png.ea73093c44b89e4584026cc4395c5dd7.png

When I use the same logic to style, it changes colors for all to the same color because there are no differentiating name:

<style>
path.highcharts-area{
fill: #CD9B06;
}
</style>

 

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 2

Try JS instead,

 

<script type = "text/javascript" >

    var timer = setInterval(function() {
        //Find if chart exists using rect element every x milliseconds
        if (document.getElementsByTagName('rect') != null) {
            //Update Chart
            UpdateChart();
        }
    }, 500);


function UpdateChart() {
    try {

        Highcharts.charts[0].update({
            
//CHANGES HERE
          
          
  series: [

{color:'red'},
{color:'blue'},
{color:'yellow'}


]

//CHANGES END HERE

            
});
        //Stop checking
        clearInterval(timer);

    } catch (err) {
        //log errors
    }

}; 
</script>

basically makes the first one red, then blue, then yellow

 

No script:

image.thumb.png.2b3066ca6fde27e1ca351e18903b5a5d.png

 

With the script
image.thumb.png.b59afafa682347bf15dede281aacd6fb.png

Link to comment
Share on other sites

  • 0
On 7/7/2021 at 9:28 AM, TellMeWhy said:

Try JS instead,

 

<script type = "text/javascript" >

    var timer = setInterval(function() {
        //Find if chart exists using rect element every x milliseconds
        if (document.getElementsByTagName('rect') != null) {
            //Update Chart
            UpdateChart();
        }
    }, 500);


function UpdateChart() {
    try {

        Highcharts.charts[0].update({
            
//CHANGES HERE
          
          
  series: [

{color:'red'},
{color:'blue'},
{color:'yellow'}


]

//CHANGES END HERE

            
});
        //Stop checking
        clearInterval(timer);

    } catch (err) {
        //log errors
    }

}; 
</script>

basically makes the first one red, then blue, then yellow

 

No script:

image.thumb.png.2b3066ca6fde27e1ca351e18903b5a5d.png

 

With the script
image.thumb.png.b59afafa682347bf15dede281aacd6fb.png

Hi, sharing in here a script that I found that allows you to check if an element exists (followed by your code if that element in fact exists) instead of using a timer (setInterval):

 

function waitForElm(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }

        const observer = new MutationObserver(mutations => {
            if (document.querySelector(selector)) {
                resolve(document.querySelector(selector));
                observer.disconnect();
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
}

 

 

 

 

To use it:

waitForElm('.some-class').then((elm) => {
    console.log('Element is ready');
    console.log(elm.textContent);
});
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...