ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  How to get text dump of a graph with several lines?
Posted by John Vella on Apr-07-2024 06:02
For QA to create regression tests of my chart functionality, I need to generate a textual representation of what the chart contains. The chart has a LineLayer that I create "lines" with by calling addDataSet on the layer. Each line's dataset will have a unique name, so this name is what should be dumped as the line's X/Y values. So something like this:

LINE: fred
X=0, Y=10
X=5, Y=23
X=10, Y=54
LINE: gomer
X=0, Y=100
X=8, Y=253
X=10, Y=300
X=15, Y=350

Is there a technique for getting this done? I'm using C++.

Thanks for any help you can offer.

-John

  Re: How to get text dump of a graph with several lines?
Posted by Peter Kwan on Apr-08-2024 15:17
Hi John,

The data set name can be obtained using DataSet::getDataName. You can use Layer::getXPosition to get the x value, and DataSet::getValue to get the y value.

https://www.advsofteng.com/doc/cdcpp.htm#Layer.getXPosition.htm
https://www.advsofteng.com/doc/cdcpp.htm#DataSet.getDataName.htm
https://www.advsofteng.com/doc/cdcpp.htm#DataSet.getValue.htm

We use these methods in the sample code to draw track cursors, such as:

https://www.advsofteng.com/doc/cdcpp.htm#tracklegend.htm
https://www.advsofteng.com/doc/cdcpp.htm#tracklabel.htm

Best Regards
Peter Kwan

  Re: How to get text dump of a graph with several lines?
Posted by John Vella on Apr-08-2024 21:36
I'm not sure Layer.getXPosition will work as I have a single layer that has multiple datasets added to it. So imagine a chart with two XY lines added (called A and B). My need is to dump the X and Y values for each data point within A and B.

What would the pseudo code for doing that look like?

Thanks for the help (which as usual is wonderfully prompt!!)

-John

  Re: How to get text dump of a graph with several lines?
Posted by John Vella on Apr-08-2024 21:37
I'm not sure Layer.getXPosition will work as I have a single layer that has multiple datasets added to it. So imagine a chart with two XY lines added (called A and B). My need is to dump the X and Y values for each data point within A and B.

What would the pseudo code for doing that look like?

Thanks for the help (which as usual is wonderfully prompt!!)

-John

  Re: How to get text dump of a graph with several lines?
Posted by Peter Kwan on Apr-09-2024 02:46
Hi John,

Each layer can only have one series of x coordinates. If it contains two lines, then the two lines must share the same x coordinates.

The following code iterates all the layers in a chart. For each layer, it iterates all the data sets in that layer. For each data set, it iterates all data points in the set.


for (int i = 0; i < c->getLayerCount(); ++i) {
    Layer* layer = c->getLayerByZ(i);

    // Iterate through all the data sets in the layer
    for (int j = 0; j < layer->getDataSetCount(); ++j)
    {
        DataSet* dataSet = layer->getDataSetByZ(j);
        const char* dataSetName = dataSet->getDataName();
        TRACE("DataSetName = %sn", dataSetName);

        // Get the color, name and position of the data label
        int color = dataSet->getDataColor();
        TRACE("DataSetColor = #%08Xn", color);

        for (int i = 0;; ++i)
        {
            double xPos = layer->getXPosition(i);
            if ((xPos == Chart::NoValue) || (xPos > c->xAxis()->getMaxValue()))
                break;
            TRACE("x=%f, y=%fn", xPos, dataSet->getValue(i));
        }
    }
}


Best Regards
Peter Kwan