mychartview.h
#ifndef mychartview_h
#define mychartview_h
#include #include #include"qscatterseries"
#include "qpointf"
#include "qlineseries"
#include "qchartview"
#include "qvalueaxis"
#include"qdatetimeaxis.h"
#include"qdebug"
#include"qdatetime.h"
#include"qdialog.h"
#include"common.h"
qt_begin_namespace
class qgraphicsscene;
class qmouseevent;
class qresizeevent;
qt_end_namespace
qt_charts_begin_namespace
class qchart;
qt_charts_end_namespace
class callout;
qt_charts_use_namespace
class mychartview: public qgraphicsview
;#endif
#include "mychartview.h"
#include #include #include #include #include #include #include "callout.h"
#include #include"qdebug"
mychartview::mychartview(chartviewparam *cvp,qwidget *parent)
: qgraphicsview(new qgraphicsscene, parent),
m_coordx(0),
m_coordy(0),
m_chart(0),
m_tooltip(0)
else if(m_linenum==2)
m_chart->addaxis(m_axisx, qt::alignbottom); //並且xy軸的位置是下和左
m_chart->addaxis(m_axisy, qt::alignleft);
//m_chart->legend()->hide();
m_chart->settitle(cvp->m_title);
m_scatseries0->attachaxis(m_axisx);
m_scatseries0->attachaxis(m_axisy);
m_chart->settitlefont(qfont("宋體",12,qfont::bold));
m_scatseries1->attachaxis(m_axisx);
m_scatseries1->attachaxis(m_axisy);
m_series0->attachaxis(m_axisx);
m_series0->attachaxis(m_axisy);
m_series1->attachaxis(m_axisx);
m_series1->attachaxis(m_axisy);
m_series0->setname(cvp->linename[0]);
m_scatseries0->setname(cvp->linename[0]+"點");
if(m_linenum==2)
else
m_chart->legend()->hide();
m_chart->setaccepthoverevents(true);
setrenderhint(qpainter::antialiasing);
scene()->additem(m_chart);
m_coordx = new qgraphics******textitem(m_chart);
//m_coordx->setpos(m_chart->size().width()/2 - 50, m_chart->size().height());
//m_coordx->settext("x1: ");
m_coordy = new qgraphics******textitem(m_chart);
// m_coordy->setpos(m_chart->size().width()/2 + 50, m_chart->size().height());
//m_coordy->settext("y1: ");
connect(m_series0, signal(clicked(qpointf)), this, slot(keepcallout()));
connect(m_series0, signal(hovered(qpointf, bool)), this, slot(tooltip(qpointf,bool)));
connect(m_series1, signal(clicked(qpointf)), this, slot(keepcallout()));
connect(m_series1, signal(hovered(qpointf, bool)), this, slot(tooltip(qpointf,bool)));
this->setmousetracking(true);
m_tooltiptype=0;
}void mychartview::setxformat(qstring str)
bool mychartview::setwarnline()
void mychartview::resizeevent(qresizeevent *event)
qgraphicsview::resizeevent(event);
}void mychartview::mousemoveevent(qmouseevent *event)
void mychartview::keepcallout()
void mychartview::clearchart()
m_series0->clear();
m_scatseries0->clear();
m_series0->points().clear();
m_scatseries0->points().clear();
//qdebug()<<" clear m_series0 points2:"m_tooltip->setzvalue(11);
m_tooltip->updategeometry();
m_tooltip->show();
} else
}
mian.cpp
typedef struct chartviewparam
chartviewparam;
void mainwindow::initchart()
"); m_curpass1->setstylesheet("qgraphicsview");
m_perfomance2->setstylesheet("qgraphicsview");
m_historypass->setstylesheet("qgraphicsview");
m_perfomance1->installeventfilter(this);
m_curpass1->installeventfilter(this);
legendevent(m_curpass1);
legendevent(m_perfomance1);
legendevent(m_perfomance2);
legendevent(m_historypass);
m_perfomance1->m_tooltiptype=1;
}
大體的在這裡了,例項化這個物件後,往你介面布局中新增這個view就可以,qvboxlayout *layout = ui->passchart;
部分東西可以刪除。
QChart重新整理
重新整理的核心 新增新的資料前,使用 chart removeallseries 清除即可,重要操作,qchart重新整理的必要操作qchart建立完整建立過程 第一部分 資料預處理 將相關資料壓入list中,資料型別為qpoint型別 第二部分 新增資料 儲存需要繪製曲線的y值 qlineseri...
QChart教程(一) QChart實現動態曲線
qchart實現了各種各樣的曲線,餅狀圖,柱狀圖等等,綜合了之前的第三方圖表模組qcustomplot,qwt的功能,這兩種也是很好的qt圖表類庫。qchart在5.7之前只有商業版才有,5.7之後社群版也可以使用了。建議使用qt5.7之後的版本,在安裝的時候勾選qcharts模組,不然無法使用該功...
QChart與QCustomPlot簡單運用
qchart的使用 條件 需要在.pro檔案新增qt charts 四個標頭檔案的作用 include 類似於畫筆 include 類似於畫布 include 類 series 是用來新增資料的物件 可以理解為乙個集合 include 用來自定義圖表中的x,y座標軸 定義了五個物件qchartvie...