QScatterSeries类是Qt Charts模块的一部分,用于表示散点图。
QScatterSeries* series = new QScatterSeries(); // 创建离散点数据
series->setName("圆点样式");
series->setMarkerShape(QScatterSeries::MarkerShapeCircle); //设置位圆形
series->setMarkerSize(10); //设置原大小
for(int i = 0; i < 20; i++)
{
series->append(i, QRandomGenerator::global()->bounded(10, 50));
}
QScatterSeries* range = new QScatterSeries(); // 创建一个散点数据集对象
range->setName("方形样式");
range->setMarkerShape(QScatterSeries::MarkerShapeRectangle); // 设置绘制的散点的样式为矩形
range->setMarkerSize(10); // 设置绘制的点的大小
for(int i = 0; i < 20; i++) // 添加10个任意点
{
*range << QPointF(i, QRandomGenerator::global()->bounded(10, 50)); // 换一种添加数据的方式
}
QChart *chart = new QChart();
chart->addSeries(series);
chart->addSeries(range);
chart->setTitle("Simple barchart example");
chart->createDefaultAxes();
chart->setAnimationOptions(QChart::SeriesAnimations);
QChartView *chartView = new QChartView(chart);
chartView->setRenderHint(QPainter::Antialiasing);
chartView->chart()->setTitle("li san dian");
//设置点形状样式
chartView->chart()->legend()->setMarkerShape(QLegend::MarkerShapeFromSeries);
chartView->chart()->setTheme(QChart::ChartThemeBlueCerulean); //设置标背景