I have a bar chart with a number of dates on the x-axis. I would like to use different colours for the bars based on defined date ranges. So I would have different coloured bars on the same chart. Is this possible?
Conditional Styling of Bar Charts
(7 posts) (2 voices)-
-
Hi,
You can use dbr.chart.color to set the colors used in the chart (color map). If you want to set color based on the label, use chart option 'label_color' to define the color for specific label.--
myDBR Team -
Ok, yes I've got no problem changing colours using dbr.chart.color but that changes the colour of all bars in my chart. I'm not sure how labels would help, I'm only selecting 2 fields. I have this:
select 'dbr.chart','Column3d';
select date,total
from mytable
group by dateI want the totals to appear in different colours depending on the date.
-
You can do:
select distinct 'dbr.chart.options', 'label_color', date, '0x00FF00'
from mytable
where date <'2014-01-01'
This will give you green labels for dates previous to this year.Btw, you are missing aggregate function from your total (sum(total)) as you are using group by.
--
myDBR Team -
Thanks, that looks like a promising solution but I can't get it working. My full statement is:
select 'dbr.chart','Column3d', 'Accounts Tasks ARD by Month', 1100 as 'x';
select 'dbr.chart.options','rotateNames', 40;
select distinct 'dbr.chart.options', 'label_color', ARD, '0x00FF00'
from mytable
where ARD <'2014-01-01';
SELECT if (ARD<date_sub(now(),interval 11 month),concat(date_format(date_sub(now(),interval 1 year),'%M %y')," or earlier"),
date_format(ARD,'%M %y')) as ARD, Monthly
FROM mytable; -
Just to update I've got this working as expected if I remove the date_format in the final select statement. Is there a way to do this leaving the formatted date in place?
-
Paul,
you can use the date formatting (or choose not to use it) as long as your date format is the same in label_color and in the actual query.The label_color option just builds a label-color pair array and matched the defined labels to the labels in actual query.
--
myDBR Team
Reply
You must log in to post.