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

Message ListMessage List     Post MessagePost Message

  print realtime chart
Posted by isan on Aug-05-2019 01:26
I want to print chart instead of save it
I know In qt program can use this
QPrinter printer;

        QPrintDialog dialog(&printer, this);
        dialog.setWindowTitle(tr("Print Document"));
        if (editor->textCursor().hasSelection())
            dialog.addEnabledOption(QAbstractPrintDialog::PrintSelection);
        if (dialog.exec() != QDialog::Accepted) {
            return;
        }

But how can print chart as picture?

  Re: print realtime chart
Posted by Peter Kwan on Aug-05-2019 14:18
Hi isan,

You can print the chart just like printing any image. The following is an example:

    QPrinter printer;
    QPrintDialog dlg(&printer, 0);
    if (dlg.exec() == QDialog::Accepted) {

        // Output chart as QImage
        QImage image;
        MemBlock m = c->makeChart(Chart::PNG);
        image.loadFromData((uchar *)m.data, (uint)m.len);

        // Print the image
        QPainter painter(&printer);
        painter.drawImage(QPoint(0,0),image);
        painter.end();
    }

Hope this can help.

Regards
Peter Kwan

  Re: print realtime chart
Posted by isan on Aug-06-2019 00:53
c must be defined by BaseChart * c; ?
I define it as BaseChart and when I click on the print button the program stops and closes

  Re: print realtime chart
Posted by Peter Kwan on Aug-06-2019 12:29
Hi isan,

I think you cannot use "BaseChart c" for anything. BaseChart is just a base class for the chart objects (XYChart, PieChart, etc) for factoring out the code that is common among the charts. You can use XYChart or PieChart, etc., if you like. For example:


    // Create a XYChart object of size 250 x 250 pixels
    XYChart c(250, 250);

    // Set the plotarea at (30, 20) and of size 200 x 200 pixels
    c.setPlotArea(30, 20, 200, 200);

    // Add a bar chart layer using the given data
    c.addBarLayer(DoubleArray(data, (int)sizeof(data)/sizeof(*data)));

    // Set the labels on the x axis.
    c.xAxis()->setLabels(StringArray(labels, (int)sizeof(labels)/sizeof(*labels)));

    QPrinter printer;
    QPrintDialog dlg(&printer, 0);
    if (dlg.exec() == QDialog::Accepted) {

        // Output chart as QImage
        QImage image;
        MemBlock m = c.makeChart(Chart::PNG);
        image.loadFromData((uchar *)m.data, (uint)m.len);

        // Print the image
        QPainter painter(&printer);
        painter.drawImage(QPoint(0,0),image);
        painter.end();
    }

Regards
Peter Kwan

  Re: print realtime chart
Posted by isan on Aug-06-2019 23:36
So for example in RealTimeMultiThread project can I get object from the chart and print it ?


BaseChart *c = m_ChartViewer->getChart();

    QPrinter printer;

        QPrintDialog dlg(&printer, 0);
        if (dlg.exec() == QDialog::Accepted) {

            // Output chart as QImage
            QImage image;
            MemBlock m = c1->makeChart(Chart::PNG);
            image.loadFromData((uchar *)m.data, (uint)m.len);

            // Print the image
            QPainter painter(&printer);
            painter.drawImage(QPoint(0,0),image);
            painter.end();
        }

  Re: print realtime chart
Posted by isan on Aug-07-2019 00:49
I'm sorry for my questions, I'm confused
Why create an XY chart while the chart is being drawn?
I don't know what the data and labels in this row are and how they can be defined

// Add a bar chart layer using the given data
    c.addBarLayer(DoubleArray(data, (int)sizeof(data)/sizeof(*data)));

    // Set the labels on the x axis.
    c.xAxis()->setLabels(StringArray(labels, (int)sizeof(labels)/sizeof(*labels)));



The data for the chart in this function is received and buffered, right?

void RealTimeMultiThread::OnData(void *self, double elapsedTime, double series0, double series1)
{
    // Copy the data into a structure and store it in the queue.
    DataPacket packet;
    packet.elapsedTime = elapsedTime;
    packet.series0 = series0;
    packet.series1 = series1;

    ((RealTimeMultiThread *)self)->buffer.put(packet);
}

  Re: print realtime chart
Posted by Peter Kwan on Aug-08-2019 00:18
Hi isan,

My understanding of your earlier question is that you try to use "BaseChart", not "BaseChart *". If this is the case, it is not possible to refer to another chart, so you need to create a chart. In your latest code, you seem to be using "BaseChart *". In this case, you can refer to the existing "BaseChart *" in QChartViewer.

Regards
Peter Kwan

  Re: print realtime chart
Posted by Peter Kwan on Aug-08-2019 00:05
Hi isan,

Yes. However, I think your code has some issue. You get the chart, then pop up the print dialog. As the chart is constantly being updated, by the time the user responds to the print dialog, the previous chart has already been destroyed. So it may cause issue. You should get the chart after user has responded to the dialog, then print it.

In the RealTimeMultiThread sample code, there is a "Save" button. You can look at our code. We pop-up the file dialog first. We get the chart only after the user responds to the dialog. It is the same for printing.

Regards
Peter Kwan


cix porn hard porn kostenlose porn amateur xxx love porn amateur sex hd porn free 3 xxx moblie porn