void PlottingDialog::drawRGBHistogram(QImage *img){ QCPBars *rBar = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); QCPBars *gBar = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); QCPBars *bBar = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); ui->customPlot->addPlottable(rBar); ui->customPlot->addPlottable(gBar); ui->customPlot->addPlottable(bBar); int bins = 16; QVector<double> keyRData(bins); QVector<double> valueRData(bins, 0); QVector<double> keyGData(bins); QVector<double> valueGData(bins, 0); QVector<double> keyBData(bins); QVector<double> valueBData(bins, 0); QColor currentPixel; int currentRed, currentGreen, currentBlue; // now we can modify properties of myBars: for(int x=0;x<img->width();x++){ for(int y=0;y<img->height();y++){ currentPixel = QColor(img->pixel(x,y)); currentRed = currentPixel.redF() * bins; valueRData[(currentRed == bins) ? bins - 1 : currentRed]++; currentGreen = currentPixel.greenF() * bins; valueGData[(currentGreen == bins) ? bins - 1 : currentGreen]++; currentBlue = currentPixel.blueF() * bins; valueBData[(currentBlue == bins) ? bins - 1 : currentBlue]++; } } rBar->setName("R Value"); rBar->setBrush(QBrush(Qt::red)); gBar->setName("G Value"); gBar->setBrush(QBrush(Qt::green)); bBar->setName("B Value"); bBar->setBrush(QBrush(Qt::blue)); int totalPix = img->width() * img->height(); for(int i = 0;i<bins;i++){ keyRData[i] = (i/(double) bins); keyGData[i] = (i/(double) bins); keyBData[i] = (i/(double) bins); valueRData[i] = valueRData[i] / (double)totalPix; valueGData[i] = valueGData[i] / (double)totalPix; valueBData[i] = valueBData[i] / (double)totalPix; } rBar->setData(keyRData, valueRData); gBar->setData(keyGData, valueGData); bBar->setData(keyBData, valueBData); ui->customPlot->legend->setVisible(true); ui->customPlot->xAxis->setLabel("Color %"); ui->customPlot->xAxis->setRange(0,1); rBar->setWidth(1/(4*(double)bins)); gBar->setWidth(1/(4*(double)bins)); bBar->setWidth(1/(4*(double)bins)); ui->customPlot->yAxis->setLabel("Image %"); ui->customPlot->yAxis->setRange(0,1); ui->customPlot->replot(); qDebug() << "Replotting"; }
/** * @brief widgetBarChart::drawYear draw a given year on a bar chart * @param sel the index of the selected year */ void widgetBarChart::drawYear(const int &sel) { QCPBars *bar = new QCPBars(ui->widgetBarChart_2->xAxis,ui->widgetBarChart_2->yAxis); bar->setName(_meas->yearRange().at(sel)); bar->setWidth(BAR_WIDTH); QPen pen; bar->setBrush(COLOUR_LIST[sel%5]); pen.setWidthF(PEN_WIDTH); QVector<double> valueData, keyData; ui->widgetBarChart_2->addPlottable(bar); double i = 0.25 + 0.2*ui->widgetBarChart_2->xAxis->plottables().size(); QList<QListWidgetItem*> tempList = ui->listBarChartMunicipality->selectedItems(); for(QList<QListWidgetItem*>::Iterator it = tempList.begin(); it != tempList.end(); ++it) { QListWidgetItem *tempItem = *it; keyData << i; i+=1.5; try { valueData.append(_meas->findMuni(tempItem->text()).getYear(_meas->yearRange().at(sel)).value()); } catch (std::string s) { valueData.append(0.0); } } bar->setData(keyData,valueData); bar->keyAxis()->setTickVector(keyData); ui->widgetBarChart_2->legend->setVisible(true); ui->widgetBarChart_2->replot(); }
void Window::plotHistogram(QVector<double> key, QVector<double> nonEq, QVector<double> eqValue, QVector<double> lutValue) { QCustomPlot *histogramPlot = ui->histogramPlot; histogramPlot->clearGraphs(); // Non Equalized QCPBars *nonEqHistBars = new QCPBars(histogramPlot->xAxis, histogramPlot->yAxis); histogramPlot->addPlottable(nonEqHistBars); nonEqHistBars->setWidth(1); nonEqHistBars->setData(key, nonEq); nonEqHistBars->setPen(Qt::NoPen); nonEqHistBars->setBrush(QColor(10, 140, 70, 160)); // // Equalized // QCPBars *eqHistBars = new QCPBars(histogramPlot->xAxis, histogramPlot->yAxis); // histogramPlot->addPlottable(eqHistBars); // eqHistBars->setWidth(1); // eqHistBars->setData(key, eqValue); // eqHistBars->setPen(Qt::NoPen); // eqHistBars->setBrush(QColor(10, 100, 50, 70)); //// eqHistBars->moveAbove(eqHistBars); // // LUT // QCPGraph *lut = histogramPlot->addGraph(); // lut->setData(key, lutValue); // lut->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone, QPen(Qt::black, 1.5), QBrush(Qt::white), 9)); // lut->setLineStyle(QCPGraph::lsStepCenter); // lut->setPen(QPen(QColor(120, 120, 120), 2)); histogramPlot->replot(); histogramPlot->rescaleAxes(); }
/** * @brief TimerWindow::slotUpdatePlotHorizontal 更新横向绘图槽 * @param data 数据 * @param labels 文本 */ void TimerWindow::slotUpdatePlotHorizontal(QVector<double> &data, QVector<QString> &labels) { qDebug()<<"slotUpdatePlotHorizontal"; delete(customPlot); customPlot = new QCustomPlot(); customPlot->setFixedSize(500, 250); vLayoutMain->addWidget(customPlot); // create empty bar chart objects: QCPBars *regen = new QCPBars(customPlot->yAxis, customPlot->xAxis);//横向 customPlot->addPlottable(regen); // set names and colors: QPen pen; regen->setName("Regenerative"); pen.setColor(QColor("#D26079")); regen->setPen(pen); regen->setBrush(QColor("#D26079")); // prepare x axis with country labels: QVector<double> ticks; double maxValue = 0; //查找最大值 for(int i = 0; i < labels.size(); i++){ ticks << i + 1; maxValue = maxValue > data.at(i) ? maxValue : data.at(i); } customPlot->yAxis->setAutoTicks(false); customPlot->yAxis->setAutoTickLabels(false); customPlot->yAxis->setTickVector(ticks); customPlot->yAxis->setTickVectorLabels(labels); customPlot->yAxis->setTickLabelRotation(0); customPlot->yAxis->setSubTickCount(0); customPlot->yAxis->setTickLength(0, 4); customPlot->yAxis->grid()->setVisible(true); customPlot->yAxis->setRange(0, ticks.size() + 1); customPlot->yAxis->setLabel("姓名"); // prepare y axis: // customPlot->xAxis-> customPlot->xAxis->setRange(0, maxValue + maxValue / 10); customPlot->xAxis->setPadding(5); // a bit more space to the left border customPlot->xAxis->setLabel("本周时长 (小时)"); customPlot->xAxis->grid()->setSubGridVisible(true); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); customPlot->xAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); customPlot->xAxis->grid()->setSubGridPen(gridPen); /* // setup legend: customPlot->legend->setVisible(false); customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignHCenter); customPlot->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); customPlot->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(10); customPlot->legend->setFont(legendFont); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); */ regen->setData(ticks, data); customPlot->replot(); customPlot->setHidden(false); qDebug()<<"slotUpdatePlotHorizontal end"; }
/** * @brief TimerWindow::slotUpdateVerticalPlot 更新纵向绘图槽 * @param data 数据 * @param labels 文本 */ void TimerWindow::slotUpdateVerticalPlot(QVector<double> &data, QVector<QString> &labels) { qDebug()<<"slotUpdateVerticalPlot"; delete(customPlot); customPlot = new QCustomPlot(); customPlot->setFixedSize(500, 250); vLayoutMain->addWidget(customPlot); //只取labels的month/day QDate tmpDate; for(int index = 0; index < labels.size(); ++index){ // qDebug()<<"before"<<labels.at(index); tmpDate = QDate::fromString(labels.at(index),"yyyy-MM-dd"); labels.replace(index, QString::number(tmpDate.month())+"/"+QString::number(tmpDate.day())); // qDebug()<<"after"<<labels.at(index); } // create empty bar chart objects: QCPBars *regen = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(regen); // set names and colors: QPen pen; regen->setName("Regenerative"); pen.setColor(QColor("#D26079")); regen->setPen(pen); regen->setBrush(QColor("#D26079")); QVector<double> ticks; double maxValue = 0; //查找最大值 for(int i = 0; i < labels.size(); i++){ ticks << i + 1; maxValue = maxValue > data.at(i) ? maxValue : data.at(i); } customPlot->xAxis->setAutoTicks(false); customPlot->xAxis->setAutoTickLabels(false); customPlot->xAxis->setTickVector(ticks); customPlot->xAxis->setTickVectorLabels(labels); customPlot->xAxis->setTickLabelRotation(0); customPlot->xAxis->setSubTickCount(0); customPlot->xAxis->setTickLength(0, 4); customPlot->xAxis->grid()->setVisible(true); customPlot->xAxis->setRange(0, ticks.size() + 1); customPlot->xAxis->setLabel("日期"); // prepare y axis: customPlot->yAxis->setRange(0, maxValue + maxValue / 10); customPlot->yAxis->setPadding(5); // a bit more space to the left border customPlot->yAxis->setLabel("时长 (小时)"); customPlot->yAxis->grid()->setSubGridVisible(true); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); customPlot->yAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); customPlot->yAxis->grid()->setSubGridPen(gridPen); /* // setup legend: customPlot->legend->setVisible(false); customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignHCenter); customPlot->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); customPlot->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(10); customPlot->legend->setFont(legendFont); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); */ regen->setData(ticks, data); customPlot->replot(); // for(int i=0; i < labels.size(); i++){ // qDebug()<<data.at(i)<<labels.at(i); // } qDebug()<<"slotUpdateVerticalPlot end"; }
/*! * Function: slot_get_graph * Description: When "Get Graph" is clicked, this function is responsible for generating the graph based on the data passed, * a full description of each part is given below * @param bool check when it is check */ void MainWindow::slot_get_graph(bool) { Stub *stub = new Stub(); //! stub contains data for testing purpose. //! This is the variable for bar width; the value will be calculated and scaled accordingly, depending on how //! many checkboxes were selected double barWidth = 0; double i = 0; //! loop index; counts how many checkboxes where checked int barsAdded = 0; //! Creating the legend box ui -> customPlot -> legend -> clearItems(); ui -> customPlot -> axisRect()->insetLayout()->setInsetAlignment(0,Qt::AlignTop|Qt::AlignRight); ui -> customPlot -> legend -> setVisible(true); ui->customPlot->clearPlottables(); //! clear the graph //! Set graph interval ui->customPlot->xAxis->setAutoTickStep(0); ui->customPlot->xAxis->setTicks(1); ui->customPlot->xAxis->setTickStep(1.0); ui->customPlot->xAxis->setSubTickCount(0); chartcolour *colourSelect = new chartcolour(); ui->customPlot->legend->clearItems(); //!Clears the existing data from the legend ui->customPlot->axisRect()->setAutoMargins(QCP::msLeft | QCP::msTop | QCP::msBottom); ui->customPlot->axisRect()->setMargins(QMargins(0,0,150,0)); ui->customPlot->axisRect()->insetLayout()->setInsetPlacement(0, QCPLayoutInset::ipFree); ui->customPlot->axisRect()->insetLayout()->setInsetRect(0, QRectF(1.1,0,0.1,0.1)); //! Scaling the bar width based on the number of cities checked if (ui->barrie->isChecked()) { ++i; } if (ui->calgary->isChecked()) { ++i; } if (ui->hamilton->isChecked()) { ++i; } if (ui->london->isChecked()) { ++i; } if (ui->ottawa->isChecked()) { ++i; } if (ui->sudbury->isChecked()) { ++i; } if (ui->thunderBay->isChecked()) { ++i; } if (ui->toronto->isChecked()) { ++i; } if (ui->windsor->isChecked()) { ++i; } if (ui->winnipeg->isChecked()) { ++i; } //! Calculating the new bar width double totalWidth = 0.8; barWidth = totalWidth / i; double setBack = totalWidth/2; double offset = 0; //! Plot data and create a bar graph for Barrie if this city is selected if(ui->barrie->isChecked()) { //! if barrie is checked QCPBars *myBars = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); myBars->setWidth(barWidth); myBars->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded)))); myBars->setName("Barrie"); ui->customPlot->addPlottable(myBars); //! Barrie data QVector<double> barrieDatatemp = stub->getData("Barrie"); QVector<double> barrieData; QVector<double> valueYears; offset = (barWidth*barsAdded)+(barWidth/2); /*! Checks which years are checked. Plots the years selected, and scales the graph accordingly. */ if(ui->twoThousandNine->isChecked()) { valueYears << 2009-setBack+offset; barrieData << barrieDatatemp.at(0); } if(ui->twoThousandTen->isChecked()) { valueYears << 2010-setBack+offset; barrieData << barrieDatatemp.at(1); } if(ui->twoThousandEleven->isChecked()) { valueYears << 2011-setBack+offset; barrieData << barrieDatatemp.at(2); } //!valueYears << 2009-setBack+offset << 2010-setBack+offset<< 2011-setBack+offset; ++barsAdded; myBars->setData(valueYears, barrieData); ui->customPlot->rescaleAxes(); ui->customPlot->replot(); } //! Plot data and create a bar graph for Calgary if this city is selected if (ui->calgary->isChecked()) { //! This is for Calgary QCPBars *myBars2 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); myBars2->setWidth(barWidth); myBars2->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded)))); ui->customPlot->addPlottable(myBars2); //! now we can modify properties of myBars myBars2->setName("Calgary"); //! Calgary Data QVector<double> calgaryDatatemp = stub->getData("Calgary"); QVector<double> calgaryData; QVector<double> valueYears; offset = (barWidth*barsAdded)+(barWidth/2); /*! Checks which years are checked. Plots the years selected, and scales the graph accordingly. */ if(ui->twoThousandNine->isChecked()) { valueYears << 2009-setBack+offset; calgaryData << calgaryDatatemp.at(0); } if(ui->twoThousandTen->isChecked()) { valueYears << 2010-setBack+offset; calgaryData << calgaryDatatemp.at(1); } if(ui->twoThousandEleven->isChecked()) { valueYears << 2011-setBack+offset; calgaryData << calgaryDatatemp.at(2); } //! valueYears2 << 2009-setBack+offset << 2010-setBack+offset<< 2011-setBack+offset; //!2008.60+barWidth*barsAdded << 2009.60+barWidth*barsAdded << 2010.60+barWidth*barsAdded; ++barsAdded; myBars2->setData(valueYears, calgaryData); ui->customPlot->rescaleAxes(); ui->customPlot->replot(); } //!Plot data and create a bar graph for London if this city is selected if (ui->london->isChecked()) { QCPBars *myBars3 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); myBars3->setWidth(barWidth); myBars3->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded)))); myBars3->setName("London"); ui->customPlot->addPlottable(myBars3); //! London data QVector<double> londonDatatemp = stub->getData("London"); QVector<double> londonData; QVector<double> valueYears; offset = (barWidth*barsAdded)+(barWidth/2); /*! Checks which years are checked. Plots the years selected, and scales the graph accordingly. */ if(ui->twoThousandNine->isChecked()) { valueYears << 2009-setBack+offset; londonData << londonDatatemp.at(0); } if(ui->twoThousandTen->isChecked()) { valueYears << 2010-setBack+offset; londonData << londonDatatemp.at(1); } if(ui->twoThousandEleven->isChecked()) { valueYears << 2011-setBack+offset; londonData << londonDatatemp.at(2); } //! valueYears << 2009-setBack+offset << 2010-setBack+offset<< 2011-setBack+offset; ++barsAdded; myBars3->setData(valueYears, londonData); ui->customPlot->rescaleAxes(); ui->customPlot->replot(); } //!Plot data and create a bar graph for Hamilton if this city is selected if (ui->hamilton->isChecked()) { QCPBars *myBars4 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); myBars4->setWidth(barWidth); myBars4->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded)))); myBars4->setName("Hamilton"); ui->customPlot->addPlottable(myBars4); //! Hamilton data QVector<double> hamiltonDatatemp = stub->getData("Hamilton"); QVector<double> hamiltonData; QVector<double> valueYears; offset = (barWidth*barsAdded)+(barWidth/2); /*! Checks which years are checked. Plots the years selected, and scales the graph accordingly. */ if(ui->twoThousandNine->isChecked()) { valueYears << 2009-setBack+offset; hamiltonData << hamiltonDatatemp.at(0); } if(ui->twoThousandTen->isChecked()) { valueYears << 2010-setBack+offset; hamiltonData << hamiltonDatatemp.at(1); } if(ui->twoThousandEleven->isChecked()) { valueYears << 2011-setBack+offset; hamiltonData << hamiltonDatatemp.at(2); } ++barsAdded; myBars4->setData(valueYears, hamiltonData); ui->customPlot->rescaleAxes(); ui->customPlot->replot(); } //! Plot data and create a bar graph for Ottawa if this city is selected if (ui->ottawa->isChecked()) { QCPBars *myBars5 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); myBars5->setWidth(barWidth); myBars5->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded)))); myBars5->setName("Ottawa"); ui->customPlot->addPlottable(myBars5); //! Ottawa data QVector<double> ottawaDatatemp = stub->getData("Ottawa"); QVector<double> ottawaData; QVector<double> valueYears; offset = (barWidth*barsAdded)+(barWidth/2); /*! Checks which years are checked. Plots the years selected, and scales the graph accordingly. */ if(ui->twoThousandNine->isChecked()) { valueYears << 2009-setBack+offset; ottawaData << ottawaDatatemp.at(0); } if(ui->twoThousandTen->isChecked()) { valueYears << 2010-setBack+offset; ottawaData << ottawaDatatemp.at(1); } if(ui->twoThousandEleven->isChecked()) { valueYears << 2011-setBack+offset; ottawaData << ottawaDatatemp.at(2); } ++barsAdded; myBars5->setData(valueYears, ottawaData); ui->customPlot->rescaleAxes(); ui->customPlot->replot(); } //! Plot data and create a bar graph for Sudbury (Greater) if this city is selected if (ui->sudbury->isChecked()) { QCPBars *myBars6 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); myBars6->setWidth(barWidth); myBars6->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded)))); myBars6->setName("Sudbury"); ui->customPlot->addPlottable(myBars6); //! Sudbury data QVector<double> sudburyDatatemp = stub->getData("Sudbury (Greater)"); QVector<double> sudburyData; QVector<double> valueYears; offset = (barWidth*barsAdded)+(barWidth/2); /*! Checks which years are checked. Plots the years selected, and scales the graph accordingly. */ if(ui->twoThousandNine->isChecked()) { valueYears << 2009-setBack+offset; sudburyData << sudburyDatatemp.at(0); } if(ui->twoThousandTen->isChecked()) { valueYears << 2010-setBack+offset; sudburyData << sudburyDatatemp.at(1); } if(ui->twoThousandEleven->isChecked()) { valueYears << 2011-setBack+offset; sudburyData << sudburyDatatemp.at(2); } ++barsAdded; myBars6->setData(valueYears, sudburyData); ui->customPlot->rescaleAxes(); ui->customPlot->replot(); } //! Plot data and create a bar graph for Thunder Bay if this city is selected if (ui->thunderBay->isChecked()) { QCPBars *myBars7 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); myBars7->setWidth(barWidth); myBars7->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded)))); myBars7->setName("Thunder Bay"); ui->customPlot->addPlottable(myBars7); //! Thunder Bay data QVector<double> thunderDatatemp = stub->getData("Thunder Bay"); QVector<double> thunderData; QVector<double> valueYears; offset = (barWidth*barsAdded)+(barWidth/2); /*! Checks which years are checked. Plots the years selected, and scales the graph accordingly. */ if(ui->twoThousandNine->isChecked()) { valueYears << 2009-setBack+offset; thunderData << thunderDatatemp.at(0); } if(ui->twoThousandTen->isChecked()) { valueYears << 2010-setBack+offset; thunderData << thunderDatatemp.at(1); } if(ui->twoThousandEleven->isChecked()) { valueYears << 2011-setBack+offset; thunderData << thunderDatatemp.at(2); } ++barsAdded; myBars7->setData(valueYears, thunderData); ui->customPlot->rescaleAxes(); ui->customPlot->replot(); } //! Plot data and create a bar graph for Toronto if this city is selected if (ui->toronto->isChecked()) { QCPBars *myBars8 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); myBars8->setWidth(barWidth); myBars8->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded)))); myBars8->setName("Toronto"); ui->customPlot->addPlottable(myBars8); //! Sudbury data QVector<double> torontoDatatest = stub->getData("Toronto"); QVector<double> torontoData; QVector<double> valueYears; offset = (barWidth*barsAdded)+(barWidth/2); /*! Checks which years are checked. Plots the years selected, and scales the graph accordingly. */ if(ui->twoThousandNine->isChecked()) { valueYears << 2009-setBack+offset; torontoData << torontoDatatest.at(0); } if(ui->twoThousandTen->isChecked()) { valueYears << 2010-setBack+offset; torontoData << torontoDatatest.at(1); } if(ui->twoThousandEleven->isChecked()) { valueYears << 2011-setBack+offset; torontoData << torontoDatatest.at(2); } ++barsAdded; myBars8->setData(valueYears, torontoData); ui->customPlot->rescaleAxes(); ui->customPlot->replot(); } //! Plot data and create a bar graph for Winnipeg if this city is selected if (ui->winnipeg->isChecked()) { QCPBars *myBars9 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); myBars9->setWidth(barWidth); myBars9->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded)))); myBars9->setName("Winnipeg"); ui->customPlot->addPlottable(myBars9); //! Sudbury data QVector<double> winnipegDatatemp = stub->getData("Winnipeg"); QVector<double> winnipegData; QVector<double> valueYears; offset = (barWidth*barsAdded)+(barWidth/2); /*! Checks which years are checked. Plots the years selected, and scales the graph accordingly. */ if(ui->twoThousandNine->isChecked()) { valueYears << 2009-setBack+offset; winnipegData << winnipegDatatemp.at(0); } if(ui->twoThousandTen->isChecked()) { valueYears << 2010-setBack+offset; winnipegData << winnipegDatatemp.at(1); } if(ui->twoThousandEleven->isChecked()) { valueYears << 2011-setBack+offset; winnipegData << winnipegDatatemp.at(2); } ++barsAdded; myBars9->setData(valueYears, winnipegData); ui->customPlot->rescaleAxes(); ui->customPlot->replot(); } //! Plot data and create a bar graph for Windsor if this city is selected if (ui->windsor->isChecked()) { QCPBars *myBars10 = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); myBars10->setWidth(barWidth); myBars10->setBrush(QBrush(QColor(colourSelect->getColour(barsAdded)))); myBars10->setName("Windor"); ui->customPlot->addPlottable(myBars10); //! Sudbury data QVector<double> windsorDatatemp = stub->getData("Windsor"); QVector<double> windsorData; QVector<double> valueYears; offset = (barWidth*barsAdded)+(barWidth/2); /*! Checks which years are checked. Plots the years selected, and scales the graph accordingly. */ if(ui->twoThousandNine->isChecked()) { valueYears << 2009-setBack+offset; windsorData << windsorDatatemp.at(0); } if(ui->twoThousandTen->isChecked()) { valueYears << 2010-setBack+offset; windsorData << windsorDatatemp.at(1); } if(ui->twoThousandEleven->isChecked()) { valueYears << 2011-setBack+offset; windsorData << windsorDatatemp.at(2); } ++barsAdded; myBars10->setData(valueYears, windsorData); ui->customPlot->rescaleAxes(); ui->customPlot->replot(); } }
void chartcreate::repaintplot() { QCustomPlot * customPlot = ui->chart_preview; // create empty bar chart objects: QCPBars *regen = new QCPBars(customPlot->xAxis, customPlot->yAxis); QCPBars *nuclear = new QCPBars(customPlot->xAxis, customPlot->yAxis); QCPBars *fossil = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(regen); customPlot->addPlottable(nuclear); customPlot->addPlottable(fossil); // set names and colors: QPen pen; pen.setWidthF(1.2); fossil->setName("Danone"); pen.setColor(QColor(255, 131, 0)); fossil->setPen(pen); fossil->setBrush(QColor(255, 131, 0, 50)); nuclear->setName("AuBonLait"); pen.setColor(QColor(1, 92, 191)); nuclear->setPen(pen); nuclear->setBrush(QColor(1, 92, 191, 50)); regen->setName("Yoplait"); pen.setColor(QColor(150, 222, 0)); regen->setPen(pen); regen->setBrush(QColor(150, 222, 0, 70)); // stack bars ontop of each other: nuclear->moveAbove(fossil); regen->moveAbove(nuclear); // prepare x axis with country labels: QVector<double> ticks; QVector<QString> labels; ticks << 1 << 2 ; labels << "Homme" << "Femme" ; customPlot->xAxis->setAutoTicks(false); customPlot->xAxis->setAutoTickLabels(false); customPlot->xAxis->setTickVector(ticks); customPlot->xAxis->setTickVectorLabels(labels); customPlot->xAxis->setTickLabelRotation(60); customPlot->xAxis->setSubTickCount(0); customPlot->xAxis->setTickLength(0, 4); customPlot->xAxis->grid()->setVisible(true); customPlot->xAxis->setRange(0, 8); // prepare y axis: customPlot->yAxis->setRange(0, 12.1); customPlot->yAxis->setPadding(5); // a bit more space to the left border customPlot->yAxis->setLabel("Marque de Yaourt Connu"); customPlot->yAxis->grid()->setSubGridVisible(true); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); customPlot->yAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); customPlot->yAxis->grid()->setSubGridPen(gridPen); // Add data: QVector<double> fossilData, nuclearData, regenData; fossilData << 0.86*10.5 << 0.83*5.5; nuclearData << 0.08*10.5 << 0.12*5.5; regenData << 0.06*10.5 << 0.05*5.5; fossil->setData(ticks, fossilData); nuclear->setData(ticks, nuclearData); regen->setData(ticks, regenData); // setup legend: customPlot->legend->setVisible(true); customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignHCenter); customPlot->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); customPlot->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(10); customPlot->legend->setFont(legendFont); customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); }
DrawFinancialChart::DrawFinancialChart(QWidget *parent) : QCustomPlot(parent) { resize(600,400); legend->setVisible(true); // generate two sets of random walk data (one for candlestick and one for ohlc chart): int n = 500; QVector<double> time(n), value1(n), value2(n); QDateTime start = QDateTime(QDate(2014, 6, 11)); start.setTimeSpec(Qt::UTC); double startTime = start.toTime_t(); double binSize = 3600*24; // bin data in 1 day intervals time[0] = startTime; value1[0] = 60; value2[0] = 20; qsrand(9); for (int i=1; i<n; ++i) { time[i] = startTime + 3600*i; value1[i] = value1[i-1] + (qrand()/(double)RAND_MAX-0.5)*10; value2[i] = value2[i-1] + (qrand()/(double)RAND_MAX-0.5)*3; } // create candlestick chart: QCPFinancial *candlesticks = new QCPFinancial(xAxis, yAxis); addPlottable(candlesticks); QCPFinancialDataMap data1 = QCPFinancial::timeSeriesToOhlc(time, value1, binSize, startTime); candlesticks->setName("Candlestick"); candlesticks->setChartStyle(QCPFinancial::csCandlestick); candlesticks->setData(&data1, true); candlesticks->setWidth(binSize*0.9); candlesticks->setTwoColored(true); candlesticks->setBrushPositive(QColor(245, 245, 245)); candlesticks->setBrushNegative(QColor(0, 0, 0)); candlesticks->setPenPositive(QPen(QColor(0, 0, 0))); candlesticks->setPenNegative(QPen(QColor(0, 0, 0))); // create ohlc chart: QCPFinancial *ohlc = new QCPFinancial(xAxis, yAxis); addPlottable(ohlc); QCPFinancialDataMap data2 = QCPFinancial::timeSeriesToOhlc(time, value2, binSize/3.0, startTime); // divide binSize by 3 just to make the ohlc bars a bit denser ohlc->setName("OHLC"); ohlc->setChartStyle(QCPFinancial::csOhlc); ohlc->setData(&data2, true); ohlc->setWidth(binSize*0.2); ohlc->setTwoColored(true); // create bottom axis rect for volume bar chart: QCPAxisRect *volumeAxisRect = new QCPAxisRect(this); plotLayout()->addElement(1, 0, volumeAxisRect); volumeAxisRect->setMaximumSize(QSize(QWIDGETSIZE_MAX, 100)); volumeAxisRect->axis(QCPAxis::atBottom)->setLayer("axes"); volumeAxisRect->axis(QCPAxis::atBottom)->grid()->setLayer("grid"); // bring bottom and main axis rect closer together: plotLayout()->setRowSpacing(0); volumeAxisRect->setAutoMargins(QCP::msLeft|QCP::msRight|QCP::msBottom); volumeAxisRect->setMargins(QMargins(0, 0, 0, 0)); // create two bar plottables, for positive (green) and negative (red) volume bars: QCPBars *volumePos = new QCPBars(volumeAxisRect->axis(QCPAxis::atBottom), volumeAxisRect->axis(QCPAxis::atLeft)); QCPBars *volumeNeg = new QCPBars(volumeAxisRect->axis(QCPAxis::atBottom), volumeAxisRect->axis(QCPAxis::atLeft)); for (int i=0; i<n/5; ++i) { int v = qrand()%20000+qrand()%20000+qrand()%20000-10000*3; (v < 0 ? volumeNeg : volumePos)->addData(startTime+3600*5.0*i, qAbs(v)); // add data to either volumeNeg or volumePos, depending on sign of v } setAutoAddPlottableToLegend(false); addPlottable(volumePos); addPlottable(volumeNeg); volumePos->setWidth(3600*4); volumePos->setPen(Qt::NoPen); volumePos->setBrush(QColor(100, 180, 110)); volumeNeg->setWidth(3600*4); volumeNeg->setPen(Qt::NoPen); volumeNeg->setBrush(QColor(180, 90, 90)); // interconnect x axis ranges of main and bottom axis rects: connect(xAxis, SIGNAL(rangeChanged(QCPRange)), volumeAxisRect->axis(QCPAxis::atBottom), SLOT(setRange(QCPRange))); connect(volumeAxisRect->axis(QCPAxis::atBottom), SIGNAL(rangeChanged(QCPRange)), xAxis, SLOT(setRange(QCPRange))); // configure axes of both main and bottom axis rect: volumeAxisRect->axis(QCPAxis::atBottom)->setAutoTickStep(false); volumeAxisRect->axis(QCPAxis::atBottom)->setTickStep(3600*24*4); // 4 day tickstep volumeAxisRect->axis(QCPAxis::atBottom)->setTickLabelType(QCPAxis::ltDateTime); volumeAxisRect->axis(QCPAxis::atBottom)->setDateTimeSpec(Qt::UTC); volumeAxisRect->axis(QCPAxis::atBottom)->setDateTimeFormat("dd. MMM"); volumeAxisRect->axis(QCPAxis::atBottom)->setTickLabelRotation(15); volumeAxisRect->axis(QCPAxis::atLeft)->setAutoTickCount(3); xAxis->setBasePen(Qt::NoPen); xAxis->setTickLabels(false); xAxis->setTicks(false); // only want vertical grid in main axis rect, so hide xAxis backbone, ticks, and labels xAxis->setAutoTickStep(false); xAxis->setTickStep(3600*24*4); // 4 day tickstep rescaleAxes(); xAxis->scaleRange(1.025, xAxis->range().center()); yAxis->scaleRange(1.1, yAxis->range().center()); // make axis rects' left side line up: QCPMarginGroup *group = new QCPMarginGroup(this); axisRect()->setMarginGroup(QCP::msLeft|QCP::msRight, group); volumeAxisRect->setMarginGroup(QCP::msLeft|QCP::msRight, group); }
void MainWindow::makePlot() { /* QRegExp rx("(\\ |\\n)"); QStringList query = szoveg.split(rx); for (int i=0; i<query.size(); i++) QMessageBox::information(0, "info", query[i]); int szohossz[3]; for (int i=0; i<3; i++) szohossz[i] = query[i].size(); for (int i=0; i<3; i++) QMessageBox::information(0, "info", QString::number(szohossz[i]));*/ // create empty bar chart objects: QCPBars *regen = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); QCPBars *nuclear = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); QCPBars *fossil = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); ui->customPlot->addPlottable(regen); ui->customPlot->addPlottable(nuclear); ui->customPlot->addPlottable(fossil); // set names and colors: QPen pen; pen.setWidthF(1.2); fossil->setName("Fossil fuels"); pen.setColor(QColor(255, 131, 0)); fossil->setPen(pen); fossil->setBrush(QColor(255, 131, 0, 50)); nuclear->setName("Nuclear"); pen.setColor(QColor(1, 92, 191)); nuclear->setPen(pen); nuclear->setBrush(QColor(1, 92, 191, 50)); regen->setName("Regenerative"); pen.setColor(QColor(150, 222, 0)); regen->setPen(pen); regen->setBrush(QColor(150, 222, 0, 70)); // stack bars ontop of each other: nuclear->moveAbove(fossil); regen->moveAbove(nuclear); // prepare x axis with country labels: QVector<double> ticks; QVector<QString> labels; ticks << 1 << 2 << 3 << 4 << 5 << 6 << 7; labels << "Japan" << "Germany" << "France" << "UK" << "Italy" << "Canada"; ui->customPlot->xAxis->setAutoTicks(false); ui->customPlot->xAxis->setAutoTickLabels(false); ui->customPlot->xAxis->setTickVector(ticks); ui->customPlot->xAxis->setTickVectorLabels(labels); ui->customPlot->xAxis->setTickLabelRotation(60); ui->customPlot->xAxis->setSubTickCount(0); ui->customPlot->xAxis->setTickLength(0, 4); ui->customPlot->xAxis->grid()->setVisible(true); ui->customPlot->xAxis->setRange(0, 8); // prepare y axis: ui->customPlot->yAxis->setRange(0, 12.1); ui->customPlot->yAxis->setPadding(5); // a bit more space to the left border ui->customPlot->yAxis->setLabel("Power Consumption in\nKilowatts per Capita (2007)"); ui->customPlot->yAxis->grid()->setSubGridVisible(false); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); ui->customPlot->yAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); ui->customPlot->yAxis->grid()->setSubGridPen(gridPen); // Add data: QVector<double> fossilData, nuclearData, regenData; fossilData << 0.86*10.5 << 0.83*5.5 << 0.84*5.5 << 0.52*5.8 << 0.89*5.2 << 0.90*4.2 << 0.67*11.2; nuclearData << 0.08*10.5 << 0.12*5.5 << 0.12*5.5 << 0.40*5.8 << 0.09*5.2 << 0.00*4.2 << 0.07*11.2; regenData << 0.06*10.5 << 0.05*5.5 << 0.04*5.5 << 0.06*5.8 << 0.02*5.2 << 0.07*4.2 << 0.25*11.2; fossil->setData(ticks, fossilData); nuclear->setData(ticks, nuclearData); regen->setData(ticks, regenData); // setup legend: ui->customPlot->legend->setVisible(true); ui->customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignHCenter); ui->customPlot->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); ui->customPlot->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(10); ui->customPlot->legend->setFont(legendFont); ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); }
/* * makePlot() * * This function deals with creating a fully modifable bar graph based on the totals * of the surveys. It fully sets up the graph with plottting, the legend, and anything related * with the graphing. */ void MainWindow::makePlot() { ui -> customPlot->clearPlottables(); // create empty bar chart objects: QCPBars *theoretical = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); QCPBars *actual = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); QCPBars *expected = new QCPBars(ui->customPlot->xAxis, ui->customPlot->yAxis); ui->customPlot->addPlottable(actual); ui->customPlot->addPlottable(expected); ui->customPlot->addPlottable(theoretical); // set names and colors: QPen pen; pen.setWidthF(1.2); theoretical ->setName("Personal Goal"); pen.setColor(QColor(255, 131, 0)); theoretical ->setPen(pen); theoretical ->setBrush(QColor(255, 131, 0, 50)); actual->setName("Actual"); pen.setColor(QColor(1, 92, 191)); actual->setPen(pen); actual->setBrush(QColor(1, 92, 191, 50)); expected->setName("Trainer Goal"); pen.setColor(QColor(150, 222, 0)); expected->setPen(pen); expected->setBrush(QColor(150, 222, 0, 50)); // prepare x axis with labels: QVector<double> actual_ticks , expected_ticks, theoretical_ticks; QVector<QString> labels; actual_ticks<< 1 << 4 << 7 << 10 << 13; expected_ticks << 2 << 5 << 8 << 11 << 14; theoretical_ticks << 3 << 6 << 9 << 12 << 15; labels << "Prospect" << "PIE" << "FLI" << "PI" << "NCC"; ui->customPlot->xAxis->setAutoTicks(false); ui->customPlot->xAxis->setAutoTickLabels(false); ui->customPlot->xAxis->setTickVector(actual_ticks); ui->customPlot->xAxis->setTickVectorLabels(labels); ui->customPlot->xAxis->setTickLabelRotation(50); ui->customPlot->xAxis->setSubTickCount(0); ui->customPlot->xAxis->setTickLength(0,5); ui->customPlot->xAxis->grid()->setVisible(true); ui->customPlot->xAxis->setRange(0, 16); // prepare y axis: if(actual_total[0] == 0) ui->customPlot->yAxis->setRange(0, 9); else ui->customPlot->yAxis->setRange(0, actual_total[0]+2); ui->customPlot->yAxis->setPadding(5); ui->customPlot->yAxis->setLabel("Total Surveys Completed"); ui->customPlot->yAxis->grid()->setSubGridVisible(true); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); ui->customPlot->yAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); ui->customPlot->yAxis->grid()->setSubGridPen(gridPen); // Add data points: QVector<double> theoreticalData, actualData, expectedData; theoreticalData << theoretical_total[0] << theoretical_total[1] << theoretical_total[2]<< theoretical_total[3] << theoretical_total[4]; theoretical->setData(theoretical_ticks, theoreticalData); actualData << actual_total[0] << actual_total[1] << actual_total[2] << actual_total[3] << actual_total[4]; actual->setData(actual_ticks, actualData); expectedData << expected_total[0] << expected_total[1] << expected_total[2] << expected_total[3] << expected_total[4]; expected->setData(expected_ticks, expectedData); // setup legend: ui->customPlot->legend->setVisible(true); ui->customPlot->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop|Qt::AlignRight); ui->customPlot->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); ui->customPlot->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(15); ui->customPlot->legend->setFont(legendFont); }
int BarPlot::plotGrant() { string dataType = Node->getFirst(); // Get the types // Note the type is not always going to be the within the children of the node (depending on what node is passed) // It will be possible to pass in a different node (say a publication type node) when implemented vector<node*> types; vector<node*>* temptypes = Node->getChildren(); for (int i = 0; i < temptypes->size(); i++){ if (temptypes->at(i)->getSecond() > 0) types.push_back(temptypes->at(i)); } // Grab Data and prepare x axis with (professor Name) labels: QVector<QString> labels; //display the types only for (int i = 0; i < Node->getChildren()->size(); i++) labels.push_back(QString::fromStdString(Node->getChildren()->at(i)->getFirst())); // stacked bar chart can get cluttered, ensure no more than 30 different types // determine which types to push into an "Others" group vector<int> othersNdx; if (types.size() > COUNT_MAX){ vector<double> typeSumCounts; for (int i = 0; i < types.size(); i++){ typeSumCounts.push_back(types.at(i)->getFourth()); } while (types.size() - othersNdx.size() > COUNT_MAX){ othersNdx.push_back(min_element(typeSumCounts.begin(), typeSumCounts.end()) - typeSumCounts.begin()); typeSumCounts.at(min_element(typeSumCounts.begin(), typeSumCounts.end()) - typeSumCounts.begin()) = std::numeric_limits<double>::infinity(); } } QVector<double> ticks; for (int i = 1; i <= labels.size(); i++) ticks.push_back(i); QVector<double> count(labels.size()); double *data = count.data(); // create a new plottable area for each type, group everything within the "Others" group together for (int i = 0; i < types.size(); i++){ data[i] = types.at(i)->getFourth(); } QCPBars *bar = new QCPBars(this->xAxis, this->yAxis); bar->setName(QString::fromStdString(dataType)); bar->setData(ticks, count); this->addPlottable(bar); // set the colors QPen pen; pen.setWidthF(1.2); int C_HUE = 0; QColor color_brush, color_pen; color_brush.setHsv(C_HUE, BAR_SAT, BAR_VAL); color_brush.setAlpha(BAR_ALPHA); color_pen.setHsv(C_HUE, BAR_SAT + 30, BAR_VAL + 10); color_pen.setAlpha(255); pen.setColor(color_pen); bar->setPen(pen); bar->setBrush(color_brush); // prepare x axis: this->xAxis->setAutoTicks(false); this->xAxis->setAutoTickLabels(false); this->xAxis->setTickVector(ticks); this->xAxis->setTickVectorLabels(labels); this->xAxis->setTickLabelRotation(60); this->xAxis->setSubTickCount(0); this->xAxis->setTickLength(0, 3); this->xAxis->grid()->setVisible(true); // prepare y axis: this->yAxis->setTickStep(5); this->yAxis->setPadding(5); // a bit more space to the left border this->yAxis->setLabel("Amount ($)"); this->yAxis->grid()->setSubGridVisible(true); QPen gridPen; gridPen.setStyle(Qt::SolidLine); gridPen.setColor(QColor(0, 0, 0, 25)); this->yAxis->grid()->setPen(gridPen); gridPen.setStyle(Qt::DotLine); this->yAxis->grid()->setSubGridPen(gridPen); this->yAxis->scaleRange(1.3, this->yAxis->range().center()); this->rescaleAxes(true); this->xAxis->setRange(0.5, 10.5); // setup legend: QCPLayoutGrid *subLayout = new QCPLayoutGrid; QCPLayoutElement *dummyElement = new QCPLayoutElement; this->plotLayout()->addElement(0, 1, subLayout); // add sub-layout in the cell to the right of the main axis rect subLayout->addElement(0, 0, this->legend); // add legend subLayout->addElement(1, 0, dummyElement); // add dummy element below legend subLayout->setRowStretchFactor(0, 0.01); // make legend cell (in row 0) take up as little vertical space as possible this->plotLayout()->setColumnStretchFactor(1, 0.01); // make the legend cell and dummy element column as small as possible this->legend->setVisible(true); this->axisRect()->insetLayout()->setInsetAlignment(0, Qt::AlignTop | Qt::AlignRight); this->legend->setBrush(QColor(255, 255, 255, 200)); QPen legendPen; legendPen.setColor(QColor(130, 130, 130, 200)); this->legend->setBorderPen(legendPen); QFont legendFont = font(); legendFont.setPointSize(8); this->legend->setFont(legendFont); this->legend->setSelectableParts(QCPLegend::spItems); // legend box shall not be selectable, only legend items this->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iSelectLegend); return 0; }
void CPerformance::graphColors(QCustomPlot *customPlot) { QVector<double> datax = QVector<double>() << 1 << 2 << 3 << 4 << 5; customPlot->clearPlottables(); // QCPPlotTitle *title = new QCPPlotTitle(customPlot, "Colors Performance"); // ///To print only one time the title // if(customPlot->plotLayout()->rowCount() < 2) // { // customPlot->plotLayout()->insertRow(0); // } // title->setTextColor(QColor(255, 255, 255)); // customPlot->plotLayout()->addElement(0, 0, title); QCPBarsGroup *group1 = new QCPBarsGroup(customPlot); QCPBars *bars = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(bars); bars->setData(datax, blueRights); bars->setBrush(QColor(25, 115, 215, 50)); bars->setPen(QColor(25, 115, 215)); bars->setWidth(0.15); group1->insert(1, bars); // bars->setBarsGroup(group1); bars->setName("Blue"); // customPlot->plottable(0)->setName("squareRights"); bars = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(bars); bars->setData(datax,redRights); bars->setBrush(QColor(240, 0, 0, 50)); bars->setPen(QColor(240, 0, 0)); bars->setWidth(0.15); group1->insert(2,bars); // bars->setBarsGroup(group1); bars->setName("Red"); bars = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(bars); bars->setData(datax, greenRights); bars->setBrush(QColor(30, 210, 60, 50)); bars->setPen(QColor(30, 210, 60)); bars->setWidth(0.15); group1->insert(3,bars); // bars->setBarsGroup(group1); bars->setName("Green"); bars = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(bars); bars->setData(datax, yellowRights); bars->setBrush(QColor(240, 230, 0, 50)); bars->setPen(QColor(240, 230, 0)); bars->setWidth(0.15); group1->insert(4,bars); // bars->setBarsGroup(group1); bars->setName("Yellow"); bars = new QCPBars(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(bars); bars->setData(datax, blackRights); bars->setBrush(QColor(0, 0, 0, 50)); bars->setPen(QColor(0, 0, 0)); bars->setWidth(0.15); group1->insert(5,bars); // bars->setBarsGroup(group1); bars->setName("Black"); customPlot->legend->setVisible(true); customPlot->replot(); }