#include “mainwindow.h”
#include “error.h”
#include
#include
#include
#include
#include
#include
#include
#include
QT_CHARTS_USE_NAMESPACE
int main(int argc, char *argv[])
{
QCoreApplication::addLibraryPath(“F:/Qt/5.14.1/mingw73_64/plugins”);
QApplication a(argc, argv);
MainWindow w;
w.show();
// QSqlDatabase db = QSqlDatabase::addDatabase(“QSQLITE”);
// //db.setHostName(“localhost”);//设置主机名
// db.setDatabaseName(“AddressBook.db”);
// //db.setUserName(“root”); // 如果是 SQLite 不需要
// //db.setPassword(“root”); // 如果是 SQLite 不需要
// bool ok = db.open();
// if(ok)
// {
// qDebug()<<“Create DB”;
// QSqlQuery query;
// query.exec(“create table FriendManager (create_date datetime, “
// “id INTEGER PRIMARY KEY AUTOINCREMENT,name varchar(20) ,phone varchar(20), “
// “email varchar(20) , address varchar(20) , description varchar(50))”);
// }
// else
// {
// qDebug()<<“open failed”<<db.databaseName();
// }
//画图*************************************************************
QList<QLineSeries *> m_series;
QLineSeries *series1 = new QLineSeries();//实例化一个QLineSeries对象
m_series.append(series1);
// m_series.append(series2);
//设置线条名称
series1->setName(QString(“line ” + QString::number(1)));
//series->setName(QString("line " + QString::number(m_series.count())));
//设置线条颜色,如果不设置会给默认颜色
series1->setColor(QColor(255,0,255));
//series1->setBrush(QColor(255,0,255));
//series1->setPen(QColor(255,0,255));
//设置是否线条可视
series1->setVisible(true);
//点标签是否可视
series1->setPointLabelsVisible(true);
//点标签颜色
series1->setPointLabelsColor(QColor(255,255,255));
//点标签字体
series1->setPointLabelsFont(QFont("微软雅黑"));
//设置点标签显示格式
series1->setPointLabelsFormat("(@xPoint,@yPoint)");
//是否切割边缘点标签,默认为true
series1->setPointLabelsClipping(false);
//设置点标签是否可视
series1->setPointsVisible(true);
QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE");
database.setDatabaseName("F:/Qt/WorkPace/angle.db");
if (!database.open())
{
qDebug() << "Error: Failed to connect database.";
}
else
{
// do something
QSqlQuery query=QSqlQuery(database);
// query.exec(“create table ag(jd int);”);
// query.exec(“insert into ag(jd) values(3);”);
// query.exec(“delete from ag where jd=‘3’;”);
query.exec(“select * from ag”);
QList list;
while(true == query.next()){
list.append(query.value(0).toDouble());
}
if (!list.empty() && list.size()>0){
for(int i =0; i<list.size();i++){
series1->append(list.at(i),i);
}
}
qDebug() << “OK!”;
}
QChart *chart = new QChart();
chart->setTheme(QChart::ChartThemeBlueCerulean);//设置系统主题
chart->setAnimationOptions(QChart::AllAnimations);//设置启用或禁用动画
//chart->setBackgroundBrush(QBrush(QColor(170,170,255)));//设置背景色,主题和背景二选一
//chart->setDropShadowEnabled(true);//是否背景阴影
chart->setLocalizeNumbers(true);//数字是否本地化
//chart->legend()->show();//legend是否显示,show和hide
chart->addSeries(series1);//添加系列到QChart上
chart->createDefaultAxes();//创建默认轴
chart->setTitle("Simple line chart example");//设置标题
chart->setTitleBrush(QBrush(QColor(255,170,255)));//设置标题Brush
chart->setTitleFont(QFont("微软雅黑"));//设置标题字体
chart->legend()->setVisible(true);
chart->legend()->setAlignment(Qt::AlignBottom);//底部对齐
//chart->legend()->detachFromChart();
chart->legend()->setBackgroundVisible(true);//设置背景是否可视
//chart->legend()->setAutoFillBackground(true);//设置背景自动填充
//chart->legend()->setColor(QColor(255,128,128,128));//设置颜色
//chart->legend()->setContentsMargins(10,10,10,10);//设置边距left,top,right,bottom
chart->legend()->setLabelColor(QColor(255,128,255));//设置标签颜色
chart->legend()->setVisible(true);//设置是否可视
//chart->legend()->setMaximumHeight(50);
//chart->legend()->setMaximumWidth(120);
//chart->legend()->setMaximumSize(10000);
//chart->legend()->setGeometry(50,50,120,50);//设置几何位置x,y,w,h
//chart->legend()->setBrush(QBrush(QColor(128,128,128,128)));
//chart->legend()->setPen(QPen(QColor(192,192, 192,192)));
chart->legend()->setBorderColor(QColor(255,255,170,185));//设置边框颜色
QFont font = chart->legend()->font();
font.setItalic(!font.italic());
chart->legend()->setFont(font);//设置字体为斜体
font.setPointSizeF(12);
chart->legend()->setFont(font);//设置字体大小
chart->legend()->setFont(QFont("微软雅黑"));//设置字体类型
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
w.setCentralWidget(chartView);
w.resize(960, 720);
w.show();
// error e;
// e.show();
return a.exec();
}