public void setNewBarChartModel() { ChartModel model = new ChartModel(valueLabel + " by " + groupLabel, chartTitleStyle); model.setBackgroundColour("#fefaee"); model.setLegend(new Legend(Position.TOP, true)); model.setScaleProvider(ScaleProvider.ROUNDED_NEAREST_SCALE_PROVIDER); // BarChart bar = new BarChart(BarStyle.GLASS); // bar.setColour("#ff0000"); // bar.setAnimateOnShow(true); // BarDataProvider barProvider = new BarDataProvider("dollarValue", "productCode"); // barProvider.bind(gridStore); // bar.setDataProvider(barProvider); // model.addChartConfig(bar); BarChart bar = new BarChart(BarStyle.GLASS); // bar.setColours(chartColors); BarDataProvider barProvider = new BarDataProvider(valueCol, groupCol) { @Override public void populateData(ChartConfig config) { BarChart chart = (BarChart) config; chart.getValues().clear(); TreeMap<String, Number> valueMap = new TreeMap<String, Number>(); TreeMap<String, String> textMap = new TreeMap<String, String>(); XAxis xAxis = null; if (labelProperty != null) { // || labelProvider != null) { xAxis = chart.getModel().getXAxis(); if (xAxis == null) { xAxis = new XAxis(); chart.getModel().setXAxis(xAxis); } xAxis.getLabels().getLabels().clear(); } for (ModelData m : store.getModels()) { Number n = (valueCol == null || valueCol.equals("count")) ? 1 : getValue(m); String label = getLabel(m); String text = getText(m); if (text == null || text.length() == 0) text = label; textMap.put(label, text); if (valueMap.containsKey(label)) valueMap.put( label, new Double(valueMap.get(label).doubleValue() + n.doubleValue())); else valueMap.put(label, n); } int color = 0; List<Bar> bars = new ArrayList<Bar>(); for (String label : valueMap.keySet()) { Bar oneBar = new Bar(valueMap.get(label), 0, chartColors[color], chartColors[color]); bars.add(oneBar); color = (color + 1) % chartColors.length; minYValue = Math.min(minYValue, valueMap.get(label).doubleValue()); maxYValue = Math.max(maxYValue, valueMap.get(label).doubleValue()); if (xAxis != null) { Label l = new Label(textMap.get(label), 45); l.setSize(10); l.setColour("#000000"); xAxis.addLabels(l); } // chart.addBars(oneBar); } chart.addBars(bars.toArray(new Bar[] {})); } }; barProvider.setTextProperty(labelCol); barProvider.bind(store); bar.setDataProvider(barProvider); model.addChartConfig(bar); chart.setChartModel(model); }
public Widget aa() { int armStatus = ArmWrapper.FAILED; try { ArmWrapper.startTransaction( this, "com.base.myproject.client.busi.b2c.manager.ChartTest", "aa", new Object[] {}); ContentPanel panel = new ContentPanel(); panel.setAutoHeight(true); ToolBar tb = new ToolBar(); Button addsuit = new Button("从商品库里添加套装商品"); addsuit.setIconStyle("b2csuit"); panel.setHeading("商品库,如果加入套装你必须先选择一行(必选)"); tb.add(addsuit); panel.setTopComponent(tb); // addsuit.addListener(Events.Select, this); panel.setAutoWidth(true); CheckBoxSelectionModel cbs = new CheckBoxSelectionModel(); List<ColumnConfig> columns = new ArrayList<ColumnConfig>(); columns.add(cbs.getColumn()); ColumnConfig gcode = new ColumnConfig("gcode", "商品大类编码", 100); TextField<String> gcodetext = new TextField<String>(); gcode.setEditor(new CellEditor(gcodetext)); columns.add(gcode); ColumnConfig gname = new ColumnConfig("discountprice", "商品大类名称", 100); TextField<String> gnametext = new TextField<String>(); gname.setEditor(new CellEditor(gnametext)); columns.add(gname); ColumnConfig treecode = new ColumnConfig("price", "商品分类树编码", 100); TextField<String> treecodetext = new TextField<String>(); treecode.setEditor(new CellEditor(treecodetext)); columns.add(treecode); ColumnConfig b2cgcodecolumn = new ColumnConfig("b2cgcode", "商品编码", 100); TextField<String> b2cgcodetext = new TextField<String>(); b2cgcodecolumn.setEditor(new CellEditor(b2cgcodetext)); columns.add(b2cgcodecolumn); ColumnConfig b2cgname = new ColumnConfig("b2cgname", "商品名称", 100); TextField<String> b2cgnametext = new TextField<String>(); b2cgname.setEditor(new CellEditor(b2cgnametext)); columns.add(b2cgname); ModelType type = new ModelType(); type.setRoot("records"); type.setRecordName("record"); type.addField("gcode"); type.addField("gname"); type.addField("b2cgcode"); type.addField("price"); type.addField("discountprice"); type.addField("b2cgname"); type.addField("mainimagepath"); type.addField("treecode"); type.addField("detailimage"); StoreInfo info = new StoreInfo(); info.setTablename("b2cgcode"); info.setKeyname(new String[] {"b2cgcode"}); info.setSql("select * from b2cgcode"); BaseStore<JDBCModelData> store = new BaseStore<JDBCModelData>(type, info); ChartModel model = new ChartModel( "Team Sales by Month", "font-size: 14px; font-family: Verdana; text-align: center;"); model.setBackgroundColour("#fefefe"); model.setLegend(new Legend(Position.TOP, true)); model.setScaleProvider(ScaleProvider.ROUNDED_NEAREST_SCALE_PROVIDER); BarChart bar = new BarChart(BarStyle.GLASS); bar.setColour("#00aa00"); BarDataProvider barProvider = new BarDataProvider("price", "b2cgname"); barProvider.bind(store); bar.setDataProvider(barProvider); // bar.addChartListener(listener); model.addChartConfig(bar); bar = new BarChart(BarStyle.GLASS); bar.setColour("#ff6600"); barProvider = new BarDataProvider("discountprice"); barProvider.bind(store); bar.setDataProvider(barProvider); // bar.addChartListener(listener); model.addChartConfig(bar); LineChart line = new LineChart(); line.setAnimateOnShow(true); line.setText("Average"); line.setColour("#FF0000"); LineDataProvider lineProvider = new LineDataProvider("discountprice"); lineProvider.bind(store); line.setDataProvider(lineProvider); model.addChartConfig(line); /* PieChart pie = new PieChart(); PieDataProvider piedataprovider = new PieDataProvider("discountprice"); piedataprovider.bind(store); pie.setDataProvider(piedataprovider); model.addChartConfig(pie);*/ String url = "chart/open-flash-chart.swf"; final Chart chart = new Chart(url); chart.setChartModel(model); chart.setHeight("300px"); ContentPanel cp = new ContentPanel(); cp.setHeading("Chart"); cp.add(chart); ColumnModel cm = new ColumnModel(columns); BaseGrid grid = new BaseGrid(store, cm); grid.setHeight("300px"); cp.add(grid); armStatus = ArmWrapper.GOOD; return cp; } finally { ArmWrapper.stopTransaction( "com.base.myproject.client.busi.b2c.manager.ChartTest", "aa", armStatus); } }