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

Message ListMessage List     Post MessagePost Message

  ->getChart() but only parts of it
Posted by Medic89 on May-28-2022 23:25
Hello Peter,

for a printout of my chart, I wanna 'divide' my chart to make it fit on two or more pages. Do i have to rebuild the whole chart to archieve this?

  Re: ->getChart() but only parts of it
Posted by Medic89 on May-29-2022 18:33
EDIT: Just like in the Zoom/Scroll with PDF Report (MFC) example.

  Re: ->getChart() but only parts of it
Posted by Peter Kwan on May-30-2022 13:25
Hi Medic89,

You may notice in the Zoom/Scroll with PDF Report (MFC) example, for both on-screen display and the multi-page PDF, the chart is actually drawn by the same function
drawXYChart. However, there must be additional code to decide how to separate the chart into pages (in the sample code, we put 2 charts in one page, and each chart covers 1 year), the page size, margins, chart title (each chart can have a different title showing its year), page number, etc..

So in brief, you do not have to write two separate functions to draw the chart on screen and for print to multiple pages, provided you design your code in the first place to be able to generate separable charts.

Regards
Peter Kwan

  Re: ->getChart() but only parts of it
Posted by Medic89 on May-31-2022 00:01
Hello Peter,

so i checked the createPDFreport code and the charts gets drawn with this code:

int startYear = Chart::getChartYMD(m_timeStamps[0]) / 10000;
int endYear = Chart::getChartYMD(m_timeStamps[m_timeStamps.len - 1] - 1) / 10000;

    for (int yyyy = startYear; yyyy <= endYear; yyyy += 2)
    {
        MultiChart m(760, 920);
        m.addTitle("ChartDirector PDF Report Demonstration", "Arial Bold", 20);
        XYChart* c = drawXYChart(Chart::chartTime(yyyy, 1, 1), Chart::chartTime(yyyy + 1, 1, 1));
        m.addChart((m.getWidth() - c->getWidth()) / 2, 100, c);
        c->addTitle(c->formatValue(yyyy, "Year {value}"));

        XYChart* c2 = 0;
    }

However, I have no idea, how the data comes into the XYChart c, I mean the only input is the year which is just an integer variable. I gues Im missing something.

  Re: ->getChart() but only parts of it
Posted by Peter Kwan on May-31-2022 14:16
Hi Medic89,

In the sample code, the "drawXYChart" function takes two parameters for the starting and ending x-coordinates of the chart.

In the drawXYChart function, it will fetch the data within the x-axis range and plot the chart. In that particular example, the data are stored as member variables of the of the CZoomScrollPdfDlg class.

Best Regards
Peter Kwan

  Re: ->getChart() but only parts of it
Posted by Medic89 on Jun-01-2022 00:05
Hello Peter,

I see, however in my case, my chart gets rebuild every 10 Seconds without the drawChart function, i have the

void markzone2(CChartViewer* viewer, int /* chartIndex */)

function where my chart gets build. is it possible to store the data inside this function into member variables? Maybe into different one, so Data for the first 90 Minutes into variable one, second 90 minutes variable two and so on? What kind of variables would I have to use?

  Re: ->getChart() but only parts of it
Posted by Peter Kwan on Jun-01-2022 15:46
Hi Medic89,

When your code creates the chart, it must obtain the data. After obtaining the data, your code can always save the data somewhere, or to some member variables. For example, you can structure your code like:


void markzone2(CChartViewer* viewer, int /* chartIndex */)
{
     getDataAndStoreInMemberVariables();

     // If you want to plot all the data, you can set startX and endX to the full x-range of
     // your data
     delete viewer->getChart();
     viewer->setChart(drawChart(startX, endX));
}

The drawChart above contains your charting code. Instead of directly putting the chart in the CChartViewer, it returns the chart. It is because drawChart is used for both display (which uses the CChartViewer), and for print (which does not use the CChartViewer). So it is up to the caller to put the returned chart into the CChartViewer.

The drawChart function should be designed to obtain its data from the member variables, and only plot the part that is between startX and endX.

When you want to print the chart, you can use a loop to call drawChart multiple times with each chart covering a different x-axis range. You can then create a multi-page PDF, or "print" the charts one by one.

Regards
Peter Kwan