QCHART多坐标轴使用示例

QCHART多坐标轴和时间轴使用示例

 

多个Y坐标轴示例代码

 

    QChart *chart = new QChart();

    chart->legend()->hide();

    chart->setTitle("Multiaxis chart example");

 

    QValueAxis *axisX = new QValueAxis;

    axisX->setTickCount(10);

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

 

 

 

    QSplineSeries *series = new QSplineSeries;

    *series << QPointF(1, 5) << QPointF(3.5, 18) << QPointF(4.8, 7.5) << QPointF(10, 2.5);

    chart->addSeries(series);

 

    QValueAxis *axisY = new QValueAxis;

    axisY->setLinePenColor(series->pen().color());

 

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

    series->attachAxis(axisX);

    series->attachAxis(axisY);

 

 

 

    series = new QSplineSeries;

    *series << QPointF(1, 0.5) << QPointF(1.5, 4.5) << QPointF(2.4, 2.5) << QPointF(4.3, 12.5)

            << QPointF(5.2, 3.5) << QPointF(7.4, 16.5) << QPointF(8.3, 7.5) << QPointF(10, 17);

    chart->addSeries(series);

 

    QCategoryAxis *axisY3 = new QCategoryAxis;

    axisY3->append("Low", 5);

    axisY3->append("Medium", 12);

    axisY3->append("High", 17);

    axisY3->setLinePenColor(series->pen().color());

    axisY3->setGridLinePen((series->pen()));

 

    chart->addAxis(axisY3, Qt::AlignRight);

    series->attachAxis(axisX);

    series->attachAxis(axisY3);

 

 

    QChartView *chartView = new QChartView(chart);

    chartView->setRenderHint(QPainter::Antialiasing);

 

时间轴QDateTimeAxis 使用示例

QChart *chart = new QChart();

    chart->addSeries(series);

    chart->legend()->hide();

    chart->setTitle("Sunspots count (by Space Weather Prediction Center)");

 

    QDateTimeAxis *axisX = new QDateTimeAxis;

    axisX->setTickCount(10);

    axisX->setFormat("MMM yyyy");

    axisX->setTitleText("Date");

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

    series->attachAxis(axisX);

 

    QValueAxis *axisY = new QValueAxis;

    axisY->setLabelFormat("%i");

    axisY->setTitleText("Sunspots count");

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

    series->attachAxis(axisY);

 

    QChartView *chartView = new QChartView(chart);

    chartView->setRenderHint(QPainter::Antialiasing);

 

QT中SMAPLE代码,作为备忘。

你可能感兴趣的:(QT/C++)