Hello,
I am writing a simple test application to understand Tables and Charts
in Wt. Please find the test code attached with this post. I have
tested this code only on FF 17.0.1 on Ubuntu 12.04. I am seeing the
following anomaly with the output of this program:
1. The chart is not visible when the application is opened. The
browser is required to be resized to make the chart visible i.e. it is
only visible when the browser is resized.
2. When the browser is maximised then the chart does not resize to the
size of its fluid container i.e. the chart remains at the same size
that was before resizing.
What am I doing wrong in the attached code?
Thanks and regards,
~Plug
cmake_minimum_required(VERSION 2.8)
set(PROJECT_NAME testtablechart)
project(${PROJECT_NAME})
list(APPEND CMAKE_CXX_FLAGS "--std=c++0x")
set(CMAKE_BUILD_TYPE Debug)
find_package(Wt REQUIRED)
include_directories(${Wt_INCLUDE_DIR})
add_executable(${PROJECT_NAME}.wt test_table_chart.cpp)
target_link_libraries(${PROJECT_NAME}.wt ${Wt_HTTP_DEBUG_LIBRARY}
${Wt_DEBUG_LIBRARY})
#include <Wt/Chart/WCartesianChart>
#include <Wt/WStandardItemModel>
#include <Wt/WContainerWidget>
#include <Wt/WItemDelegate>
#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <Wt/WVBoxLayout>
#include <Wt/WTableView>
#include <Wt/WString>
#include <boost/any.hpp>
using namespace Wt;
class TestWidget : public WContainerWidget
{
public:
TestWidget(WContainerWidget *pParent = 0)
: WContainerWidget(pParent)
{
WVBoxLayout *pLayout = new WVBoxLayout();
WAbstractItemModel *pModel = CreateModel();
AddTable(pModel, pLayout);
AddChart(pModel, pLayout);
setLayout(pLayout);
}
protected:
WAbstractItemModel* CreateModel()
{
FruitData data{2163, 1336, {{"Mango", 651, 601}, {"Banana", 752, 402}, {"Orange", 367, 200}, {"Apple", 453, 133}}};
WStandardItemModel *pModel = new WStandardItemModel(data.m_Fruits.size(), 4, this);
pModel->setHeaderData(0, boost::any(WString("Fruit")));
pModel->setHeaderData(1, boost::any(WString("% OKs")));
pModel->setHeaderData(2, boost::any(WString("% Favourites")));
pModel->setHeaderData(3, boost::any(WString("% Not Favourites")));
int iRow = 0;
for(auto fruit : data.m_Fruits) {
pModel->setData(iRow, 0, boost::any(fruit.m_strName));
pModel->setData(iRow, 1, boost::any(fruit.m_ulOKs * 100.0 / data.m_ulTotalOKs));
pModel->setData(iRow, 2, boost::any(fruit.m_ulFavourites * 100.0 / data.m_ulTotalFavourites));
pModel->setData(iRow, 3, boost::any((fruit.m_ulOKs - fruit.m_ulFavourites) * 100.0 / (data.m_ulTotalOKs - data.m_ulTotalFavourites)));
++iRow;
}
return pModel;
}
void AddTable(WAbstractItemModel *pModel, WBoxLayout *pLayout)
{
WTableView *pTable = new WTableView();
pTable->setModel(pModel);
pTable->setSortingEnabled(true);
pTable->setColumnResizeEnabled(true);
pTable->setAlternatingRowColors(true);
pTable->setColumnAlignment(0, AlignCenter);
pTable->setHeaderAlignment(0, AlignCenter);
pTable->resize(WLength(100, WLength::Percentage), /*WLength(100, WLength::Percentage)*/WLength::Auto);
pTable->decorationStyle().setBorder(WBorder(WBorder::Solid, WBorder::Thin, WColor(255, 0, 0)));
pLayout->addWidget(pTable, 0);
}
void AddChart(WAbstractItemModel *pModel, WBoxLayout *pLayout)
{
Chart::WCartesianChart *pChart = new Chart::WCartesianChart();
pChart->setModel(pModel);
pChart->setXSeriesColumn(0);
pChart->setLegendEnabled(true);
for (int i = 1; i < pModel->columnCount(); ++i) {
Chart::WDataSeries s(i, Chart::BarSeries);
s.setLabelsEnabled(Chart::YAxis);
s.setLegendEnabled(true);
pChart->addSeries(s);
}
pChart->initLayout();
pChart->axis(Chart::YAxis).setVisible(false);
pChart->setLegendEnabled(true);
pChart->setLegendLocation(Chart::LegendOutside, Top, AlignCenter);
pChart->setLegendColumns(pModel->columnCount() - 1, WLength(8, WLength::FontEm));
//pChart->resize(WLength(100, WLength::Percentage), /*WLength(100, WLength::Percentage)*/WLength::Auto);
pChart->decorationStyle().setBorder(WBorder(WBorder::Solid, WBorder::Thin, WColor(0, 0, 255)));
pLayout->addWidget(pChart, 1);
}
private:
class FruitData
{
public:
class Fruit {
public:
WString m_strName;
unsigned long m_ulOKs;
unsigned long m_ulFavourites;
};
unsigned long m_ulTotalOKs;
unsigned long m_ulTotalFavourites;
std::vector<Fruit> m_Fruits;
};
};
class TestChart : public WApplication
{
public:
TestChart(const WEnvironment& env)
: WApplication(env)
{
(new WVBoxLayout(root()))->addWidget(new TestWidget(), 1);
}
};
WApplication* createApplication(const WEnvironment& env)
{
return new TestChart(env);
}
int main(int argc, char *argv[])
{
return WRun(argc, argv, &createApplication);
}
------------------------------------------------------------------------------
Master HTML5, CSS3, ASP.NET, MVC, AJAX, Knockout.js, Web API and
much more. Get web development skills now with LearnDevNow -
350+ hours of step-by-step video tutorials by Microsoft MVPs and experts.
SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122812
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest