Project

General

Profile

WCartesianChart relative size

Added by Marcelo Antunes over 2 years ago

I'm trying to create a cartesian chart whith that code:

    graf=t->bindWidget("gra",std::make_unique<Wt::Chart::WCartesianChart>(Wt::Chart::ChartType::Category));
    graf->setStyleClass("custom-chart");
    graf->setModel(model);
    graf->setXSeriesColumn(1);
    graf->setPlotAreaPadding(40, Wt::Side::Left | Wt::Side::Top | Wt::Side::Bottom);
    graf->setPlotAreaPadding(120, Wt::Side::Right);
    auto ser = std::make_unique<Wt::Chart::WDataSeries>(2, Wt::Chart::SeriesType::Bar);
    ser->setBrush(Wt::WBrush(Wt::WColor(0,51,255)));
    graf->addSeries(std::move(ser));
    graf->yAxis(0).setMinimum(0);
    graf->yAxis(0).setMaximum(5);
    graf->resize(Wt::WLength(100,Wt::LengthUnit::Percentage),Wt::WLength(400));
    graf->resize(700, 400);
    graf->setMargin(Wt::WLength::Auto, Wt::Side::Left | Wt::Side::Right);

Then after i try to resize it with that code:

 gra->resize(Wt::WLength(100,Wt::LengthUnit::Percentage),Wt::WLength(400));

When i run the code, the chart dosen't show. But if i change the resize code to next code, it shows correctly.
Bui i need the set the size relative instead of absolute, in order to be responsive.

    gra->resize(700, 400);

Could you please tell me what is the problem?


Replies (1)

RE: WCartesianChart relative size - Added by Bruce Toll over 2 years ago

Hi,

A WCartesianChart is a specialized WPaintedWidget, so I believe that you need to provide fixed sizes in resize() or place the WCartesianChart in a Wt Layout (which is probably what you want). See the note in the Detailed Description on this page: https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WPaintedWidget.html. Wt Layouts are documented here: https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WLayout.html and in the Widget Gallery: https://www.webtoolkit.eu/widgets/layout/layout-managers.

    (1-1/1)