Jump to content

Change color of the column in chart


Recommended Posts

Hello!

To change the color you need to use additional JS code. It will parse the data in chart and change the color according to name of the column.
Here is the code:

<script type="text/javascript">
document.addEventListener('DataPageReady', chartUpdateHandler);

function chartUpdateHandler(event) {
  
 var cleaner = function(interv) {
  clearInterval(interv);
 } 

 let interv = setInterval(() => {
  if (!!Highcharts) {
   const options = Highcharts.charts[0].series[0].data;
   let data = []; 

   options.forEach(option => {
      let localData = {};
      localData.y = option.y;
      localData.name = option.name; 

      if(option.name === "(blank)") {
       localData.color = '#ee5921';
      } else {
       localData.color = '#3186AD';
      } 

      data.push(localData);
     })   

     Highcharts.charts[0].update({
      series: {
       data: data
       }    
    });
    cleaner(interv);
  } 
 }, 200);
}
</script>

You need to insert this code into the Header of the report DataPage. Do not forget to disable the HTML editor.

Link to comment
Share on other sites

Hello, you can also try getting the nth child but will be a static change of color display. But since the chart will always return the blank in the first line, we can always modify the 1st one to be set as orange. Try pasting this to the header as well:

<style>

rect.highcharts-point.highcharts-color-0:nth-child(1) {
    fill: #ffd3a8;
}

</style>

 

If you want  to also apply different colors to the other values, change the bold number to any desired  displayed number  and it should work as expected. 

Link to comment
Share on other sites

2 hours ago, SinJunYoung said:

Hello, you can also try getting the nth child but will be a static change of color display. But since the chart will always return the blank in the first line, we can always modify the 1st one to be set as orange. Try pasting this to the header as well:

<style>

rect.highcharts-point.highcharts-color-0:nth-child(1) {
    fill: #ffd3a8;
}

</style>

 

If you want  to also apply different colors to the other values, change the bold number to any desired  displayed number  and it should work as expected. 

Excellent solution, worked like a charm.  Hastur's solution worked too, but seams to be resource intensive.  (Perhaps my machine just acted up..)   Thank you both!!

Link to comment
Share on other sites

  • 1 year later...
  • 6 months later...

This works perfectly!

Is there a way to add other chart columns to this?

I want to add other columns from the chart using different colors based on "status" .
I can change the color for one column but need to change for multiple columns  some different statuses.

Link to comment
Share on other sites

  • 5 months later...
On 5/29/2020 at 7:43 AM, Hastur said:

Hello!

To change the color you need to use additional JS code. It will parse the data in chart and change the color according to name of the column.
Here is the code:

<script type="text/javascript">
document.addEventListener('DataPageReady', chartUpdateHandler);

function chartUpdateHandler(event) {
  
 var cleaner = function(interv) {
  clearInterval(interv);
 } 

 let interv = setInterval(() => {
  if (!!Highcharts) {
   const options = Highcharts.charts[0].series[0].data;
   let data = []; 

   options.forEach(option => {
      let localData = {};
      localData.y = option.y;
      localData.name = option.name; 

      if(option.name === "(blank)") {
       localData.color = '#ee5921';
      } else {
       localData.color = '#3186AD';
      } 

      data.push(localData);
     })   

     Highcharts.charts[0].update({
      series: {
       data: data
       }    
    });
    cleaner(interv);
  } 
 }, 200);
}
</script>

You need to insert this code into the Header of the report DataPage. Do not forget to disable the HTML editor.

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
Reply to this topic...

×   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...
 Share

×
×
  • Create New...