gpt4 book ai didi

c++ - QtCharts添加自定义轴

转载 作者:行者123 更新时间:2023-12-02 19:37:28 25 4
gpt4 key购买 nike

我需要在 QtCharts 上有自定义轴。然而,这些线路会导致崩溃。

chart->addAxis(axisX, Qt::AlignCenter);
chart->addAxis(axisY, Qt::AlignCenter);

请问您能提供如何自定义轴的示例吗?目的是获得一些指定的范围和轴标题。

QtCharts::QValueAxis *axisX = new QtCharts::QValueAxis();
axisX->setRange(0, 3);
axisX->setTitleText("x");
QtCharts::QValueAxis *axisY = new QtCharts::QValueAxis();
axisY->setRange(0, 3);
axisY->setTitleText("y");

QtCharts::QScatterSeries *series0 = new QtCharts::QScatterSeries();
for (uint i=0; i<size; i++)
series0->append(vector4.at(i), vector6.at(i));

series0->setName("scatter1");
series0->setMarkerShape(QtCharts::QScatterSeries::MarkerShapeRectangle);
series0->setMarkerSize(10.0);

QtCharts::QChart *chart = new QtCharts::QChart();
chart->addSeries(series0);
chart->createDefaultAxes();
//chart->addAxis(axisX, Qt::AlignCenter); CRASH
//chart->addAxis(axisY, Qt::AlignCenter);

QtCharts::QChartView *chartView = new QtCharts::QChartView();
chartView->setChart(chart);
chartView->show();

提前致谢

最佳答案

过了一段时间我找到了解决方案。它可能对某人有帮助。

chart->createDefaultAxes();
chart->axes(Qt::Horizontal).back()->setRange(-35, 135);
chart->axes(Qt::Vertical).back()->setRange(-35, 50);
chart->axes(Qt::Horizontal).back()->setTitleText("axis x [mm]");
chart->axes(Qt::Vertical).back()->setTitleText("axis y [mm]");

关于c++ - QtCharts添加自定义轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60870695/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com