Allow users to set chart colors

bones

Well-known member
Joined
Aug 23, 2014
Messages
143
Programming Experience
Beginner
datavisualization charting 4.0
I'd like to build in an option for the end user to be able to select line colors of their choice. Is there something out there regarding that?

I did find this Manipulating the Chart Appearance

Visual Basic 2010 doesn't like this code. I looked in references for dlgChart in case that was the issue. Didn't find it or anything like it. I suspect the problem is my chart is a datavisualization chart and this references MSChart. I did fiddle with the code a bit but no luck.

VB.NET:
Private Sub MSChart1_SeriesActivated(ByVal Series As _
   Integer, ByVal MouseFlags As Integer, ByVal Cancel As Integer)
        ' The CommonDialog control is named dlgChart.
        Dim red, green, blue As Integer
        With dlgChart ' CommonDialog object
            .ShowColor()
            red = RedFromRGB(.Color)
            green = GreenFromRGB(.Color)
            blue = BlueFromRGB(.Color)
        End With


        ' NOTE: Only the 2D and 3D line charts use the
        ' Pen object. All other types use the Brush.


        If MSChart1.chartType <> VtChChartType2dLine Or _
        MSChart1.chartType <> VtChChartType3dLine Then
            MSChart1.Plot.SeriesCollection(Series). _
               DataPoints(-1).Brush.FillColor. _
               Set(red, green, blue)
        Else
            MSChart1.Plot.SeriesCollection(Series).Pen. _
               VtColor.Set(red, green, blue)
        End If
    End Sub
 
Chart.PaletteCustomColors Property said:
This property has no effect when the Palette property is not set to

None.
a) no.
b) accordingly Palette must be set to value None.
c) yes (* code sample), and yes (when Palette=None).
Me.Chart1.PaletteCustomColors = {Color.Red, Color.Blue, Color.Black}
 
a) no.
b) accordingly Palette must be set to value None.
c) yes (* code sample), and yes (when Palette=None).
Me.Chart1.PaletteCustomColors = {Color.Red, Color.Blue, Color.Black}


Worked like a charm :cocksure:

2 questions

a] is there a way to change NONE to DEFAULT in combobox list.... it would be more intuitive for the end user.

b] To change the chartarea color, what is the correct choice in Settings / Type? I get the message system.drawing cannot be converted to datavisualization.charting.chartarea when I go that route & If I dril down through the browse in Settings / Type to specifically select datavisualization.charting.chartarea.....there's no option to select in the Value cell of the grid?

I'm good with setting up the combobox and binding..... I have your sample code to follow & the combobox populates just fine...
 
a) Yes, one way is to use String values in combobox instead of ChartColorPalette values, but simpler is to handle ComboBox.Format event and conditionally change display value for None value, for example:
If CType(e.Value, ChartColorPalette) = ChartColorPalette.None Then e.Value = "Default"

b) If you mean binding a control property to a setting, then no, ChartArea is not a control. Moreover, "chartarea color" is not a property of Chart control. You have to assign the setting value by code.
 
Back
Top