/* * Isomorphic SmartGWT web presentation layer * Copyright 2016 and beyond Isomorphic Software, Inc. * * OWNERSHIP NOTICE * Isomorphic Software owns and reserves all rights not expressly granted in this source code, * including all intellectual property rights to the structure, sequence, and format of this code * and to all designs, interfaces, algorithms, schema, protocols, and inventions expressed herein. * * If you have any questions, please email
. * * This entire comment must accompany any portion of Isomorphic Software source code that is * copied or moved from this file. */ package com.smartgwt.sample.showcase.client.chart; import java.util.Map; import java.util.HashMap; import java.util.LinkedHashMap; import com.smartgwt.client.data.Criteria; import com.smartgwt.client.data.Record; import com.smartgwt.client.types.ChartType; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.FormItem; import com.smartgwt.client.widgets.form.fields.SelectItem; import com.smartgwt.client.widgets.form.fields.events.ChangedEvent; import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; import com.smartgwt.client.widgets.chart.FacetChart; import com.smartgwt.client.widgets.chart.ColorMapper; import com.smartgwt.client.widgets.cube.Facet; import com.smartgwt.client.widgets.cube.FacetValue; import com.smartgwt.client.widgets.layout.VLayout; import com.google.gwt.core.client.EntryPoint; public class HistogramChart implements EntryPoint { public FacetChart chart; public DynamicForm configForm; private DynamicForm getConfigForm() { final SelectItem zOrderItem = new SelectItem("zOrder", "Z-Ordering"); zOrderItem.setWrapTitle(false); zOrderItem.setAllowEmptyValue(true); zOrderItem.setEmptyDisplayValue("Draw order (default)"); zOrderItem.setValueMap(new LinkedHashMap
() {{ put("danger", "Use 'danger' Metric"); }}); zOrderItem.addChangedHandler(new ChangedHandler() { public void onChanged(ChangedEvent event) { chart.setZIndexMetric((String)event.getValue()); } }); final SelectItem borderColorItem = new SelectItem("borderColor", "Border Color"); borderColorItem.setWrapTitle(false); borderColorItem.setValueMap(new String[]{"Grey", "Orange", "Cyan"}); borderColorItem.setDefaultToFirstOption(true); borderColorItem.setVisible(!chart.getMatchBarChartDataLineColor()); borderColorItem.addChangedHandler(new ChangedHandler() { public void onChanged(ChangedEvent event) { chart.setData(chart.getDataAsRecordList()); } }); configForm = new DynamicForm(); configForm.setNumCols(4); configForm.setWidth(500); configForm.setItems(zOrderItem, borderColorItem); return configForm; } private Map
lineColors = new HashMap
() {{ put("Grey", "#333333"); put("Orange", "#FF8C00"); put("Cyan", "#00FFFF"); }}; private Map
dataColors = new HashMap
() {{ put("Metals", "#DC143C"); put("Organics", "#7FFF00"); put("Pathogens", "#0000FF"); }}; @Override public void onModuleLoad() { chart = new FacetChart(); chart.setID("histogram"); chart.setTitle("Measured Pollutant Levels"); chart.setShowValueOnHover(true); chart.setChartType(ChartType.HISTOGRAM); chart.setAllowedChartTypes(new ChartType[] {ChartType.BAR, ChartType.COLUMN, ChartType.HISTOGRAM}); chart.setValueProperty("minValue"); chart.setEndValueMetric("maxValue"); Facet metricFacet = new Facet("valueMetrics"); metricFacet.setInlinedValues(true); metricFacet.setValues(new FacetValue("minValue"), new FacetValue("maxValue"), new FacetValue("danger")); chart.setFacets(new Facet("water", "Water Source"), new Facet("pollutant", "Pollutant"), metricFacet); chart.setMetricFacetId("valueMetrics"); chart.setData(HistogramChartData.getData()); // override the default chart segment colors chart.setDataLineColorMapper(new ColorMapper() { @Override public String getColor(int index, Object facetValueId, String purpose) { FormItem item = configForm.getItem("borderColor"); return (String) lineColors.get(item.getValue()); } }); chart.setDataColorMapper(new ColorMapper() { @Override public String getColor(int index, Object facetValueId, String purpose) { return (String) dataColors.get(facetValueId); } }); VLayout layout = new VLayout(); layout.setWidth100(); layout.setHeight100(); layout.setMembers(getConfigForm(), chart); layout.draw(); } }