#include "dpBarsChart.h" #include "dataManager.h" dpBarsChart::dpBarsChart(QWidget* parent) :dpBaseChart(parent) { setAttribute(Qt::WA_TranslucentBackground,true); m_pCustomPlot = new QCustomPlot(this); initQCP(); m_barsGroup = new QCPBarsGroup(m_pCustomPlot); QBoxLayout* mainLayout = new QBoxLayout(QBoxLayout::LeftToRight); mainLayout->setContentsMargins(0, 1, 0, 0); mainLayout->addWidget(m_pCustomPlot); setLayout(mainLayout); connect(DataManager::instance(), &DataManager::dataUpdated, this, &dpBarsChart::onSignal_dataUpdated); } dpBarsChart::~dpBarsChart() { } void dpBarsChart::initQCP() { m_chartStyle.bgColor = Qt::transparent; m_chartStyle.axisColor = QColor(87, 100, 120); m_chartStyle.labelColor = QColor(250, 250, 250); m_chartStyle.labelFont = QFont("黑体", 12); m_chartStyle.tickColor = QColor(87, 100, 120); m_chartStyle.tickLabelColor = QColor(250, 250, 250); m_chartStyle.tickLabelFont = QFont("黑体", 12); m_chartStyle.gridPen = QPen(QColor(87, 100, 120), 1, Qt::DotLine); m_pCustomPlot->setInteractions(QCP::iNone); /*m_pCustomPlot->axisRect()->setRangeDrag(Qt::Horizontal); //只允许x轴方向的拖拽 double zoomFactor = m_pCustomPlot->axisRect()->rangeZoomFactor(Qt::Horizontal); m_pCustomPlot->axisRect()->setRangeZoomFactor(zoomFactor, 1); //只做x轴的缩放*/ m_pCustomPlot->xAxis->setTicks(false); m_pCustomPlot->xAxis->setSubTicks(false); m_pCustomPlot->yAxis->setTicks(false); m_pCustomPlot->yAxis->setSubTicks(false); //m_pCustomPlot->yAxis->setVisible(false); //m_pCustomPlot->yAxis2->setTicks(false); m_pCustomPlot->yAxis2->setSubTicks(false); m_pCustomPlot->yAxis2->setVisible(false); //背景颜色 m_pCustomPlot->setBackground(QBrush(m_chartStyle.bgColor)); //坐标轴颜色 m_pCustomPlot->xAxis->setBasePen(m_chartStyle.axisColor); m_pCustomPlot->xAxis2->setBasePen(m_chartStyle.axisColor); m_pCustomPlot->yAxis->setBasePen(m_chartStyle.axisColor); m_pCustomPlot->yAxis2->setBasePen(m_chartStyle.axisColor); //坐标刻度颜色 m_pCustomPlot->xAxis->setTickPen(QPen(m_chartStyle.tickColor)); m_pCustomPlot->yAxis->setTickPen(QPen(m_chartStyle.tickColor)); m_pCustomPlot->yAxis2->setTickPen(QPen(m_chartStyle.tickColor)); //坐标刻度Label颜色 m_pCustomPlot->xAxis->setTickLabels(false); m_pCustomPlot->xAxis->setTickLabelColor(m_chartStyle.tickLabelColor); m_pCustomPlot->xAxis->setTickLabelFont(m_chartStyle.tickLabelFont); m_pCustomPlot->yAxis->setTickLabels(false); m_pCustomPlot->yAxis->setTickLabelColor(m_chartStyle.tickLabelColor); m_pCustomPlot->yAxis->setTickLabelFont(m_chartStyle.tickLabelFont); m_pCustomPlot->yAxis2->setTickLabelColor(m_chartStyle.tickLabelColor); m_pCustomPlot->yAxis2->setTickLabelFont(m_chartStyle.tickLabelFont); //网格线颜色 m_pCustomPlot->xAxis->grid()->setVisible(false); m_pCustomPlot->xAxis->grid()->setPen(m_chartStyle.gridPen); m_pCustomPlot->xAxis->grid()->setZeroLinePen(m_chartStyle.gridPen); //m_pCustomPlot->xAxis2->grid()->setPen(m_chartStyle.gridPen); m_pCustomPlot->yAxis->grid()->setVisible(false); m_pCustomPlot->yAxis->grid()->setPen(m_chartStyle.gridPen); m_pCustomPlot->yAxis->grid()->setZeroLinePen(m_chartStyle.gridPen); m_pCustomPlot->yAxis2->grid()->setPen(m_chartStyle.gridPen); //Legend m_pCustomPlot->legend->setBrush(QBrush(QColor(255,255,255,12))); //背景透明 m_pCustomPlot->legend->setBorderPen(QPen(QColor(255,255,255,0))); //边框透明 m_pCustomPlot->legend->setFont(m_chartStyle.labelFont); m_pCustomPlot->legend->setTextColor( m_chartStyle.labelColor); } void dpBarsChart::setTimeRange(TimeUnit unit) {} void dpBarsChart::setDateTime(const QDateTime& dateTime) {} void dpBarsChart::viewHistoricalData(const QDateTime& dateTime) {} void dpBarsChart::synchronizeConfigData(const configurationResults& cfg) {} void dpBarsChart::onSignal_dataUpdated(const QString& dataKey, const QVariant& data, const QDateTime& timestamp) {}