How to set colors of segments in a pie chart?

hsmhsm
edited December 2012 in FastReport 4.0
I display three values in a pie chart.
They come out colored red, then green , then yellow
I need them to be red, yellow, green (like traffic lights)
How do I alter the order of colors used by the pie chart?

BTW I am showing the chart once for each line in my MasterData band so in my obp event of the Chart I have lines like
SeriesData := FloatToStr( <frxDBDataset1."PercentBelowThreshold"> ) + ';' 
            + FloatToStr( <frxDBDataset1."PercentOnThreshold"> ) + ';' 
            + FloatToStr( <frxDBDataset1."PercentAboveThreshold"> );             

Chart1.SeriesData[0].YSource := SeriesData ;
Howard
PS and where - if anywhere - is all this documented?

Comments

  • hsmhsm
    edited 2:57PM
    mithcd wrote: »
    Not really. That just shows how to make a pie chart (and one with just fixed data at that). It doesn't even mention the colours of each slice.
    I can already make a dynamic pie chart drawing data from a database. I want to set the colours of each slice to my own colours, not have them automatically generated.

    Fortunately, in this instance, I only need the colours red, yellow and green, (to represent data relating to 'below', 'avarage' and 'above').
    Those colours just happen to be the first three automaticly generated colours, although they get generated in the order red then green then yellow.
    So In this case I simply added my pie slice data in a different order ie Below then Above then Average).

    However I may not be so lucky next time as I may have more than three slices that nI need to represent different things.

    So the question still stands.

    How can I set the colour that corresponds to each slice in the pie chart?

    Howard
  • edited 2:57PM
    Howard,

    I haven't (yet!) found a solution how to define PieChart colors at runtime in the way you exactly need it.
    But at the moment I'm working on FR script and charts for myself and in the meantime I've found something close to your needs.

    I've found how to make it at runtime using DataSet as a source of PieChart data.
    Yes I know you receive your data on each band from one query row, but if you don't find any better solution than make a use of my idea.

    And that's how I did it.

    1. In my test drive I have a simple query,
    2. I made a small trick to assign FR colors to rows in that query,
    3. These colors come from an array [clRed,clYellow,clGreen,clRed,clYellow,clGreen,clRed,clYellow,clGreen,clBlue] (I need 10 items for my tests),
    4. And here is what I've got:

    Design time
    Preview
  • edited 2:57PM
    wrote:
    SeriesData := FloatToStr( <frxDBDataset1."PercentBelowThreshold"> ) + ';'
    + FloatToStr( <frxDBDataset1."PercentOnThreshold"> ) + ';'
    + FloatToStr( <frxDBDataset1."PercentAboveThreshold"> );

    Chart1.SeriesData[0].YSource := SeriesData ;
    I've GOT it [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Chart1.SeriesData[0].Source1 := 'First;Second;Third'; Chart1.SeriesData[0].Source2 := '50;35;20';[/img]Chart1.SeriesData[0].Source3 := 'clRed;clYellow;clGreen';

    Regards
    Mick

  • hsmhsm
    edited 2:57PM
    Mick.pl wrote: »
    Mick.pl wrote: »
    SeriesData := FloatToStr( <frxDBDataset1."PercentBelowThreshold"> ) + ';'
    + FloatToStr( <frxDBDataset1."PercentOnThreshold"> ) + ';'
    + FloatToStr( <frxDBDataset1."PercentAboveThreshold"> );

    Chart1.SeriesData[0].YSource := SeriesData ;
    I've GOT it [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Chart1.SeriesData[0].Source1 := 'First;Second;Third'; Chart1.SeriesData[0].Source2 := '50;35;20';[/img]Chart1.SeriesData[0].Source3 := 'clRed;clYellow;clGreen';

    Regards
    Mick

    Well done Mick !

    I had researched TeeChart ( FR uses that as the basis for its chart) and found out that the colours came from an array. However in TeeChart there is a property you can set to define what the array is. I couldn't find any such property in the FR object. With almost no documentation from FR on their chart object it was down to blind guessing - which appears to have paid off for you.


    Now we're back in business!
    Thank you for your time to find this out.

    (Makes you wonder though, what real properties .Source1, 2, 3 correspond to and if there are any more interesting and useful variations of .Source out there that the FR team are keeping a closely guarded secret.)

    Regards
    Howard
  • edited 2:57PM
    wrote:
    ...
    I had researched TeeChart ( FR uses that as the basis for its chart) and found out ...
    ...

    Howard,

    A few years ago we gave up using TeeChart as there was a conflict between it and our own libraries. But I still think of TeeChart as an interesting tool. I would decide to make new tests if I knew we'd be able to control some (many many ?) of TeeChart's objects properties and method from pure (!!!) FastReport script. Example: Chart in FR has a property AllowZoom (and some others similar), but no other to make that zoom (I guess -in preview time). I have found (www.steama.com) information about that posibility like ... ZoomRect(...).

    Do you have any experience in controling TeeChart objects from FastReport script?

    Regards
    Mick
  • hsmhsm
    edited 2:57PM
    Mick.pl wrote: »
    Do you have any experience in controling TeeChart objects from FastReport script?
    Only a little. eg setting the data to display from an array built up as a band is printed but that was the FR derivation, not 'pure' TeeChart.

    There is so little documentation from FR its hard to write anything in code as you cannot easily find out what methods/events are available and even when you do there is no reference anywhere saying what the properties do. (I guess somebody at FR must know but they are not telling us).
    Mostly I spend hours fiddling around compiling and running my applications over and over again trying to get the size of the charts exactly correct and showing the right data in the right way. Would be much easier to set the size and shape in code.

    I did experiment a bit with a test application where I referenced a chart object in Delphi and then tried to see what its properties were doing using debug watches and messageboxes showing the values. I was trying to map the things you can change in the chart editor to properties that I could set in code instead after calculating appropriate values
    Mostly I got AVs !

    Howard
  • edited 2:57PM
    hsm wrote: »
    ...
    Mostly I spend hours fiddling around compiling and running my applications over and over again trying to get the size of the charts exactly correct and showing the right data in the right way. Would be much easier to set the size and shape in code.
    ...

    Thank you Howard,

    I can see we both (or rather hundreds of us) walk the same road :-( But it means lots of lost hours.
    My so called "documentation" is frClass.pas, some other FR sources and that what I can see among objects properties.
    And running reports like in a mad circle (I don't use Delphi itself, I use olny pure FR script with its greenhorn debugger).
    I've found that the best method ever for FR develop process is ... trial and error ;-)

    All of us (including FR Team !) work on and develop (!) such products we can sell with economical success.
    And FR Team must have such products too, and I'm afraid FR4 does NOT belong to them :-(

    Regards
    Mick

  • hsmhsm
    edited 2:57PM
    After much experimentation I have managed to find out some of the datatypes and values needed to control some aspects of the chart through code so will post them here. Maybe this can be the start of a sort of 'People's Documentation'. If anyone finds out any more ways to control the chart then add them here.
    This was for a pie chart (haven't yet found out how to set a series to pie through code)

    I'm also attaching a small delphi 2009 test project in which I am trying to overlay a circle of the same size and shape as the pie chart so that I can get a pie with no internal radial lines but with a circluar boundary (This is because mathematically, a zero angled slice should not have radial lines either side as that implies it has a width)
    You can see that I am unable to get the circle to match the pie exactly, even though the size and position values are the same. It might be something to do with the shaddow property.

    Anyway, here is what I have found out so far

    Howard


    //set position of the TfrxChartView
    Chart1.left := 0;
    Chart1.top := 0;

    //set size of TfrxChartView (in px)
    Chart1.width := 200;
    Chart1.height:=200;

    //set internal margins of pie series itself so that it fits exactly inside the TfrxChartView selection rectangle box
    Chart1.Chart.MarginTop := 0;
    Chart1.Chart.MarginBottom := 0;
    Chart1.Chart.MarginLeft := 0;
    Chart1.Chart.MarginRight := 0;

    //turn off 3D and don't show a legend
    Chart1.chart.View3D := false;
    Chart1.Chart.legend.visible := false;

    //Make pie circular
    TPieSeries(Chart1.Series[0]).circled := true;

    //don't show data values
    TPieSeries(Chart1.Series[0]).marks.visible := false;

    //don't show radial lines (unfortunately gets rid of the circle around the outside as well )
    TPieSeries(Chart1.Series[0]).piepen.visible := false;

    //Simulate getting data from a database. 3 bits of data, two of which just happen to be zero at the moment
    //the pie chart should NOT therefore have any radial lines between the slices as there
    //should only be one slice. It should however have a circular boundary

    Chart1.SeriesData[0].YSource := '100;0;0';

    //set the colours of each slice and the order in which we want them to appear, corresponding to the line above
    Chart1.SeriesData[0].Source3 := 'clRed; clBlue; clYellow';

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.