Ticket Q533309
Visible to All Users

New Colors for Bars in ChartControl are not same as in legend

created 11 years ago

Hi,
i currently set custom colors to my BarSeries:

C#
series[i].View.Color = newColor;

Every bar is painted using two colors due to gradient painting-style of the bars. But i can only change the primary color, resulting to wrong gradient painting. I expected a possibility to recalculate the second color or to simply set the second color to a self defined one. But unfortunately i did not figure out an easy way.

C#
series[i].View.Color2 = newColor;

Please see the rightmost bar in the attached screenshot. It seems that a second color for gradient style is used from the original color before changed to the custom color. To correct this, i use the CustomDrawSeriesPoint event to manipulate the Color2:

C#
private void chartControl1_CustomDrawSeriesPoint(object sender, CustomDrawSeriesPointEventArgs e) { BarDrawOptions drawOptions = e.SeriesDrawOptions as BarDrawOptions; if (drawOptions == null) return; // Get the fill options for the series point. drawOptions.FillStyle.FillMode = FillMode.Gradient; RectangleGradientFillOptions options = drawOptions.FillStyle.Options as RectangleGradientFillOptions; if (options == null) { return; } Color color2 = drawOptions.Color; byte R = (byte)((float)color2.R / 1.5f); byte G = (byte)((float)color2.G / 1.5f); byte B = (byte)((float)color2.B / 1.5f); options.Color2 = Color.FromArgb(R, G, B); }

After that, i get nice bars, but there is one problem left. The legend is still showing wrong colors like before using the event. Can anybody help? Best regards from Germany,
Timo
PS: Why is it so sophisticated to simply change some colors?

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hi Timo,
That's right, it is necessary to configure the second gradient color when a custom color is assigned to the Series.View.Color property and the gradient fill mode is enabled. You can assign the primary color value within the same CustomDrawSeriesPoint event handler. It is unclear how to reproduce the Legend color issue (see a screenshot: Issue Q533309). If possible, provide your sample project for further examination. We will be glad to help you.

    Other Answers

    created 11 years ago (modified 11 years ago)

    Thanks for your prompt reply. :) Please see the attached file. The colors of the bars are not correct. If you uncomment the method chartControl2_CustomDrawSeries, the colors of the bars will be correct, but unfortunately not the legend. I did not figure out how to access the colors of the legend.
    But actually, imho setting the series.view.color should be the only thing to do to change the color of the bars.

      Show previous comments (5)
      DevExpress Support Team 11 years ago

        Thank you for your clarification, Timo. I believe you can include the Color2 property assignment into the same procedure where the Series.View.Color property is modified. Let me know if you need further assistance. I will be glad to help you.

          Hi Alex, thats exactly the point that is unintelligible for me. This is not possible, the property Series.View.Color2 does simply not exist. ;)

          DevExpress Support Team 11 years ago

            Timo,
            Please review the sample code snippet below:

            C#
            BarSeriesView view = (BarSeriesView)this.chartControl1.Series[0].View; view.Color = myColor1; view.FillStyle.FillMode = FillMode.Gradient; RectangleGradientFillOptions opts = (RectangleGradientFillOptions)view.FillStyle.Options; opts.Color2 = myColor2;

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.