One, foreword

Data transfer curve, the use of very much, such as a serial port or network receives data, for a particular byte data real time curve, or to curve drawing, history records the data stored in accordance with the contract rules, data transfer curve drawing must provide the rules, no rules only for all data, so must be very ugly, To get their data is generally under a machine with the frame head frame check code, need to eliminate irrelevant data, generally need to specify which byte or which belongs to the need to draw the curve of the data, if it is a multiple data, may also need to merge, such as 2 bytes merged into an unsigned ushort data, 4 bytes merged into a uint data, The rules for merge conversions, as well as the distinction between high and low byte positions, some high byte first and some high byte after, must be reflected in the specification, otherwise the curve is likely to be drawn incorrectly.

Open source QCustomPlot curve chart controls, support the amount of data that are high, to the level of millions, tens of hundreds of thousands of one-off drawing of data can also, drawing the has been optimized to perfection, the speed of the main takes up should be calculated, map is soon, large amount of data is generally not recommended frequent drawing, Any development tool or language, the UI is in the main thread, so drawing this area too often is likely to cause the main thread, if the amount of data is really large, you can move the calculation area to another thread, and draw once after the calculation is done. For drawing large amount of data, and an algorithm is to filter out the average data, because a pixel rendering tens of hundreds of data points is meaningless, all huddled in a block, the human eye to watch is a problem, so use algorithm to these data points after a rule operation merged into one point data, can reduce the amount of data is very large, Wait until the scaling time to automatically restore the previous data.

Two, functional characteristics

  1. The use of hierarchical design, the overall total is divided into three levels of interface, level 1 interface is the overall layout, level 2 interface is a single function module, level 3 interface is a single control.
  2. Sub-controls include pie chart, ring chart, curve chart, bar chart, bar group chart, horizontal bar chart, horizontal bar group chart, pass rate control, percentage control, progress control, equipment status panel, table data, map control, video control and so on.
  3. The secondary interface can be dragged to float freely, support to minimize hide, maximize close, response to double click custom title bar.
  4. Data sources support analog data (default), database collection, serial port communication (to be customized), network communication (to be customized), and network requests. You can freely set the collection interval of each sub-interface, namely the data refresh frequency.
  5. Written in pure QWidget, pro test Qt4.6 to Qt6.2 any version, theoretically support subsequent other Qt versions.
  6. Super cross-platform, pro test Windows, Linux, MAC, domestic UOS, domestic Galaxy Kirin Kylin and other systems, the effect is perfect, but also support embedded Linux such as raspberry pie, orange pie, Full zhi, IMX6 and so on.
  7. At the same time, the integration of custom control, Qchart pie chart, Echart map and other functions.
  8. Built-in multiple color matching styles (purple, blue, dark blue, black), default purple, adaptive arbitrary resolution.
  9. You can set the system title, target resolution, layout scheme, start immediate application.
  10. You can set the main background color, panel color, crosshair cursor color and other colors.
  11. Multiple curves with different colors can be set. In case of no color setting, multiple sets of exquisite colors are built in for random application.
  12. You can set the background color and text color of the title bar.
  13. You can set curve chart background color, text color, grid color.
  14. You can set normal color, alert color, alarm color, Disable color, percentage progress color.
  15. You can set different font sizes, such as global font, software name, title bar, subtitle bar, bold label, etc.
  16. You can set the title bar height, table header height, line height.
  17. Curves support cursors, positioning lines, hover highlighting data points, hover display values.
  18. Bar chart support top (top, upper, middle, bottom) display data, all adaptive calculation position.
  19. Support smooth curve, built-in a variety of smooth curve algorithm, but also support area graph smoothing.
  20. The area map can be filled with a variety of rules, such as monochrome opacity fill, opacity gradient fill, etc.
  21. Database support SQLite, mysql, PostgresQL, Oracle, domestic renda Jincang and other databases.
  22. Main interface directly right mouse button switch layout, color scheme, close open a level 2 form.
  23. Automatic memory of all sub-window size and position, the next startup immediately applied.
  24. Dynamic loading layout menu, you can dynamically create a new layout, restore layout, save layout, save layout, etc., the user can create any layout.
  25. Secondary form, double – click from the main form to separate float, you can freely adjust the size. Double click the title bar again to maximize, double click restore again.
  26. The sub-module can also be displayed in full screen as a large screen, so that a large screen can be extended to multiple large screens, and the data details of the sub-module can be zoomed in, which is suitable for multi-screen display.
  27. Each module can customize the collection speed, if the database collection will automatically queue processing, later can also expand each sub-module independent database collection.
  28. Provide system setting module for the overall configuration parameter setting, the effect of immediate application.
  29. Provide beautiful and cool large screen map module, including static picture, flashing effect, migration effect, world map, regional map, etc., can specify the longitude and latitude coordinates of points, identify click response, can do map jump, etc., each point can be different color and prompt information.
  30. In addition to providing a large screen system, each module has made an independent module sample interface, each module can be independently learned and used, the controls used in the control sample interface also made separately, easy to learn how to use each control.
  31. Very detailed development and use manual, including database description, module comparison diagram, control comparison diagram, project structure, code description (down to each class), demo, use method, etc.

