Created
July 25, 2019 01:05
Star
You must be signed in to star a gist
sencha gxt stacked bar bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.google.gwt.core.client.GWT; | |
import com.sencha.gxt.chart.client.chart.Chart; | |
import com.sencha.gxt.chart.client.chart.axis.CategoryAxis; | |
import com.sencha.gxt.chart.client.chart.axis.NumericAxis; | |
import com.sencha.gxt.chart.client.chart.series.BarSeries; | |
import com.sencha.gxt.chart.client.chart.series.LineSeries; | |
import com.sencha.gxt.chart.client.chart.series.Primitives; | |
import com.sencha.gxt.chart.client.draw.RGB; | |
import com.sencha.gxt.chart.client.draw.sprite.Sprite; | |
import com.sencha.gxt.core.client.ValueProvider; | |
import com.sencha.gxt.core.client.util.Margins; | |
import com.sencha.gxt.data.shared.ListStore; | |
import com.sencha.gxt.data.shared.PropertyAccess; | |
import com.sencha.gxt.widget.core.client.container.VerticalLayoutContainer; | |
import java.io.Serializable; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.List; | |
public class StackedBar extends VerticalLayoutContainer { | |
public class MyBean implements Serializable { | |
private static final long serialVersionUID = 1L; | |
private String name; | |
private Double value; | |
public MyBean() { | |
} | |
public MyBean(String name, Double value) { | |
this.name = name; | |
this.value = value; | |
} | |
public String getName() { | |
return name; | |
} | |
public double getValue() { | |
return value; | |
} | |
} | |
public interface MyProperties extends PropertyAccess<MyBean> { | |
ValueProvider<MyBean, String> name(); | |
ValueProvider<MyBean, Double> value(); | |
} | |
private MyProperties properties = GWT.create(MyProperties.class); | |
public StackedBar() { | |
clear(); | |
final ListStore<MyBean> listStore = new ListStore<>(MyBean::getName); | |
listStore.addAll(sampleDataList()); | |
NumericAxis<MyBean> axis = new NumericAxis<>(); | |
axis.setPosition(Chart.Position.BOTTOM); | |
// if these two lines are commented out the series and the bar chart are plotted at identical points | |
axis.setMinimum(995); | |
axis.setMaximum(1010); | |
// all points are within range | |
axis.setHidden(false); | |
axis.addField(properties.value()); // this is using the same data as green line series | |
axis.setDisplayGrid(false); | |
CategoryAxis<MyBean, String> catAxis = new CategoryAxis<>(); | |
catAxis.setPosition(Chart.Position.LEFT); | |
catAxis.setField(properties.name()); | |
final BarSeries<MyBean> bar = new BarSeries<>(); | |
bar.setYAxisPosition(Chart.Position.BOTTOM); | |
bar.addYField(properties.value()); | |
bar.addColor(RGB.GREEN); | |
bar.setStacked(true); | |
Sprite greenMarker = Primitives.circle(0, 0, 6); | |
greenMarker.setFill(RGB.GREEN); | |
final LineSeries<MyBean> bidLineSeries = new LineSeries<>(); | |
bidLineSeries.setXAxisPosition(Chart.Position.BOTTOM); | |
bidLineSeries.setXField(properties.value()); | |
bidLineSeries.setStroke(RGB.GREEN); | |
bidLineSeries.setStrokeWidth(1); | |
bidLineSeries.setShowMarkers(true); | |
bidLineSeries.setMarkerConfig(greenMarker); | |
final Chart<MyBean> chart = new Chart<>(); | |
chart.setStore(listStore); | |
chart.setShadowChart(false); | |
chart.addAxis(axis); | |
chart.addAxis(catAxis); | |
// the below two series are using the same data | |
chart.addSeries(bar); | |
chart.addSeries(bidLineSeries); | |
add(chart, new VerticalLayoutData(1, 1, new Margins(0, 0, 0, 0))); | |
chart.redrawChart(); | |
forceLayout(); | |
} | |
private Collection<MyBean> sampleDataList() { | |
List<MyBean> myBeanList = new ArrayList<>(5); | |
myBeanList.add(new MyBean( "01 testSec",1004.0D )); | |
myBeanList.add(new MyBean( "02 testSec",1005.0D )); | |
myBeanList.add(new MyBean( "03 testSec",1002.5D )); | |
myBeanList.add(new MyBean( "04 testSec",1003.0D )); | |
myBeanList.add(new MyBean( "05 testSec",1005.0D )); | |
return myBeanList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment