How to display X Y data as a graph?

hsmhsm
edited 4:09AM in FastReport 4.0
0 down vote favorite


I'm using Delphi and Fast reports, specifically the Chart object inside Fast Reports. I'm trying to plot a scatter graph (preferably with a line between the points).
Four points of typical X,Y data might look like this (held in two fields of the data set).
X  Y
   10  35
   15  40
   23  44
   27   8

I've set the X axis automatic to false and set a min of 0 and a max of 30.

However, when the chart plots the points it plots the Y values at the correct height but puts them in X positions 0, 1, 2, 3 instead of 10, 15, 23, 27

This even happens when I hard code the data by setting 'Data Source' to 'Fixed Data' and putting 35;40;44;8 in the Y values box and 10;15;23;27 in the X values box.

How do I set up the chart to plot the points at the correct X-Y coordinates?

Comments

  • hsmhsm
    edited 4:09AM
    Eventually I can post my own reply.
    In the graph editor the series type needs to be set to number, not text. that makes any x values supplied be proper x values and they will be used when plotting the points.

    Then in the code part of the report you can use lines like this (where 3 is the order of the series counting from zero in the designer)

    Chart2.SeriesData[3].XSource := '2;5;8';
    Chart2.SeriesData[3].YSource := '34;56;78';


    The properties of the series, line width, colour, marks etc seem to be best set in the design editor as not all properties are exposed by fats reports and when trying to do it directly in Delphi there is little documentation on how to cast the different chart obnjects from a Fast reports object to a Tee chart one.

    I have found these lines work in the code section of the report though

    ChartName.Chart.BottomAxis.Automatic := false;
    ChartName.Chart.BottomAxis.Maximum := X_AXIS_MAX; //constants
    ChartName.Chart.BottomAxis.Minimum := X_AXIS_MIN;
    ChartName.SeriesData[3].DataType := dtFixedData; //allows you to give values directly instead of via a database
    ChartName.SeriesData[3].Xtype := 1;
    For the Xtype value you don't seem to be able to use the built in TeeChart constants xtNumber etc. but you can use their numeric values directly.
    These are:
    0 = assume X values are labels, plot in position 0,1,2,3 etc;
    1 = numeric, plot at the X position given;
    2 = X values interpreted as dates


    Note when putting the graph in a data band connected to a data set and generating the data through code at run time from a hidden band above it, I found it necessry to have a dummy series as the first one that took its data from the dataset (with the others saying direct data). The hidden series doesn't need to even have any X or Y data selected. But doing this correctly gives one graph for evey item in the data band. If you don't do it then the results are nasty!

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.