Chapter 33 Manipulate Chart Colors
Chapter 33 Manipulate Chart Colors
W
hen using charts within your application, you will often get requests from
users to change the colors of the chart elements, whether it be pie chart
segments or bars on a bar chart. This is easily done on the chart itself. But
what if the colors need to be changed dynamically?
Some time ago, I had a complicated request from my users. The application in question
produced reports on foreign exchange transactions for various customers and contained a pie
chart for each customer detailing a summary of the currencies that had been traded.
The problem was that the customers all traded different currencies. One customer might
trade U.S. dollars, GB pounds, and euros, while another might trade Australian dollars, euros,
and Hong Kong dollars.
The problem was that the chart always represented the colors according to the order of the
record source. For one customer, U.S. dollars would come out blue on the pie chart, and for
another customer they would come out red. The users found this very confusing and wanted a
solution whereby each currency had its own fixed color regardless of the mix of currencies.
To see this code in action, you need a form with a chart object on it. The chart must have a
two-column table as the source, detailing the currency indicator and value.
The first step is to create a simple table in Access by clicking Create on the Access menu
and then clicking the Table Design icon in the Tables group of the ribbon. Create the
following fields:
Currency Text
Va l Number, Double
Populate the table as shown in Table 33-1.
321