Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tchart multibar := mbstacked

Status
Not open for further replies.

Tracey

Programmer
Oct 16, 2000
690
NZ
Is there anyone out there who is a dynamic charting guru?

I am trying to create a chart which shows 3 values per Y axis value. ie, i would like to show one chart for each vehicle, showing labour, parts and outwork for each mechanical system on that vehicle.

I have my values stacking, however i just cant seem to comprehend how to set the Y axis to each system.

I have 3 horizontal bar series into which i load the 3 values. How do i set the chart to show these 3 values for each system?

Code:
                            HorizBarSeries := THorizBarSeries.Create(FChart);
                            BarParts := THorizBarSeries.Create(FChart);
                            BarLabour := THorizBarSeries.Create(FChart);

                            HorizBarSeries.BarStyle := bsRectGradient;
                            BarParts.BarStyle := bsRectangle;
                            BarLabour.BarStyle := bsRectangle;

                            HorizBarSeries.ParentChart := FChart;
                            BarParts.ParentChart := FChart;
                            BarLabour.ParentChart := FChart;

                            HorizBarSeries.ShowInLegend := False;
                            BarParts.ShowInLegend := false;
                            BarLabour.ShowInLegend := false;

                            HorizBarSeries.Marks.Style := smsLabelValue;
                            BarParts.Marks.Style := smsLabelValue;
                            BarLabour.Marks.Style := smsLabelValue;

                            HorizBarSeries.MultiBar := mbStacked;
                            BarParts.MultiBar := mbStacked;
                            BarLabour.MultiBar := mbStacked;

                            Randomize;
                            with FChart do
                            begin
                                SeriesList.Clear;
                                HorizBarSeries.Add(fOutWork, 'OutWork',
                                    Random(2147483648));
                                BarParts.Add(fParts, 'Parts',
                                    Random(2147483648));
                                BarLabour.Add(fLabour, 'Labour',
                                    Random(2147483648));

                                SeriesList.Add(HorizBarSeries);
                                SeriesList.Add(BarParts);
                                SeriesList.Add(BarLabour);
                                with Title do
                                begin
                                    Font.Size := 10;
                                    Font.Color := clBlack;
                                    Text.Clear;
                                    Text.Add('Costs for ' + sRef);
                                end;
                            end;
                            { Generate the Chart as a Bitmap }
                            Bitmap := FChart.TeeCreateBitmap(clWhite, Rect);
                            FJPEG.Assign(Bitmap);
                            //GOT TO SAVE EACH CHART AS A SEPERATE FILE OR THEY WILL ALL BE THE SAME
                            FJPEG.SaveToFile('c:\apache\icons\breakdownchart'
                                + IntToStr(iThisSystem) + '.jpg');
 
Tracey,

I had a play with your code and I don't know how you're storing your OutWork, Labour, Parts values for each system. However, I created 3 arrays of double (fOutWork, fParts, fLabour) and where you have the HorizBarSeries.Add, BarParts.Add and BarLabour.Add I have run a loop to populate the chart with my array values. Basically what you're code does at the moment is to add one system's values. You need to run these add lines multiple times, once for each system. Here's an example:
Code:
var
  HorizBarSeries, BarParts, BarLabour: THorizBarSeries;
  fOutWork, fParts, fLabour: Array[1..4] of Double;
  systemCounter: Integer;
begin
  for systemCounter := 1 to 4 do
  begin
    fOutWork[systemCounter] := systemCounter;
    fParts[systemCounter] := systemCounter * 2;
    fLabour[systemCounter] := systemCounter * 4;
  end;
  ...
  with FChart do
  begin
    SeriesList.Clear;
    for systemCounter := Low(fOutWork) to High(fOutWork) do
    begin
      HorizBarSeries.Add(fOutWork[systemCounter], 'OutWork',
                                      Random(2147483648));
      BarParts.Add(fParts[systemCounter], 'Parts',
                                      Random(2147483648));
      BarLabour.Add(fLabour[systemCounter], 'Labour',
                                      Random(2147483648));
    end;
  ...
I hope this helps!

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
oh, let me start again

so far i have my chart working with stacked values for each system

But, the left axis labels show the first series value label, when i want it to display the "system"

According to the help files, the only way to do this is by using the OnGetAxisLabel event like so:

Code:
procedure GetAxisLabel(Sender: TChartAxis;
        Series: TChartSeries; ValueIndex: Integer; var LabelText: string);
    begin
        if Sender = FChart.LeftAxis then
            if ValueIndex < 1 then
                LabelText := ''
            else
            LabelText := IBQuery1.FieldByName('system').AsString;
    end;

but since i am developing in isapi/cgi, i have no events to set the axis labels within.

Does anyone know an alternative?

Stretch... i am feeding the values within a while not eof loop

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top