ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Chart with slider
Posted by Oguz on Oct-10-2019 01:55
Hello,

I have a 2D Chart with static data(not real time). What I want is to have a slider like the real time view port example for the 2D chart. Slider should have zooming functionality. (When user moves the slider, it suppose to zoom to that part of the chart) I've tried to mimic the real time view port example with no luck.

    QFrame *lowerFrame = new QFrame(this->m_p_chart_viewer);
    lowerFrame->setGeometry(0, 355, 640, 64);
    lowerFrame->setStyleSheet("background-color:white");

    m_p_ViewPortControl = new QViewPortControl(lowerFrame);
    m_p_ViewPortControl->setGeometry(0, 355, 640, 64);
    m_p_ViewPortControl->setViewer(p_chart_view);
    m_p_ViewPortControl->setChart(p_chart_view->getChart());
    m_p_ViewPortControl->show();
    lowerFrame->show();

The code above is the inside of the constructor of chart class. Result of it was a blank frame on the chart. if I remove the lowerFrame parameter from QViewPortControl's constructor it draws the exact same chart in a new window without slider. Am I missing something? What would you suggest?

Thank you.

  Re: Chart with slider
Posted by Peter Kwan on Oct-11-2019 03:37
Hi Oguz,

As I do not know what is "this->m_p_chart_viewer", I am unable to comment on the Qt layout of your code, such as why you need to set the parent of the QViewPortControl to be the lowerFrame, which in turns use this->m_p_chart_viewer as the parent.

It seems the QViewPortControl cannot be visible. The lowerFrame is only 64 pixels high, but you put the QViewPortControl at 355 pixels below the top edge of the frame, so it is way outside the lowerFrame. If you need an example, please use our sample code as an example.

When you use a viewport control, your code need to draw two charts:

(a) A chart that acts as a background image of the viewport control. This is usually a chart that shows the full data range.

(b) A chart that only includes the selected data range to be displayed in the QChartViewer. This chart is drawn whenever the viewport is changed.

In your code, you use the same chart for the QChartViewer and QViewPortControl, so the two charts are the same as expected. Please use the sample code as an example.

Regards
Peter Kwan