Author Topic: Assign different colors for the different levels of an YList  (Read 323 times)


  • New member
  • *
  • Posts: 5
Hi there.

First of all, excuse my English, I am not a native speaker. Before posting I’ve been looking for some information on the following question with no luck, so far. I need to plot a dataset consisting of the number of birds of each sex produced in an aviary in different years.

Sex has 3 “levels” (male, female and unknown), and is defined as:

sexList := array of array[0..2] of Double

Years are defined as:

yearList := array of Double

My first intention is to plot the dataset using a bar chart with Years in the X axis and Sex in a YList with 3 levels per year (male, female and unknown, side-by-side bars). When the dataset is ready, I iterate on the length of the yearList array, adding X and Ylist to the chart source with an AddXYList procedure.

For i = 1 to Length(yearList) do
   listSrc.AddXYList(yearList[i-1], sexList[i-1], yearLabel, . etc...

And here comes the question. I want to use a different color for each of the 3 YList values (male, female, unknown), but replicate the same color scheme for these levels across years. As far as I know, the AddXYList procedure admits a color parameter, but it seems to be for the whole Ylist, not for each level of the YList individually. Am I missing something? Is there any way, apart from using a different approach with 3 different series with their own style, to assign different color values to the different “levels” of an YList?

Thank you.


  • Hero Member
  • *****
  • Posts: 10291
Re: Assign different colors for the different levels of an YList
« Reply #1 on: June 29, 2022, 05:39:35 pm »
Some versions back, side-by-side bar series required a separate series for each bar. Therefore you easily can give each series an individual color by means of the BarBrush.Color property. You will have to shift the bars of the individual series horizontally (BarOffsetPercent, BarWidthPercent) so that the bars do not overlap. The wiki article describes how this can be achieved.

The current version of TAChart supports bars at various YList levels in a single series, also for the side-by-side arrangement (Stacked = false; setting it to true will stack the levels). In order to give the individual levels their own color you must add a TChartStyles component and assign it to the Styles property of the BarSeries. Add three items to the ChartStyles - each item is for a Y level - and specify the color in the Brush.Color property of each style. The tutorial describes how this can be achieved for a stacked bar series (except for setting Stacked = false, this is the same as for side-by-side).

I am attaching a sample project which you hopefully can adapt to your specific application case.
« Last Edit: June 29, 2022, 10:24:45 pm by wp »


  • New member
  • *
  • Posts: 5
Re: Assign different colors for the different levels of an YList
« Reply #2 on: June 29, 2022, 05:55:04 pm »
Thank you very much!
I'll give it a try!

All the best.


TinyPortal © 2005-2018