Is it possible to conditionally colour a part of a line in a graph?

excelos

Well-known Member
Joined
Sep 25, 2011
Messages
591
Office Version
  1. 365
Platform
  1. Windows
Hello!

Is it possible to colour a part of a line in a graph based on the colour of the source cells?

Thanks!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Yes it is ( or at least it will look as though it does.) I did this to produce a KAGI plot,
the basic principle is you use a scatter plot with no markers and put two lines on it in different colours with exactly the same points on them, then delete some of the points in the second line and the first line will show through
In detail put the number 1 to 30 in cells A1 to A30, and put some suitable numbers in B1 to B30. then copy columns A and B to colums C and D . then delete C5 to D12 and C19 to D23 , ( or any other group of points). Insert a "scatter with straight lines" plot using A1 to D30 as the source, then run this code:

Code:
Worksheets("sheet1").ChartObjects("chart 1").Chart.SetSourceData Source:=Sheets("sheet1").Range(Cells(1, 1), Cells(30, 3)), PlotBy:=xlColumns
Worksheets("sheet1").ChartObjects("chart 1").Chart.ChartType = xlXYScatterLinesNoMarkers
Worksheets("sheet1").ChartObjects("chart 1").Chart.SeriesCollection(1).Name = "Ying"
Worksheets("sheet1").ChartObjects("chart 1").Chart.SeriesCollection(1).XValues = Sheets("sheet1").Range(Cells(1, 1), Cells(30, 1))
Worksheets("sheet1").ChartObjects("chart 1").Chart.SeriesCollection(1).Values = Sheets("sheet1").Range(Cells(1, 2), Cells(30, 2))
Worksheets("sheet1").ChartObjects("chart 1").Chart.SeriesCollection(2).XValues = Sheets("sheet1").Range(Cells(1, 3), Cells(30, 3))
Worksheets("sheet1").ChartObjects("chart 1").Chart.SeriesCollection(2).Values = Sheets("sheet1").Range(Cells(1, 4), Cells(30, 4))
Worksheets("sheet1").ChartObjects("chart 1").Chart.SeriesCollection(2).Name = "Yang"
this shows you how to present it, obviously you need to massage your data to get it into this format.

I have never tried this with other graph types but it might work just as well.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,263
Messages
6,123,959
Members
449,135
Latest member
jcschafer209

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top