Hi, I would like to have multiple colors on one graph depending on the x-value.
Also, the curve is doing the real-time plotting.

Here's my code:

void main()
{
...
ui->CustomPlot->graph(0)->addData(-5, 10);
ui->CustomPlot->graph(0)->addData(-4, 11);
ui->CustomPlot->graph(0)->addData(-3, 12);
ui->CustomPlot->graph(0)->addData(-2, 13);
ui->CustomPlot->graph(0)->addData(-1, 14);
ui->CustomPlot->graph(0)->addData(3, 16);
ui->CustomPlot->graph(0)->addData(2, 17);
ui->CustomPlot->graph(0)->addData(1, 18);
ui->CustomPlot->graph(0)->addData(0, 19);
ui->CustomPlot->graph(0)->setSelectable(QCP::stMultipleDataRanges);
// setup a timer that repeatedly calls MainWindow::realtimeDataSlot:
connect(&timer, SIGNAL(timeout()), this, SLOT(RealtimeDataSlot()));
connect(&timer, SIGNAL(timeout()), this, SLOT(colorSelected()));
timer.start(5);
}

void RealtimeDataSlot()
{
ui->CustomPlot->graph(0)->addData(0, 16);
}

void colorSelected()
{
QCPDataRange range;
range.setBegin(0);
range.setEnd(20);

QCPDataSelection selection;
selection.addDataRange(range);
QCPSelectionDecorator * decorator = new QCPSelectionDecorator();

decorator->setBrush(QBrush(Qt::red));
ui->CustomPlot->graph(0)->setSelectionDecorator(decorator);
ui->CustomPlot->graph(0)->setSelection(selection);
}

However, whenever RealtimeDataSlot() function is called, the selected color disappears even though colorSelected() is always called afterwards.
Can anybody help me on fixing this issue?