mainwindow创建折线图部分参数
QT += charts
#include <QtCharts/QChartView>//显示图表
#include <QtCharts/QLineSeries>//线系列
QList<QLineSeries *> m_series;
QLineSeries *series1 = new QLineSeries();//实例化一个QLineSeries对象
QChart *chart = new QChart();
QChartView *chartView1 = new QChartView(chart, this);
m_series.append(series1);
//设置线条名称
series1->setName(QString("曲线" + QString::number(1)));
//设置线条颜色,如果不设置会给默认颜色
series1->setColor(QColor(255,0,255));
//设置是否线条可视
series1->setVisible(true);
//点标签是否可视
series1->setPointLabelsVisible(false);
//点标签颜色
series1->setPointLabelsColor(QColor(255,255,255));
//点标签字体
series1->setPointLabelsFont(QFont("微软雅黑"));
//设置点标签显示格式
series1->setPointLabelsFormat("(@xPoint,@yPoint)");
//是否切割边缘点标签,默认为true
series1->setPointLabelsClipping(false);
//设置点标签是否可视
series1->setPointsVisible(true);
//添加坐标点
series1->append(0, 6);
series1->append(2, 4);
series1->append(3, 8);
series1->append(7, 4);
series1->append(10, 5);
*series1 << QPointF(11, 1) << QPointF(13, 3) << QPointF(17, 6) << QPointF(18, 3) << QPointF(20, 2);
//QChart类用于控制整个图表界面的设置,例如坐标轴、主题、背景色、标题、legend等;
//chart->setTheme(QChart::ChartThemeDark);//设置系统主题
chart->setAnimationOptions(QChart::AllAnimations);//设置启用或禁用动画
chart->setBackgroundBrush(QBrush(QColor(0,0,0)));//设置背景色,主题和背景二选一
chart->setDropShadowEnabled(false);//是否背景阴影
chart->setLocalizeNumbers(true);//数字是否本地化
//chart->legend()->show();//legend是否显示,show和hide
chart->addSeries(series1);//添加系列到QChart上
//chart->addSeries(series2);//添加系列到QChart上
chart->createDefaultAxes();//创建默认轴
// chart->setTitle("标题");//设置标题
chart->setTitleBrush(QBrush(QColor(255,255,255)));//设置标题Brush
chart->setTitleFont(QFont("微软雅黑"));//设置标题字体
//legend的设置参数 状态栏
chart->legend()->setVisible(true);
chart->legend()->setAlignment(Qt::AlignTop);//顶部
//chart->legend()->detachFromChart();
chart->legend()->setBackgroundVisible(false);//设置背景是否可视
//chart->legend()->setAutoFillBackground(true);//设置背景自动填充
chart->legend()->setColor(QColor(255,255,255));//设置颜色
//chart->legend()->setContentsMargins(10,10,10,10);//设置边距left,top,right,bottom
chart->legend()->setLabelColor(QColor(0,0,0));//设置标签颜色
chart->legend()->setMaximumHeight(50);
chart->legend()->setMaximumWidth(220);
//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(14);
chart->legend()->setFont(font);//设置字体大小
chart->legend()->setFont(QFont("微软雅黑"));//设置字体类型
chartView1->setRenderHint(QPainter::Antialiasing);
//chartView1->move(133,803);
chartView1->resize(this->width(),this->height());
// 显示图表
chartView1->show();