Solved LineChart: one line with different colors
-
Hello,
I want to plot a LineChart using diffrent colors for the same QLineSeries. I have been searching but I found nothing. Does anyone know if this is possible with Qt?
I attach a photo to show what I would like to do.
Thanks
-
I found a kind of solution to do this using gradients. It is probably not the best way but by now it accomplishes the goal.
QLinearGradient gradient(0,0,0,1); gradient.setColorAt(0, Qt::blue); gradient.setColorAt(threshold_low-0.1, Qt::blue); gradient.setColorAt(threshold_low, Qt::gray); gradient.setColorAt(threshold_up, Qt::gray); gradient.setColorAt(threshold_up+0.1, Qt::red); gradient.setColorAt(1, Qt::red); gradient.setCoordinateMode(QGradient::StretchToDeviceMode); QPen pen(QBrush(gradient), 2);
-
I found a kind of solution to do this using gradients. It is probably not the best way but by now it accomplishes the goal.
QLinearGradient gradient(0,0,0,1); gradient.setColorAt(0, Qt::blue); gradient.setColorAt(threshold_low-0.1, Qt::blue); gradient.setColorAt(threshold_low, Qt::gray); gradient.setColorAt(threshold_up, Qt::gray); gradient.setColorAt(threshold_up+0.1, Qt::red); gradient.setColorAt(1, Qt::red); gradient.setCoordinateMode(QGradient::StretchToDeviceMode); QPen pen(QBrush(gradient), 2);