Chart Bar Color

pinbotpinbot Texas
edited 7:49PM in FastReport .NET

I'm trying to set the Color in a Chart Object.

What is the correct field type? I've tried varchar and setting it to "clblue" (like I used to do with FR Studio) as well as int and setting the field value to 0xC0C0C0.

Each time I get an exception "Specified cast is not valid"

Also, Can I use this to color each bar in the series? I have 1 series but would like to color each bar a separate color.

Comments

  • pinbotpinbot Texas
    edited 7:49PM

    Also,

    What is the correct "Using" statement to access/cast an MSChartObject in script?
  • pinbotpinbot Texas
    edited 7:49PM
    Ok Last question,

    :-)

    And this may be a chart question outside the scope of this forum.

    How come when I select the "excel" palette, it colors each bar in the series (bottom chart) but when I create my own palette (with 16 colors), and select "none" as the series palette, it only displays the first color (top chart)?

  • edited September 2009
    wrote:
    What is the correct field type?
    You have to convert your field content to System.Drawing.Color type. For example, if your field contains color names such as "Blue", "Red", "Gainsboro" (standard color names), you may use the following code:
    new ColorConverter().ConvertFromInvariantString(your_string_value)
    

    it will color each value in a series.

    wrote:
    What is the correct "Using" statement to access/cast an MSChartObject in script?
    using System.Windows.Forms.DataVisualization.Charting;

    you also need to add the System.Windows.Forms.DataVisualization.dll to your report assembly references.
  • edited 7:49PM
    wrote:
    How come when I select the "excel" palette, it colors each bar in the series (bottom chart) but when I create my own palette (with 16 colors), and select "none" as the series palette, it only displays the first color (top chart)?
    You set your custom palette to Chart.PaletteCustomColors, right? This palette is for different series, it does not color each value in a series.
  • pinbotpinbot Texas
    edited 7:49PM

    That's what the documentation says.

    But if I select ANY other built-in palette, it DOES color each data point in the series. (see the second graph which is from the same data set). Both graphs only have 1 series. The 1st one I set the palette to "none" and the second one to "excel"

    How can I acccess the chart in script to set the colors for the datapoints? (using <what>)

    Bryan

  • pinbotpinbot Texas
    edited 7:49PM

    You can see this behaviour in FR DEMO.

    1. Edit the Microsoft Chart Sample.
    2. On the Revenue chart, the default is that all the data points are the same color.
    3. Double click on the revenue chart. Select Series1.
    4. Select the Fills&Border tab and change the palette from "None" to "Excel"
    5. You will see that each data point in the same series has a different color.

    This does not work for the CustomPalette.






  • pinbotpinbot Texas
    edited 7:49PM

    Success!!!!

    You're code for converting the data color from the data field did the trick.

    I put this as the expression for the series color:

    new ColorConverter().ConvertFromInvariantString([SOP.BarColor])

    All I really wanted was the first color to be special. It is the color of the customer's logo. Go Figure.

    In the data set, I'm only setting the color of the first record in the dataset to be the color shown. I leave the rest of the color values NULL.

    For the first bar it uses the color I pass, for the rest it uses the colors from the Excel palette and colors each data point.

    Could not be better!




  • edited 7:49PM
    wrote:
    1. Edit the Microsoft Chart Sample.
    2. On the Revenue chart, the default is that all the data points are the same color.
    3. Double click on the revenue chart. Select Series1.
    4. Select the Fills&Border tab and change the palette from "None" to "Excel"
    5. You will see that each data point in the same series has a different color.

    This does not work for the CustomPalette.

    There are two palettes in MS Chart: one is for series (Chart.Palette and Chart.PaletteCustomColors), second is for values (Chart.Series.Palette). Note that there is no custom palette for values, you need to specify the color for each value manually.
  • pinbotpinbot Texas
    edited 7:49PM

    ok.


    Thanks for the explanation.


    Seems strange that you cannot create a custom palette for values.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.