void CameraWidget::initChatView() {
//
//qDebug() << "ChartView begin:";
int yRange = 0;
_chart = new QChart();
//设置横坐标
QStringList categories;
for (int i = 0; i<256; i++)
if(i%50 == 0)
{
categories.append(QString::number(i));
}
QBarCategoryAxis *axisX = new QBarCategoryAxis();
axisX->append(categories);
//设置纵坐标
QValueAxis *axisY = new QValueAxis;
axisY->setLabelFormat("%d");
axisY->setRange(0, yRange);
_chart->setAxisX(axisX);
_chart->setAxisY(axisY);
//_chart->addAxis(axisX, Qt::AlignBottom);
//_chart->addAxis(axisY, Qt::AlignLeft);
//series->attachAxis(axisX);
//series->attachAxis(axisY);
_chart->setTitle("GrayHistogram");
_chart->legend()->setVisible(false);
_chart->createDefaultAxes();
_chart->setAnimationOptions(QChart::SeriesAnimations);
_series = new QBarSeries();
ui->histwidget->setChart(_chart);
ui->histwidget->setRenderHint(QPainter::Antialiasing);
ui->histwidget->setVisible(true);
}
void CameraWidget::onUpdateBarSeries(int* data) {
qDebug() << "CameraWidget::onUpdateBarSeries>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> make chart:";
//设置每个“柱”的颜色,值,宽度等
qDebug() << "Data::" << data;
int yRange = 0;
auto set = new QBarSet("Pixel");
for (int i = 0; i<256; i++)
{
//qDebug() << "data[i] = " << data[i];
set->append(data[i]);
if (yRange<data[i]) yRange = data[i];
set->setColor(QColor::Rgb);
}
_series->clear();
_series->append(set);
_series->setBarWidth(1.2);
_chart->addSeries(_series);
delete[] data;
}