qchart 坐标轴设置_QChart学习之QValueAxis坐标轴设置

QChart 坐标轴设置

// 添加轴

QValueAxis *xAxis = new QValueAxis();

QValueAxis *yAxis = new QValueAxis();

// 坐标轴整体

xAxis->setRange(0, 10);

yAxis->setRange(0, 10);

// 轴标题设置

xAxis->setTitleText(QStringLiteral(“时间”));

xAxis->setTitleFont(QFont(“宋体”));

QBrush brush;

brush.setStyle(Qt::SolidPattern);

brush.setColor(Qt::red);

xAxis->setTitleBrush(brush);

// 轴标签设置

xAxis->setLabelFormat(“%.1f”);

xAxis->setLabelsAngle(45);

xAxis->setLabelsColor(Qt::blue);

xAxis->setLabelsEditable(true);

// 轴线和刻度线设置

xAxis->setTickCount(11);

QPen pen;

pen.setStyle(Qt::SolidLine);

pen.setColor(Qt::red);

xAxis->setLinePen(pen);

xAxis->setLineVisible(true);

xAxis->setLinePenColor(Qt::blue);

// 主网格线设置

xAxis->setGridLineVisible(true);

xAxis->setGridLineColor(Qt::black);

// 次刻度和次网格线设置

xAxis->setMinorTickCount(1);

xAxis->setMinorGridLineColor(Qt::red);

完整代码

QChart *chart = new QChart();

chart->setTheme(QChart::ChartThemeQt);

chart->setTitle(“显示坐标点”);

chart->setMargins(QMargins(10, 10, 10, 10));

QLineSeries *lineSeries0 = new QLineSeries();

lineSeries0->setName(“时间 1”);

lineSeries0->append(0, 8);

lineSeries0->append(2, 8);

lineSeries0->append(3, 6);

lineSeries0->append(5, 6);

lineSeries0->append(7, 9);

*lineSeries0 << QPointF(9, 9) << QPointF(10, 7);

QScatterSeries *scatterSeries = new QScatterSeries();

scatterSeries->setName(“时间”);

scatterSeries->setPointLabelsFormat(“(@xPoint, @yPoint)”);

scatterSeries->setMarkerSize(6);

scatterSeries->setPointLabelsVisible();

scatterSeries->append(0, 8);

scatterSeries->append(2, 8);

scatterSeries->append(3, 6);

scatterSeries->append(5, 6);

scatterSeries->append(7, 9);

scatterSeries->append(9, 9);

scatterSeries->append(10, 7);

// 添加轴

QValueAxis *xAxis = new QValueAxis();

QValueAxis *yAxis = new QValueAxis();

// 坐标轴整体

xAxis->setRange(0, 10);

yAxis->setRange(0, 10);

// 轴标题设置

xAxis->setTitleText(QStringLiteral(“时间”));

xAxis->setTitleFont(QFont(“宋体”));

QBrush brush;

brush.setStyle(Qt::SolidPattern);

brush.setColor(Qt::red);

xAxis->setTitleBrush(brush);

// 轴标签设置

xAxis->setLabelFormat(“%.1f”);

xAxis->setLabelsAngle(45);

xAxis->setLabelsColor(Qt::blue);

xAxis->setLabelsEditable(true);

// 轴线和刻度线设置

xAxis->setTickCount(11);

QPen pen;

pen.setStyle(Qt::SolidLine);

pen.setColor(Qt::red);

xAxis->setLinePen(pen);

xAxis->setLineVisible(true);

xAxis->setLinePenColor(Qt::blue);

// 主网格线设置

xAxis->setGridLineVisible(true);

xAxis->setGridLineColor(Qt::black);

// 次刻度和次网格线设置

xAxis->setMinorTickCount(1);

xAxis->setMinorGridLineColor(Qt::red);

chart->addSeries(lineSeries0);

chart->addSeries(scatterSeries);

chart->addAxis(xAxis, Qt::AlignBottom);

chart->addAxis(yAxis, Qt::AlignLeft);

scatterSeries->attachAxis(xAxis);

scatterSeries->attachAxis(yAxis);

lineSeries0->attachAxis(xAxis);

lineSeries0->attachAxis(yAxis);

ui->chartView->setChart(chart);

ui->chartView->setRubberBand(QChartView::RectangleRubberBand);

ui->chartView->setRenderHint(QPainter::Antialiasing, true);

运行效果

726.html

IT宅个人博客 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权

转载请注明原文链接:QChart学习之QValueAxis坐标轴设置


版权声明:本文为weixin_31002075原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。