How can I control the color of individual segments of a pie chart in Excel?

I would like to be able to control the color of sections in a pie chart programmatically. Ideally, my chart will be based on a three-column table, and the columns will be as follows: Data value, label, and color chart value. The color values ​​will be the same numbers that are visible in the properties of the access form.

Thanks,

Steve

+6
colors excel controls charts
source share
4 answers
Sub a() ActiveSheet.ChartObjects("Chart 1").Activate ActiveChart.SeriesCollection(1).Points.Item(1).Interior.ColorIndex = 7 End Sub 

You can find out the color represented by ColorIndex , with the trick I posted in This other answer

+2
source share

Perhaps something on these lines?

 Dim ws As Worksheet Dim sh As Shape Set ws = Sheet2 Set sh = ws.Shapes.AddChart '.Select With sh.Chart .ChartType = xlPie .SetSourceData Source:=Range("Sheet1!$A$1:$B$3") For i = 1 To .SeriesCollection(1).Points.Count With .SeriesCollection(1).Points(i).Format.Fill .ForeColor.RGB = Range("C" & i).Interior.Color .Solid End With Next End With 

This will allow you to add color to the cell using the fill button and use it for the segment.

+2
source share

First of all, I know that this can be done. BeGraphic has an Excel add-in with an add-in with the ability to set the colors of chart elements in the distribution. Cm.:

Use an add-in. I have to say that the results are impressive. For myself, I needed something more than Excel, and many others would find this option on a shelf.

While the VB option from Remou and the add-in does this. For me, or for the current project, at least I need an Excel-based solution (as much as possible and possible). At the same time, you feel great, and I can find workarounds through VB, VBA, .Net and / or macros. Visit the Jon P website for available options.

If I find "more" - I will return it back at this request.

aloha
Will it

0
source share

It may be possible to do this using VBA, but here I propose another solution that allows you to do this using JavaScript . You can use the free Excel add-in called Funfun, which allows you to use JavaScript code directly in Excel. At the same time, you can use libraries such as HighCharts.js or D3.js to draw a pie chart and manage the color separately. Here is an example that I made based on your description.

enter image description here

The colors of the different parts of the pie chart are determined by the data of the third column in the spreadsheet. In this example, I used HighCharts.js to control the drawing of this chart. The specific code that controls the color can be seen below.

  var pieColors =[]; for(var i=1;i<data.length;i++){ switch(parseInt(data[i][2])){ case 0: pieColors.push('blue'); break; case 1: pieColors.push('green'); break; case 2: pieColors.push('orange'); break; case 3: pieColors.push('purple'); break; case 4: pieColors.push('red'); break; case 5: pieColors.push('brown'); break; } } 

In this example, I just manually selected six colors, but you can easily generate a random color or color in a specific range using JavaScript code.

The Funfun add-in also has an online editor where you can test your code and result. You can check the detailed code and this example from the link below.

https://www.funfun.io/1/#/edit/5a4f4680c3a8a526caeec989

Once you are satisfied with your result, you can easily load the result into your Excel using the link above. But, of course, firstly, you need to add the Funfun add-in to your Excel using Insert - Office Add-Ins. Here are some screenshots showing how you load an example in Excel.

enter image description here

enter image description here

Disclosure: I'm a Funfun Developer

0
source share

All Articles