/** * Draw a bar chart using the selected years and Municipalities */ void widgetBarChart::drawChart() { ui->widgetBarChart_2->clearPlottables(); QVector<QString> selectedMuniList; QList<QListWidgetItem*> tempMuniList = ui->listBarChartMunicipality->selectedItems(); for(QList<QListWidgetItem*>::Iterator it = tempMuniList.begin(); it != tempMuniList.end(); ++it) { QListWidgetItem *tempItem = *it; selectedMuniList.append(_meas->findMuni(tempItem->text()).name()); } QVector<double> keyData; double i = 0.25; for(QVector<QString>::Iterator it = selectedMuniList.begin(); it != selectedMuniList.end(); ++it) { keyData << i; i += 1.5; } ui->widgetBarChart_2->xAxis->setAutoTicks(false); ui->widgetBarChart_2->xAxis->setAutoTickLabels(false); ui->widgetBarChart_2->xAxis->setTickVector(keyData); ui->widgetBarChart_2->xAxis->setTickVectorLabels(selectedMuniList); ui->widgetBarChart_2->xAxis->setTickLabelRotation(-60); ui->widgetBarChart_2->xAxis->setRange(0.25,selectedMuniList.count()*1.5+1); ui->widgetBarChart_2->yAxis->setRange(_range.first*GRAPH_LOW_RATIO,_range.second*GRAPH_HIGH_RATIO); //Check if average is selected if(ui->radioButtonMeanAllDataBar->isChecked()) drawAverage(selectedMuniList.size()*1.5+1); //Draw applicable years for(int j = 0; j < _meas->yearRange().size(); ++j) if(ui->listBarChartYears->item(j)->isSelected()) drawYear(j); ui->widgetBarChart_2->legend->setVisible(true); ui->widgetBarChart_2->replot(); }
//---------------------------------------------------------------------------------------------------------------- void statsRecorder::draw( int x_, int y_, float w, float h, int nLastValues,string label, bool bLabeled, int nColor ) { float scaleH = h; float scaleW = w / maxValues; if(w == 0 ) scaleW = 1; if(h == 0 ) scaleH = maxValues*scaleW; ofSetColor(ofColor::antiqueWhite); ofRect(x_,y_,maxValues*scaleW,scaleH); glPushMatrix(); glTranslatef(x_,y_,0); ofSetColor(ofColor::grey); for(int i = 0; i < marker.size(); i++) { float y1 = scaleH-(marker[i]*scaleH); ofLine(0,y1,maxValues*scaleW,y1); } if(nLastValues > 0) drawAverage( 0, scaleH, nLastValues, scaleH, scaleW ); drawLine(0,scaleH,scaleH,scaleW,nColor); ofSetColor(ofColor::darkRed); ofDrawBitmapString(label,5,12); ofDrawBitmapString( "Avg last 10 values = "+ofToString(getAverage(10),2),5, 12-10); if(bLabeled) { ofDrawBitmapString( ofToString(loVal,2),maxValues*scaleW + 10, scaleH); ofDrawBitmapString( ofToString(hiVal,2),maxValues*scaleW + 10, 12); } glPopMatrix(); }
/** * Draw a line graph using the selected years and Municipalities and plots everything back to default. * @param lowrange the low range of the data * @param highrange the high range of the data */ void WidgetLineChart::drawChartDefault() { ui->widgetLineChart_2->clearPlottables(); //put back default title ui->widgetLineChart_2->plotLayout()->removeAt(0); QString title = _meas->name() + " Over the Years"; ui->widgetLineChart_2->plotLayout()->addElement(0, 0, new QCPPlotTitle(ui->widgetLineChart_2,title)); //Random Number stuff srand(time(NULL)); QList<QListWidgetItem*> tempMuniList = ui->listLineChartMunicipality->selectedItems(); int j = 0; for(QList<QListWidgetItem*>::Iterator it = tempMuniList.begin(); it != tempMuniList.end(); ++it) { ui->widgetLineChart_2->addGraph(); QPen tempPen(QColor(rand()%255,rand()%255,rand()%255,255)); tempPen.setWidth(PEN_WIDTH); ui->widgetLineChart_2->graph(j)->setPen(tempPen); ++j; } ui->widgetLineChart_2->xAxis->setAutoTickStep(false); ui->widgetLineChart_2->xAxis->setTickStep(1.0); ui->widgetLineChart_2->xAxis->setTickLabelRotation(-60); ui->widgetLineChart_2->xAxis->setLabel("Years"); if(_meas->yearRange().size() > 0 )ui->widgetLineChart_2->xAxis->setRange(_meas->yearRange().at(0).toInt(),_meas->yearRange().at(_meas->yearRange().size()-1).toInt()); ui->widgetLineChart_2->yAxis->setLabel(_meas->name()); ui->widgetLineChart_2->yAxis->setRange(_range.first*GRAPH_LOW_RATIO,_range.second*GRAPH_HIGH_RATIO); for(int j = 0; j < _meas->yearRange().size(); ++j) if(ui->listLineChartYears->item(j)->isSelected()) drawYear(j); if(ui->radioButtonMeanAllDataBar->isChecked()) { drawAverage(); } ui->widgetLineChart_2->setBackground(QBrush(Qt::white)); ui->widgetLineChart_2->axisRect()->setBackground(QBrush(Qt::white)); ui->widgetLineChart_2->legend->setVisible(true); ui->widgetLineChart_2->replot(); }