3. Experience address

  1. Experience address: pan.baidu.com/s/1d7TH_GEY… Extraction code: 01jf File name: bin_bigscreen.zip
  2. Domestic site: gitee.com/feiyangqing…
  3. International site: github.com/feiyangqing…
  4. Profile: blog.csdn.net/feiyangqing…
  5. Zhihu homepage: www.zhihu.com/people/feiy…
  6. Online documentation: feiyangqingyun. Gitee. IO/qwidgetdemo…

Four, effect drawing

Five, core code

#include "frmplotdata.h"
#include "ui_frmplotdata.h"
#include "quihelper.h"

frmPlotData::frmPlotData(QWidget *parent) : QWidget(parent), ui(new Ui::frmPlotData)
{
    ui->setupUi(this);
    this->initForm(a);this->loadPlot(a); } frmPlotData::~frmPlotData()
{
    delete ui;
}

void frmPlotData::initForm(a)
{
    // Add canvas
    ui->customPlot->addGraph(1);
    // Set drag zoom mode
    ui->customPlot->setInteractions(3);
    // Set the margin
    ui->customPlot->setPadding(15);
    // Set the size of the data point
    ui->customPlot->setPointSize(0);
    // Set the text color
    ui->customPlot->setTextColor(Qt::white);
    // Set the XY axis range
    ui->customPlot->setRangeX(0.1000.15);
    ui->customPlot->setRangeY(0.1000.15);

    // Bind double click to reload data
    connect(ui->customPlot->getPlot(), SIGNAL(mouseDoubleClick(QMouseEvent *)), this.SLOT(loadPlot()));
}

void frmPlotData::loadPlot(a)
{
    // Read data from a text file
    QString fileName = QString(":/image/data%1.txt").arg(rand() % 3);
    QFile file(fileName);
    if (file.open(QFile::ReadOnly | QIODevice::Text)) {
        QString value = file.readAll(a); file.close(a); vdouble keys, values; QStringList list = value.split("");
        int len = list.length(a);If it is not a multiple of 2, the length is subtracted by 1
        if (len % 2! =0) {
            len = (len - 1);
        }

        for (int i = 0; i < len / 2; i++) {
            keys.append(i);
        }

        // Every two hexadecimal digits are combined to form a single number
        for (int i = 0; i < len; i = i + 2) {
            qint16 value = CustomPlotHelper::strHexToShort(QString("% 1% 2").arg(list.at(i)).arg(list.at(i + 1)));
            values.append(value);
        }

        LineData data;
        data.index = 0;
        data.name = "Angle value";
        data.key = keys;
        data.value = values;
        // Set the line color, either specified or random
        data.lineColor = CustomPlotHelper::getRandColor(a); data.scatterShape =0;
        data.fillColor = 1;
        data.autoScale = true;
        ui->customPlot->setDataLine(data);
        ui->customPlot->replot();
    }
}
Copy the code