Plot2d: Create a Simple Overlay Plot

Use the Plot2d Component to create a basic plot to show as an overlay item in the view.

../_images/tut_plot.png
void TutorialRunnerMainWindow::createPlot()
{
    //--------------------------------------------------------------------------
    // Create an overlay plot item and add two plot curves
    //--------------------------------------------------------------------------

    // X Values (same for both curves)
    std::vector<double> xValues = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 };

    // Y Values
    std::vector<double> y1Values = { 0.0, 1.2, 3.3, 4.0, 3.0, 2.9, 2.8, 2.7, 2.7, 2.7 };
    std::vector<double> y2Values = { 0.0, 1.5, 4.3, 5.0, 4.0, 3.8, 3.5, 3.0, 2.8, 2.7 };

    cee::PtrRef<cee::vis::Font> font = cee::vis::Font::createNormalFont();
    cee::PtrRef<cee::plt::OverlayPlot> plot = new cee::plt::OverlayPlot(font.get());
    plot->setSize(400, 300);
    plot->addCurve("First curve", xValues, y1Values);
    plot->addCurve("Second curve", xValues, y2Values);

    cee::vis::View* gcView = getTutorialView();
    gcView->overlay().addItem(plot.get(), cee::vis::OverlayItem::TOP_RIGHT, cee::vis::OverlayItem::HORIZONTAL);
    gcView->requestRedraw();
}