nanthiran_2005
20th June 2014, 05:38
Hi everyone,
I am currently trying to plot a stacked bar chart. However the width of the bars are not equal. I am plotting 5 bars with each bar stacked with two. I have attached an image of the bar chart. Only the first and last bar are not in equal size as the rest of the bars. I have also attached the portion of code which generates the barchart, below. Please guide me on how to solve this issue.
10434
BarChart::BarChart(QWidget *parent)
: QwtPlot(parent)
{
setAutoFillBackground(true);
setPalette(Qt::white);
canvas()->setPalette(QColor ("Black")); //background color
barChart = new QwtPlotMultiBarChart;
barChart->setLayoutPolicy(QwtPlotMultiBarChart::AutoAdjustSa mples);
barChart->setSpacing(20);
barChart->setMargin(20);
barChart->setStyle(QwtPlotMultiBarChart::Stacked);
barChart->attach(this);
for(int i = 0; i < 2; ++i)
{
QwtColumnSymbol *symbol = new QwtColumnSymbol(QwtColumnSymbol::Box);
QPalette barColor = (i == 0) ? Qt::green : Qt::red ;
symbol->setPalette(barColor);
symbol->setFrameStyle(QwtColumnSymbol::Raised);
symbol->setLineWidth(1);
barChart->setSymbol(i, symbol);
}
QVector<QVector<double> > newBarChartData;
for(int i = 0; i < 5; i++)
{
num = rand() % 100;
QVector<double> values;
values.push_back(num);
values.push_back(100-num);
newBarChartData.push_back(values);
}
barChart->setSamples(newData);
QwtPlot::Axis yAxis = QwtPlot::yLeft,
xAxis = QwtPlot::xBottom;
setAxisScale(yAxis, 0, 100, 20);
setAxisAutoScale(xAxis);
enableAxis(yAxis, true);
enableAxis(xAxis, false);
QwtScaleDraw *yAxis_scaleDraw = axisScaleDraw(yAxis);
yAxis_scaleDraw->enableComponent(QwtScaleDraw::Backbone, false);
yAxis_scaleDraw->enableComponent(QwtScaleDraw::Ticks, false);
QwtScaleDraw *xAxis_scaleDraw = axisScaleDraw(xAxis);
xAxis_scaleDraw->enableComponent(QwtScaleDraw::Backbone, false);
xAxis_scaleDraw->enableComponent(QwtScaleDraw::Ticks, false);
plotLayout()->setCanvasMargin(0);
updateCanvasMargins();
replot();
}
I am currently trying to plot a stacked bar chart. However the width of the bars are not equal. I am plotting 5 bars with each bar stacked with two. I have attached an image of the bar chart. Only the first and last bar are not in equal size as the rest of the bars. I have also attached the portion of code which generates the barchart, below. Please guide me on how to solve this issue.
10434
BarChart::BarChart(QWidget *parent)
: QwtPlot(parent)
{
setAutoFillBackground(true);
setPalette(Qt::white);
canvas()->setPalette(QColor ("Black")); //background color
barChart = new QwtPlotMultiBarChart;
barChart->setLayoutPolicy(QwtPlotMultiBarChart::AutoAdjustSa mples);
barChart->setSpacing(20);
barChart->setMargin(20);
barChart->setStyle(QwtPlotMultiBarChart::Stacked);
barChart->attach(this);
for(int i = 0; i < 2; ++i)
{
QwtColumnSymbol *symbol = new QwtColumnSymbol(QwtColumnSymbol::Box);
QPalette barColor = (i == 0) ? Qt::green : Qt::red ;
symbol->setPalette(barColor);
symbol->setFrameStyle(QwtColumnSymbol::Raised);
symbol->setLineWidth(1);
barChart->setSymbol(i, symbol);
}
QVector<QVector<double> > newBarChartData;
for(int i = 0; i < 5; i++)
{
num = rand() % 100;
QVector<double> values;
values.push_back(num);
values.push_back(100-num);
newBarChartData.push_back(values);
}
barChart->setSamples(newData);
QwtPlot::Axis yAxis = QwtPlot::yLeft,
xAxis = QwtPlot::xBottom;
setAxisScale(yAxis, 0, 100, 20);
setAxisAutoScale(xAxis);
enableAxis(yAxis, true);
enableAxis(xAxis, false);
QwtScaleDraw *yAxis_scaleDraw = axisScaleDraw(yAxis);
yAxis_scaleDraw->enableComponent(QwtScaleDraw::Backbone, false);
yAxis_scaleDraw->enableComponent(QwtScaleDraw::Ticks, false);
QwtScaleDraw *xAxis_scaleDraw = axisScaleDraw(xAxis);
xAxis_scaleDraw->enableComponent(QwtScaleDraw::Backbone, false);
xAxis_scaleDraw->enableComponent(QwtScaleDraw::Ticks, false);
plotLayout()->setCanvasMargin(0);
updateCanvasMargins();
replot();
}