A Widget that demonstrates a category chart. More...
#include <ChartsExample.h>
Inherits Wt::WContainerWidget.
Public Member Functions | |
CategoryExample (Wt::WContainerWidget *parent) | |
Creates the category chart example. |
A Widget that demonstrates a category chart.
Definition at line 39 of file ChartsExample.h.
CategoryExample::CategoryExample | ( | Wt::WContainerWidget * | parent | ) |
Creates the category chart example.
Definition at line 66 of file ChartsExample.C.
00067 : 00068 WContainerWidget(parent) 00069 { 00070 new WText(WString::tr("category chart"), this); 00071 00072 WAbstractItemModel *model = readCsvFile("category.csv", this); 00073 00074 if (!model) 00075 return; 00076 00077 /* 00078 * If we have JavaScript, show an Ext table view that allows editing 00079 * of the model. 00080 */ 00081 if (wApp->environment().javaScript()) { 00082 WContainerWidget *w = new WContainerWidget(this); 00083 Ext::TableView *table = new Ext::TableView(w); 00084 table->setMargin(10, Top | Bottom); 00085 table->setMargin(WLength::Auto, Left | Right); 00086 table->resize(500, 175); 00087 table->setModel(model); 00088 table->setAutoExpandColumn(0); 00089 00090 table->setEditor(0, new Ext::LineEdit()); 00091 00092 for (int i = 1; i < model->columnCount(); ++i) { 00093 Ext::NumberField *nf = new Ext::NumberField(); 00094 table->setEditor(i, nf); 00095 } 00096 } 00097 00098 /* 00099 * Create the category chart. 00100 */ 00101 WCartesianChart *chart = new WCartesianChart(this); 00102 chart->setModel(model); // set the model 00103 chart->setXSeriesColumn(0); // set the column that holds the categories 00104 chart->setLegendEnabled(true); // enable the legend 00105 00106 // Provide space for the X and Y axis and title. 00107 chart->setPlotAreaPadding(100, Left); 00108 chart->setPlotAreaPadding(50, Top | Bottom); 00109 00110 //chart->axis(YAxis).setBreak(70, 110); 00111 00112 /* 00113 * Add all (but first) column as bar series 00114 */ 00115 for (int i = 1; i < model->columnCount(); ++i) { 00116 WDataSeries s(i, BarSeries); 00117 s.setShadow(WShadow(3, 3, WColor(0, 0, 0, 127), 3)); 00118 chart->addSeries(s); 00119 } 00120 00121 chart->resize(800, 400); // WPaintedWidget must be given explicit size 00122 00123 chart->setMargin(10, Top | Bottom); // add margin vertically 00124 chart->setMargin(WLength::Auto, Left | Right); // center horizontally 00125 00126 new ChartConfig(chart, this); }