If you think the Android project customhellochartdemo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package lecho.lib.hellocharts.model;
//fromwww.java2s.comimport java.util.ArrayList;
import java.util.List;
import lecho.lib.hellocharts.view.Chart;
/**
* Data for BubbleChart.
*
*/publicclass BubbleChartData extends AbstractChartData {
publicstaticfinalint DEFAULT_MIN_BUBBLE_RADIUS_DP = 6;
publicstaticfinalfloat DEFAULT_BUBBLE_SCALE = 1f;
private ValueFormatter formatter = new SimpleValueFormatter();
privateboolean hasLabels = false;
privateboolean hasLabelsOnlyForSelected = false;
privateint minBubbleRadius = DEFAULT_MIN_BUBBLE_RADIUS_DP;
privatefloat bubbleScale = DEFAULT_BUBBLE_SCALE;
// TODO: consider Collections.emptyList()
private List<BubbleValue> values = new ArrayList<BubbleValue>();
public BubbleChartData() {
};
public BubbleChartData(List<BubbleValue> values) {
setValues(values);
}
/**
* Copy constructor for deep copy.
*/public BubbleChartData(BubbleChartData data) {
super(data);
this.formatter = data.formatter;
this.hasLabels = data.hasLabels;
this.hasLabelsOnlyForSelected = data.hasLabelsOnlyForSelected;
this.minBubbleRadius = data.minBubbleRadius;
this.bubbleScale = data.bubbleScale;
for (BubbleValue bubbleValue : data.getValues()) {
this.values.add(new BubbleValue(bubbleValue));
}
}
@Override
publicvoid update(float scale) {
for (BubbleValue value : values) {
value.update(scale);
}
}
@Override
publicvoid finish() {
for (BubbleValue value : values) {
value.finish();
}
}
public List<BubbleValue> getValues() {
return values;
}
public BubbleChartData setValues(List<BubbleValue> values) {
if (null == values) {
this.values = new ArrayList<BubbleValue>();
} else {
this.values = values;
}
returnthis;
}
publicboolean hasLabels() {
return hasLabels;
}
public BubbleChartData setHasLabels(boolean hasLabels) {
this.hasLabels = hasLabels;
if (hasLabels) {
hasLabelsOnlyForSelected = false;
}
returnthis;
}
/**
* @see #setHasLabelsOnlyForSelected(boolean)
*/publicboolean hasLabelsOnlyForSelected() {
return hasLabelsOnlyForSelected;
}
/**
* Set true if you want to show value labels only for selected value, works best when chart has
* isValueSelectionEnabled set to true {@link Chart#setValueSelectionEnabled(boolean)}.
*/public BubbleChartData setHasLabelsOnlyForSelected(boolean hasLabelsOnlyForSelected) {
this.hasLabelsOnlyForSelected = hasLabelsOnlyForSelected;
if (hasLabelsOnlyForSelected) {
this.hasLabels = false;
}
returnthis;
}
/**
* Returns minimal bubble radius in dp.
*
* @see #setMinBubbleRadius(int)
*/publicint getMinBubbleRadius() {
return minBubbleRadius;
}
/**
* Set minimal bubble radius in dp, helpful when you want small bubbles(bubbles with very small z values compared to
* other bubbles) to be visible on chart, default 6dp
*/publicvoid setMinBubbleRadius(int minBubbleRadius) {
this.minBubbleRadius = minBubbleRadius;
}
/**
* Returns bubble scale which is used to adjust bubble size.
*
* @see #setBubbleScale(float)
*/publicfloat getBubbleScale() {
return bubbleScale;
}
/**
* Set bubble scale which is used to adjust bubble size. If you want smaller bubbles set scale <0, 1>, if you want
* bigger bubbles set scale >1, default 1.0f.
*/publicvoid setBubbleScale(float bubbleScale) {
this.bubbleScale = bubbleScale;
}
public ValueFormatter getFormatter() {
return formatter;
}
public BubbleChartData setFormatter(ValueFormatter formatter) {
if (null == formatter) {
this.formatter = new SimpleValueFormatter();
} else {
this.formatter = formatter;
}
returnthis;
}
publicstatic BubbleChartData generateDummyData() {
finalint numValues = 4;
BubbleChartData data = new BubbleChartData();
List<BubbleValue> values = new ArrayList<BubbleValue>(numValues);
values.add(new BubbleValue(0, 20, 15000));
values.add(new BubbleValue(3, 22, 20000));
values.add(new BubbleValue(5, 25, 5000));
values.add(new BubbleValue(7, 30, 30000));
values.add(new BubbleValue(11, 22, 10));
data.setValues(values);
return data;
}
}