QCHART的几种坐标轴的详细介绍及使用代码示例

QCHART的几种坐标轴的详细介绍及使用代码示例

 

QCHART主要有如下几种坐标轴:

QAbstractAxis->QBarCategoryAxis:柱状图坐标轴文字
QAbstractAxis->QDateTimeAxis:日期坐标轴
QAbstractAxis->QLogValueAxis(对数做标轴)
QAbstractAxis->QValueAxis(设置坐标轴范围)->QCategoryAxis(文字描述坐标轴)

 

下面详细介绍各种坐标轴的使用代码:

QAbstractAxis->QBarCategoryAxis:柱状图坐标轴文字

  QChartView *chartView = new QChartView;
  QBarSeries *series = new QBarSeries;
  // ...
  chartView->chart()->addSeries(series);
  chartView->chart()->createDefaultAxes();

  QBarCategoryAxis *axisX = new QBarCategoryAxis;
  QStringList categories;
  categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
  axisX->append(categories);
  axisX->setRange("Feb", "May");
  chartView->chart()->setAxisX(axisX, series);

QDateTimeAxis:日期坐标轴

  QChartView *chartView = new QChartView;
  chartView->chart()->addSeries(series);

  // ...
  QDateTimeAxis *axisX = new QDateTimeAxis;
  axisX->setFormat("dd-MM-yyyy h:mm");
  chartView->chart()->setAxisX(axisX, series);

QAbstractAxis->QLogValueAxis(对数做标轴)

  QValueAxis *axisX = new QValueAxis();
  axisX->setTitleText("Data point");
  axisX->setLabelFormat("%i");
  axisX->setTickCount(series->count());
  chart->addAxis(axisX, Qt::AlignBottom);
  series->attachAxis(axisX);

  QLogValueAxis *axisY = new QLogValueAxis();
  axisY->setTitleText("Values");
  axisY->setLabelFormat("%g");
  axisY->setBase(8.0);
  axisY->setMinorTickCount(-1);
  chart->addAxis(axisY, Qt::AlignLeft);
  series->attachAxis(axisY);

QValueAxis(设置坐标轴范围)

QChartView *chartView = new QChartView;
  QLineSeries *series = new QLineSeries;
  // ...
  chartView->chart()->addSeries(series);

  QValueAxis *axisX = new QValueAxis;
  axisX->setRange(10, 20.5);
  axisX->setTickCount(10);
  axisX->setLabelFormat("%.2f");
  chartView->chart()->setAxisX(axisX, series);

QCategoryAxis(文字描述坐标轴)

  QChartView *chartView = new QChartView;
  QLineSeries *series = new QLineSeries;
  // ...
  chartView->chart()->addSeries(series);

  QCategoryAxis *axisY = new QCategoryAxis;
  axisY->setMin(0);
  axisY->setMax(52);
  axisY->setStartValue(15);
  axisY->append("First", 20);
  axisY->append("Second", 37);
  axisY->append("Third", 52);
  chartView->chart()->setAxisY(axisY, series);

备注:实战示例,解疑答惑。

           --不间端地思考,实时地批判你的工作!

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值