CategoryExample Class Reference
[Charts example]

A Widget that demonstrates a category chart. More...

#include <ChartsExample.h>

Inheritance diagram for CategoryExample:

Inheritance graph
[legend]

List of all members.

Public Member Functions

 CategoryExample (Wt::WContainerWidget *parent)
 Creates the category chart example.


Detailed Description

A Widget that demonstrates a category chart.

Definition at line 39 of file ChartsExample.h.


Constructor & Destructor Documentation

CategoryExample::CategoryExample ( Wt::WContainerWidget parent  ) 

Creates the category chart example.

Definition at line 71 of file ChartsExample.C.

00071                                                           :
00072   WContainerWidget(parent)
00073 {
00074   new WText(WString::tr("category chart"), this);
00075 
00076   WAbstractItemModel *model = readCsvFile("category.csv", this);
00077 
00078   if (!model)
00079     return;
00080 
00081   // Show a view that allows editing of the model.
00082   WContainerWidget *w = new WContainerWidget(this);
00083   WTableView *table = new WTableView(w);
00084 
00085   table->setMargin(10, Top | Bottom);
00086   table->setMargin(WLength::Auto, Left | Right);
00087 
00088   table->setModel(model);
00089   table->setSortingEnabled(true);
00090   table->setColumnResizeEnabled(true);
00091   table->setSelectionMode(NoSelection);
00092   table->setAlternatingRowColors(true);
00093   table->setColumnAlignment(0, AlignCenter);
00094   table->setHeaderAlignment(0, AlignCenter);
00095   table->setRowHeight(22);
00096 
00097   // Editing does not really work without Ajax, it would require an
00098   // additional button somewhere to confirm the edited value.
00099   if (WApplication::instance()->environment().ajax()) {
00100     table->resize(600, 20 + 5*22);
00101     table->setEditTriggers(WAbstractItemView::SingleClicked);
00102   } else {
00103     table->resize(600, WLength::Auto);
00104     table->setEditTriggers(WAbstractItemView::NoEditTrigger);
00105   }
00106 
00107   // We use a single delegate for all items which rounds values to
00108   // the closest integer value.
00109   WItemDelegate *delegate = new WItemDelegate(this);
00110   delegate->setTextFormat("%.f");
00111   table->setItemDelegate(delegate);
00112 
00113   table->setColumnWidth(0, 80);
00114   for (int i = 1; i < model->columnCount(); ++i)
00115     table->setColumnWidth(i, 120);
00116 
00117   /*
00118    * Create the category chart.
00119    */
00120   WCartesianChart *chart = new WCartesianChart(this);
00121   chart->setModel(model);        // set the model
00122   chart->setXSeriesColumn(0);    // set the column that holds the categories
00123   chart->setLegendEnabled(true); // enable the legend
00124 
00125   // Provide space for the X and Y axis and title. 
00126   chart->setPlotAreaPadding(100, Left);
00127   chart->setPlotAreaPadding(50, Top | Bottom);
00128 
00129   /*
00130    *   Add all (but first) column as bar series
00131    */
00132   for (int i = 1; i < model->columnCount(); ++i) {
00133     WDataSeries s(i, BarSeries);
00134     s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3));
00135     chart->addSeries(s);
00136   }
00137 
00138   chart->resize(800, 400);
00139 
00140   chart->setMargin(10, Top | Bottom);
00141   chart->setMargin(WLength::Auto, Left | Right);
00142 
00143   /*
00144    * Provide a widget to manipulate chart properties
00145    */
00146   new ChartConfig(chart, this);
00147 }


The documentation for this class was generated from the following files:

Generated on Thu May 20 18:14:56 2010 for Wt by doxygen 1.5.6