1 Attachment(s)
Problem with implementing custom QChartView
I have implemented a line graph using QchartView. Attachment 13638
However, I would like to highlight a specific section of only the green line graph.
Any suggestions?
Code:
// Actual hit-ratio
QLineSeries *seriesData = new QLineSeries();
for(int i=0; i<timeWindowHR.size(); i++){
int xFirstPoint = timeWinXCoor[i];
int yFirstPoint = timeWindowHR[i];
seriesData->append(xFirstPoint, yFirstPoint);
int xSecondPoint = timeWinXCoor[i+1];
int ySecondPoint = timeWindowHR[i];
seriesData->append(xSecondPoint, ySecondPoint);
}
QPen pen
((Qt
::darkGreen));
pen.setWidth(2);
seriesData->setName("Actual Hit-Ratio");
seriesData->setPen(pen);
// Expected hit-ratio
QLineSeries *expectedSeries = new QLineSeries();
for(int i=0; i<expectedHR.size(); i++){
int xFirstPoint = timeWinXCoor[i];
int yFirstPoint = expectedHR[i];
expectedSeries->append(xFirstPoint, yFirstPoint);
int xSecondPoint = timeWinXCoor[i+1];
int ySecondPoint = expectedHR[i];
expectedSeries->append(xSecondPoint, ySecondPoint);
}
QPen expPen
((Qt
::darkGray));
expPen.setWidth(2);
expectedSeries->setName("Expected Hit-Ratio");
expectedSeries->setPen(expPen);
chartView->chart()->removeAllSeries();
chartView->chart()->addSeries(seriesData);
chartView->chart()->addSeries(expectedSeries);
Re: Problem with implementing custom QChartView
QCharts is probably the most poorly-designed library in all of Qt. You can't customize it in any way because none of the classes have virtual methods and there is no way to override them through inheritance to change their behavior.
I think the only way to solve your problem is to create a third QLineSeries that contains the points in the section you want to highlight, and to remove those points from the green series. You probably need to split the green series into three separate series - one before the highlight, the highlight, and one after, because if you don't there will be a line drawn through the highlight region that connects the two parts on the non-highlighted series.
You might want to check out QCustomPlot instead. I have been able to customize it to do almost everything I need. I gave up on QCharts long ago when I realized there was nothing I could change. Literally everything is locked-in way down into the implementation.
1 Attachment(s)
Re: Problem with implementing custom QChartView
Quote:
Originally Posted by
d_stranz
QCharts is probably the most poorly-designed library in all of Qt. You can't customize it in any way because none of the classes have virtual methods and there is no way to override them through inheritance to change their behavior.
I think the only way to solve your problem is to create a third QLineSeries that contains the points in the section you want to highlight, and to remove those points from the green series. You probably need to split the green series into three separate series - one before the highlight, the highlight, and one after, because if you don't there will be a line drawn through the highlight region that connects the two parts on the non-highlighted series.
You might want to check out QCustomPlot instead. I have been able to customize it to do almost everything I need. I gave up on QCharts long ago when I realized there was nothing I could change. Literally everything is locked-in way down into the implementation.
Thanks, I will try to implement it.
I also need to draw a cursor on the QChartView object. something like this:
Cursor on the ChartAttachment 13639
Whenever the user will hover on the QchartView, I need to show this vertical cursor. Can you tell me how can I do that?
Re: Problem with implementing custom QChartView
Quote:
Can you tell me how can I do that?
Sorry, like I said, I don't use QtCharts. Maybe someone else here can give you some help.
However, because you have three different colors, you will probably have to create three QScatterSeries, one for each dot and color, and use a QChartView RubberBand for the vertical line. Each time the line moves, you will have to call QScatterSeries::replace() for each dot to update the position. It will be ugly code.