Skip to content

Commit

Permalink
Merge pull request #68 from Arman92/patch1
Browse files Browse the repository at this point in the history
Added Selection listener for BarLine  charts, added a sample in README
  • Loading branch information
hongyin163 authored Jan 9, 2017
2 parents 299da55 + 4792921 commit 67746c4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ var Component = React.createClass({
<TitleBar/>
<View style={styles.chartContainer}>
<BarChart style={{flex:1}} data={this.getBarData()}/>

<BarChart
style={{flex:1}}
data={this.getRandomData()}
Expand All @@ -149,6 +150,37 @@ var Component = React.createClass({
description={"测试"}
legend={{enable:true,position:'ABOVE_CHART_LEFT',direction:"LEFT_TO_RIGHT"}}
/>

<LineChart
style={{flex:1}}
data={this.getRandomData()}
visibleXRange={[0,30]}
maxVisibleValueCount={50}
xAxis={{
drawGridLines:false,
gridLineWidth:1,
position:"BOTTOM",
labelRotationAngle: 12.0,
spaceBetweenLabels: 10,
}}
yAxisRight={{enable:false}}
yAxis={{
startAtZero:false,
drawGridLines:true,
position:"OUTSIDE_CHART",
textColor: "#E94343"
}}
drawGridBackground={false}
backgroundColor={"#FAFAFA"}
description={"Line Chart sample"}
legend={{enable:true,position:'ABOVE_CHART_LEFT',direction:"LEFT_TO_RIGHT", legendForm: "CIRCLE"}}
pinchZoom={true}
dragDecelerationFrictionCoef={0.5}
noDataText={"No data available"}
onSelect={(e) => {
console.log("onSelect xIndex", e.nativeEvent.xIndex, "yValue:", e.nativeEvent.yValue);
}}
/>
</View>
</View>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class MPBarLineChartManager extends SimpleViewManager<BarLineChartBase> {
private BarChart chart;
private BarData data;
private BarDataSet dataSet;

@Override
public String getName() {
return this.CLASS_NAME;
Expand Down Expand Up @@ -63,6 +64,9 @@ protected BarLineChartBase createViewInstance(ThemedReactContext reactContext) {
chart.animateY(3000);
//图表描述
chart.setDescription("公司前半年财务报表(单位:万元)");*/
new MPChartSelectionEventListener(chart);


return chart;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.github.mikephil.charting.charts.BarLineChartBase;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;

import com.github.mikephil.charting.data.Entry;
Expand All @@ -19,11 +19,11 @@
* use eventName 'topSelect' mapping to 'onSelect' callback prop in JS
*/
public class MPChartSelectionEventListener implements OnChartValueSelectedListener {
private BarLineChartBase chart=null;
private Chart chart=null;
public MPChartSelectionEventListener(){

}
public MPChartSelectionEventListener(BarLineChartBase chart){
public MPChartSelectionEventListener(Chart chart){
this.chart=chart;

// bind selection callback listener to chart
Expand Down

0 comments on commit 67746c4

Please sign in to comment.