本文整理汇总了Java中com.github.mikephil.charting.components.Legend.setWordWrapEnabled方法的典型用法代码示例。如果您正苦于以下问题:Java Legend.setWordWrapEnabled方法的具体用法?Java Legend.setWordWrapEnabled怎么用?Java Legend.setWordWrapEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.github.mikephil.charting.components.Legend
的用法示例。
在下文中一共展示了Legend.setWordWrapEnabled方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateView
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_simple_scatter, container, false);
mChart = (ScatterChart) v.findViewById(R.id.scatterChart1);
mChart.getDescription().setEnabled(false);
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
mv.setChartView(mChart); // For bounds control
mChart.setMarker(mv);
mChart.setDrawGridBackground(false);
mChart.setData(generateScatterData(6, 10000, 200));
XAxis xAxis = mChart.getXAxis();
xAxis.setEnabled(true);
xAxis.setPosition(XAxisPosition.BOTTOM);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(tf);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setTypeface(tf);
rightAxis.setDrawGridLines(false);
Legend l = mChart.getLegend();
l.setWordWrapEnabled(true);
l.setTypeface(tf);
l.setFormSize(14f);
l.setTextSize(9f);
// increase the space between legend & bottom and legend & content
l.setYOffset(13f);
mChart.setExtraBottomOffset(16f);
return v;
}
示例2: setLineChart
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
/**
* Set the line chart pattern
* @param lineChart chart
* @param chartData pie chart data
* @param month data
* @param typeface Typeface font
*/
public static void setLineChart(Context context, LineChart lineChart, ChartData<?> chartData,
final String[] month, Typeface typeface) {
// apply styling
lineChart.getDescription().setEnabled(false);
lineChart.setDrawGridBackground(false);
// create a custom MarkerView (extend MarkerView) and specify the layout to use for it
SalaryMarker marker = new SalaryMarker(context, R.layout.marker_salary_detail);
marker.setChartView(lineChart); // For bounds control
lineChart.setMarker(marker);
//fix crash com.github.mikephil.charting.charts.Chart.drawMarkers(Chart.java:731)
lineChart.setDrawMarkers(false);
XAxis xAxis = lineChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setTypeface(typeface);
xAxis.setDrawGridLines(false);
xAxis.setDrawAxisLine(true);
xAxis.setValueFormatter(new LineChartValueFormatter(month));
xAxis.setLabelCount(month.length / 2, true);//xAxis label count
YAxis leftAxis = lineChart.getAxisLeft();
leftAxis.setTypeface(typeface);
leftAxis.setLabelCount(9, false);
leftAxis.setAxisMinimum(0f);
YAxis rightAxis = lineChart.getAxisRight();
rightAxis.setTypeface(typeface);
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f);
Legend l = lineChart.getLegend();
l.setWordWrapEnabled(true);
l.setTypeface(typeface);
l.setFormSize(14f);
l.setTextSize(9f);
lineChart.setData((LineData) chartData);
lineChart.animateX(DURATION_SHORT);
}
示例3: runTests
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
public void runTests() {
for (TestCaseRunner runner : mRunners) {
runner.cancel(true);
}
mRunners.clear();
mChart.clear();
BarData data = new BarData();
mChart.setData(data);
MetricsVariableAxisFormatter formatter = new MetricsVariableAxisFormatter(getMetricsTransformer());
setupYAxes(mChart);
setupXAxis(mChart, formatter);
setupDescription(mChart);
Legend legend = mChart.getLegend();
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
legend.setWordWrapEnabled(true);
legend.setOrientation(Legend.LegendOrientation.HORIZONTAL);
legend.setDrawInside(false);
mChart.invalidate();
Map<TestScenarioMetadata, TestCase[]> scenarios = getTestScenarios();
for (Map.Entry<TestScenarioMetadata, TestCase[]> scenario : scenarios.entrySet()) {
TestScenarioMetadata d = scenario.getKey();
TestCaseRunner r = new TestCaseRunner(d.iterations, mChart, d.title, d.color, formatter);
r.executeOnExecutor(TestCaseRunner.SERIAL_EXECUTOR, scenario.getValue());
mRunners.add(r);
}
}
示例4: onCreateView
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.frag_simple_scatter, container, false);
mChart = (ScatterChart) v.findViewById(R.id.scatterChart1);
mChart.setDescription("");
Typeface tf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Light.ttf");
MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
mChart.setMarkerView(mv);
mChart.setDrawGridBackground(false);
mChart.setData(generateScatterData(6, 10000, 200));
XAxis xAxis = mChart.getXAxis();
xAxis.setEnabled(true);
xAxis.setPosition(XAxisPosition.BOTTOM);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setTypeface(tf);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setTypeface(tf);
rightAxis.setDrawGridLines(false);
Legend l = mChart.getLegend();
l.setWordWrapEnabled(true);
l.setTypeface(tf);
l.setFormSize(14f);
l.setTextSize(9f);
// increase the space between legend & bottom and legend & content
l.setYOffset(13f);
mChart.setExtraBottomOffset(16f);
return v;
}
示例5: setData
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
/**
* By calling setData initializes the rest of the view
* @param data the chart data
*/
@Override
public void setData(LineData data) {
super.setData(data);
setOnChartValueSelectedListener(this);
setDescription("");
setNoDataTextDescription("No chart data");
setTouchEnabled(true);
setScaleEnabled(true);
setDragEnabled(true);
setDrawGridBackground(true);
setPinchZoom(true);
Legend legend = getLegend();
legend.setForm(Legend.LegendForm.CIRCLE);
legend.setWordWrapEnabled(true);
XAxis xAxis = getXAxis();
xAxis.setAvoidFirstLastClipping(true);
xAxis.setPosition(XAxis.XAxisPosition.TOP);
YAxis yAxisLeft = getAxisLeft();
yAxisLeft.setAxisMinValue(0);
YAxis yAxisRight = getAxisRight();
yAxisRight.setEnabled(false);
}
示例6: getFormattedPieChart
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
/**
* Formats a pie chart in a standardized way
* @param c Context
* @param p Pie chart
* @param shouldShowLegend
* @return the PieChart, whose data must be set and invalidated
*/
public static PieChart getFormattedPieChart(Context c, PieChart p, boolean shouldShowLegend) {
Legend cLegend = p.getLegend();
if (shouldShowLegend) {
cLegend.setEnabled(true);
cLegend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
cLegend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
cLegend.setOrientation(Legend.LegendOrientation.HORIZONTAL);
cLegend.setDrawInside(false);
cLegend.setForm(Legend.LegendForm.CIRCLE);
cLegend.setTextSize(15);
cLegend.setWordWrapEnabled(true);
} else {
cLegend.setEnabled(false);
}
p.setDrawEntryLabels(false);
p.setDescription(EMPTY_CHART_DESCRIPTION);
p.setHoleRadius(60f);
p.setTransparentCircleRadius(65f);
p.setCenterTextSize(20);
if (SettingsActivity.getTheme(c) == SettingsActivity.THEME_NOIR) {
int colorPrimaryNoir = ContextCompat.getColor(c, R.color.colorPrimaryNoir);
int colorPrimaryTextNoir = ContextCompat.getColor(c, R.color.colorPrimaryTextNoir);
p.setHoleColor(colorPrimaryNoir);
p.setTransparentCircleColor(colorPrimaryNoir);
p.setCenterTextColor(colorPrimaryTextNoir);
cLegend.setTextColor(colorPrimaryTextNoir);
}
p.setRotationEnabled(false);
p.setOnChartValueSelectedListener(new PieChartListener(p));
return p;
}
示例7: onCreate
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_combined);
mChart = (CombinedChart) findViewById(R.id.chart1);
mChart.getDescription().setEnabled(false);
mChart.setBackgroundColor(Color.WHITE);
mChart.setDrawGridBackground(false);
mChart.setDrawBarShadow(false);
mChart.setHighlightFullBarEnabled(false);
// draw bars behind lines
mChart.setDrawOrder(new DrawOrder[]{
DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER
});
Legend l = mChart.getLegend();
l.setWordWrapEnabled(true);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxisPosition.BOTH_SIDED);
xAxis.setAxisMinimum(0f);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return mMonths[(int) value % mMonths.length];
}
});
CombinedData data = new CombinedData();
data.setData(generateLineData());
data.setData(generateBarData());
data.setData(generateBubbleData());
data.setData(generateScatterData());
data.setData(generateCandleData());
data.setValueTypeface(mTfLight);
xAxis.setAxisMaximum(data.getXMax() + 0.25f);
mChart.setData(data);
mChart.invalidate();
}
示例8: setUpActivityChart
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
private void setUpActivityChart() {
Legend l = lineChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setTextColor(Color.WHITE);
l.setTextSize(12);
l.setWordWrapEnabled(true);
l.setXEntrySpace(UiUtils.dpToPx(4));
l.setYEntrySpace(UiUtils.dpToPx(4));
YAxis rightAxis = lineChart.getAxisRight();
rightAxis.setEnabled(false);
YAxis leftAxis = lineChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0);
leftAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return value == 0 ? "" : String.valueOf(FormatUtils.getFormattedTime(context, (int) value));
}
});
leftAxis.setGranularityEnabled(true);
leftAxis.setGranularity(3600f); // FIXME: 12-04-2017 granularity not respected
leftAxis.setAxisLineWidth(2f);
leftAxis.setTextColor(Color.WHITE);
leftAxis.setAxisLineColor(Color.WHITE);
XAxis xAxis = lineChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
xAxis.setTextColor(Color.WHITE);
xAxis.setSpaceMin(0.5f);
xAxis.setSpaceMax(0.5f);
xAxis.setYOffset(UiUtils.dpToPx(4));
xAxis.setAxisLineWidth(2f);
xAxis.setAxisLineColor(Color.WHITE);
lineChart.getDescription().setEnabled(false);
lineChart.setDrawGridBackground(false);
lineChart.setBackground(context.getResources().getDrawable(R.color.colorPrimaryDark));
lineChart.setDragEnabled(false);
lineChart.setScaleEnabled(false);
lineChart.setDragDecelerationEnabled(false);
lineChart.setPinchZoom(false);
lineChart.setDoubleTapToZoomEnabled(false);
lineChart.setDrawBorders(false);
lineChart.setExtraOffsets(16, 0, 16, 0);
}
示例9: setUpActivityChart
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
private void setUpActivityChart() {
Legend l = lineChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
l.setTextColor(Color.WHITE);
l.setTextSize(12);
l.setWordWrapEnabled(true);
l.setXEntrySpace(UiUtils.dpToPx(4));
l.setYEntrySpace(UiUtils.dpToPx(4));
YAxis rightAxis = lineChart.getAxisRight();
rightAxis.setEnabled(false);
YAxis leftAxis = lineChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0);
leftAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return value == 0 ? "" : String.valueOf(FormatUtils.getFormattedTime(context, (int) value));
}
});
leftAxis.setGranularityEnabled(true);
leftAxis.setGranularity(3600f); // FIXME: 12-04-2017 granularity not respected
leftAxis.setAxisLineWidth(2f);
leftAxis.setTextColor(Color.WHITE);
leftAxis.setAxisLineColor(Color.WHITE);
long referenceTime = new DateTime().plusDays(-7).getMillis();
XAxis xAxis = lineChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setValueFormatter(new FormatUtils().getBarXAxisValueFormatterInstance(referenceTime));
xAxis.setDrawGridLines(false);
xAxis.setTextColor(Color.WHITE);
xAxis.setSpaceMin(0.5f);
xAxis.setSpaceMax(0.5f);
xAxis.setYOffset(UiUtils.dpToPx(4));
xAxis.setAxisLineWidth(2f);
xAxis.setAxisLineColor(Color.WHITE);
CustomMarkerView customMarkerView = new CustomMarkerView(context, R.layout.marker_view, referenceTime);
lineChart.setMarker(customMarkerView);
lineChart.getDescription().setEnabled(false);
lineChart.setDrawGridBackground(false);
lineChart.setBackground(context.getResources().getDrawable(R.color.colorPrimaryDark));
lineChart.setDragEnabled(false);
lineChart.setScaleEnabled(false);
lineChart.setDragDecelerationEnabled(false);
lineChart.setPinchZoom(false);
lineChart.setDoubleTapToZoomEnabled(false);
lineChart.setDrawBorders(false);
lineChart.setExtraOffsets(16, 0, 16, 0);
customMarkerView.setChartView(lineChart);
}
示例10: initChart
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
protected void initChart() {
mCombinedChart.getDescription().setEnabled(false);
mCombinedChart.setBackgroundColor(Color.WHITE);
mCombinedChart.setDrawGridBackground(false);
mCombinedChart.setDrawBarShadow(false);
mCombinedChart.setHighlightFullBarEnabled(false);
// draw bars behind lines
mCombinedChart.setDrawOrder(new CombinedChart.DrawOrder[]{
CombinedChart.DrawOrder.BAR, CombinedChart.DrawOrder.BUBBLE,
CombinedChart.DrawOrder.CANDLE, CombinedChart.DrawOrder.LINE,
CombinedChart.DrawOrder.SCATTER
});
Legend l = mCombinedChart.getLegend();
l.setWordWrapEnabled(true);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
YAxis rightAxis = mCombinedChart.getAxisRight();
rightAxis.setDrawGridLines(false);
rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
YAxis leftAxis = mCombinedChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
XAxis xAxis = mCombinedChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTH_SIDED);
xAxis.setAxisMinimum(0f);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
return mMonths[(int) value % mMonths.length];
}
});
CombinedData data = new CombinedData();
data.setData(generateLineData());
data.setData(generateBarData());
data.setData(generateBubbleData());
data.setData(generateScatterData());
data.setData(generateCandleData());
//data.setValueTypeface(mTfLight);
xAxis.setAxisMaximum(data.getXMax() + 0.25f);
mCombinedChart.setData(data);
mCombinedChart.invalidate();
}
示例11: initChart
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
/**
* 初始化报表
*
* @param showAnimation 是否显示动画
*/
void initChart(boolean showAnimation) {
int screenWidth = Utils.getScreenWidth(mContext);
combinedChart.getLayoutParams().height = screenWidth * 300 / 640;
//启用缩放和拖动
combinedChart.setDragEnabled(true);//拖动
combinedChart.setScaleEnabled(false);//缩放
combinedChart.setOnChartValueSelectedListener(this);
combinedChart.getDescription().setEnabled(false);
combinedChart.setBackgroundColor(ContextCompat.getColor(mContext, R.color.co10));
combinedChart.setDrawGridBackground(false);
combinedChart.setDrawBarShadow(false);
combinedChart.setHighlightFullBarEnabled(false);
Legend l = combinedChart.getLegend();
l.setForm(Legend.LegendForm.NONE);//底部样式
l.setTextColor(ContextCompat.getColor(mContext, R.color.transparent));
l.setWordWrapEnabled(false);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
YAxis rightAxis = combinedChart.getAxisRight();
rightAxis.setEnabled(false);
YAxis leftAxis = combinedChart.getAxisLeft();
leftAxis.setDrawGridLines(false);
leftAxis.setGranularityEnabled(false);
leftAxis.setDrawAxisLine(false);
leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
leftAxis.setTextColor(ContextCompat.getColor(mContext, R.color.co4));
updateTitle(items.get(dateSelected));
XAxis xAxis = combinedChart.getXAxis();
xAxis.setTypeface(mTfLight);
xAxis.setEnabled(true);//设置轴启用或禁用 如果禁用以下的设置全部不生效
xAxis.setDrawAxisLine(true);//是否绘制轴线
xAxis.setDrawGridLines(false);//设置x轴上每个点对应的线
xAxis.setDrawLabels(true);//绘制标签 指x轴上的对应数值
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);//设置x轴的显示位置
xAxis.setTextSize(10f); //设置X轴文字大小
xAxis.setGranularityEnabled(true);//是否允许X轴上值重复出现
xAxis.setTextColor(ContextCompat.getColor(this, R.color.co4));//设置X轴文字颜色
// //设置竖线的显示样式为虚线
// //lineLength控制虚线段的长度
// //spaceLength控制线之间的空间
xAxis.enableGridDashedLine(10f, 10f, 0f);
xAxis.setAxisMinimum(0f);//设置x轴的最小值
xAxis.setAxisMaximum(mDatas.length);//设置最大值
xAxis.setAvoidFirstLastClipping(true);//图表将避免第一个和最后一个标签条目被减掉在图表或屏幕的边缘
xAxis.setLabelRotationAngle(0f);//设置x轴标签字体的旋转角度
// 设置x轴显示标签数量 还有一个重载方法第二个参数为布尔值强制设置数量 如果启用会导致绘制点出现偏差
xAxis.setLabelCount(10);
xAxis.setGridLineWidth(10f);//设置竖线大小
// xAxis.setGridColor(Color.RED);//设置竖线颜色
xAxis.setAxisLineColor(Color.GRAY);//设置x轴线颜色
xAxis.setAxisLineWidth(1f);//设置x轴线宽度
CombinedData combinedData = new CombinedData();
combinedData.setData(generateLineData());
combinedData.setData(generateBarData());
combinedData.setValueTypeface(mTfLight);
xAxis.setAxisMaximum(combinedData.getXMax() + 0.25f);
//X轴的数据格式
ValueFormatter xAxisFormatter = new ValueFormatter(combinedChart);
xAxisFormatter.setmValues(xAxisValue);
xAxis.setValueFormatter(xAxisFormatter);//格式化x轴标签显示字符
combinedChart.setData(combinedData);
combinedChart.invalidate();
if (showAnimation) {
combinedChart.animateY(2000);
}
}
示例12: setLegend
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
/**
* More details about legend customization: https://github.com/PhilJay/MPAndroidChart/wiki/Legend
*/
@ReactProp(name = "legend")
public void setLegend(T chart, ReadableMap propMap) {
Legend legend = chart.getLegend();
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "enabled")) {
legend.setEnabled(propMap.getBoolean("enabled"));
}
// Styling
if (BridgeUtils.validate(propMap, ReadableType.String, "textColor")) {
legend.setTextColor(Color.parseColor(propMap.getString("textColor")));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "textSize")) {
legend.setTextSize((float) propMap.getDouble("textSize"));
}
if (BridgeUtils.validate(propMap, ReadableType.String, "fontFamily") ||
BridgeUtils.validate(propMap, ReadableType.Number, "fontStyle")) {
legend.setTypeface(BridgeUtils.parseTypeface(chart.getContext(), propMap, "fontStyle", "fontFamily"));
}
// Wrapping / clipping avoidance
if (BridgeUtils.validate(propMap, ReadableType.Boolean, "wordWrapEnabled")) {
legend.setWordWrapEnabled(propMap.getBoolean("wordWrapEnabled"));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "maxSizePercent")) {
legend.setMaxSizePercent((float) propMap.getDouble("maxSizePercent"));
}
// Customizing
if (BridgeUtils.validate(propMap, ReadableType.String, "position")) {
legend.setPosition(LegendPosition.valueOf(propMap.getString("position").toUpperCase()));
}
if (BridgeUtils.validate(propMap, ReadableType.String, "form")) {
legend.setForm(LegendForm.valueOf(propMap.getString("form").toUpperCase()));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "formSize")) {
legend.setFormSize((float) propMap.getDouble("formSize"));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "xEntrySpace")) {
legend.setXEntrySpace((float) propMap.getDouble("xEntrySpace"));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "yEntrySpace")) {
legend.setYEntrySpace((float) propMap.getDouble("yEntrySpace"));
}
if (BridgeUtils.validate(propMap, ReadableType.Number, "formToTextSpace")) {
legend.setFormToTextSpace((float) propMap.getDouble("formToTextSpace"));
}
// Custom labels & colors
if (BridgeUtils.validate(propMap, ReadableType.Map, "custom")) {
ReadableMap customMap = propMap.getMap("custom");
if (BridgeUtils.validate(customMap, ReadableType.Array, "colors") &&
BridgeUtils.validate(customMap, ReadableType.Array, "labels")) {
ReadableArray colorsArray = customMap.getArray("colors");
ReadableArray labelsArray = customMap.getArray("labels");
if (colorsArray.size() == labelsArray.size()) {
// TODO null label should start a group
// TODO -2 color should avoid drawing a form
String[] labels = BridgeUtils.convertToStringArray(labelsArray);
String[] colors = BridgeUtils.convertToStringArray(colorsArray);
int[] colorsParsed = new int[colors.length];
for (int i = 0; i < colors.length; i++) {
colorsParsed[i] = Color.parseColor(colors[i]);
}
legend.setCustom(colorsParsed, labels);
}
}
}
// TODO resetCustom function
// TODO extra
chart.invalidate(); // TODO is this necessary? Looks like enabled is not refreshing without it
}
示例13: onCreate
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mChart = (CombinedChart) findViewById(R.id.chart1);
//描述
mChart.getDescription().setEnabled(false);
mChart.setBackgroundColor(Color.WHITE);
mChart.setDrawGridBackground(false);
mChart.setDrawBarShadow(false);
mChart.setHighlightFullBarEnabled(false);
mChart.setScaleEnabled(false);
mChart.setScaleYEnabled(false);
mChart.setScaleXEnabled(false);
mChart.setPinchZoom(false);
// mChart.setScaleMinima(2f, 1f);
// mChart.setAutoScaleMinMaxEnabled(true);
// draw bars behind lines
mChart.setDrawOrder(new CombinedChart.DrawOrder[]{
CombinedChart.DrawOrder.BAR
});
//图例
Legend l = mChart.getLegend();
l.setWordWrapEnabled(true);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setEnabled(false);
rightAxis.setAxisMinimum(0f);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setEnabled(false);
leftAxis.setAxisMinimum(0f);
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
// xAxis.setAvoidFirstLastClipping(true);
xAxis.setAxisMinimum(0.5f);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
if (value % 1 == 0&&value>=1) {
return mMonths[(int) value % mMonths.length-1];
} else {
return "";
}
}
});
CombinedData data = new CombinedData();
data.setData(generateBarData(1f, 1f));
xAxis.setAxisMaximum(data.getXMax() + 0.25f);
mChart.setData(data);
mChart.setVisibleXRange(3, 5);
mChart.setExtraOffsets(10, 0, 0, 0);
mChart.invalidate();
}
示例14: onCreate
import com.github.mikephil.charting.components.Legend; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mChart = (CombinedChart) findViewById(R.id.chart1);
//描述
mChart.getDescription().setEnabled(false);
mChart.setBackgroundColor(Color.WHITE);
mChart.setDrawGridBackground(false);
mChart.setDrawBarShadow(false);
mChart.setHighlightFullBarEnabled(false);
mChart.setScaleEnabled(false);
mChart.setScaleYEnabled(false);
mChart.setScaleXEnabled(false);
mChart.setPinchZoom(false);
// mChart.setScaleMinima(2f, 1f);
// mChart.setAutoScaleMinMaxEnabled(true);
// draw bars behind lines
mChart.setDrawOrder(new CombinedChart.DrawOrder[]{
CombinedChart.DrawOrder.BAR
});
//图例
Legend l = mChart.getLegend();
l.setWordWrapEnabled(true);
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
l.setDrawInside(false);
YAxis rightAxis = mChart.getAxisRight();
rightAxis.setEnabled(false);
rightAxis.setAxisMinimum(0f);
YAxis leftAxis = mChart.getAxisLeft();
leftAxis.setEnabled(false);
leftAxis.setAxisMinimum(0f);
XAxis xAxis = mChart.getXAxis();
xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
xAxis.setDrawGridLines(false);
// xAxis.setAvoidFirstLastClipping(true);
xAxis.setAxisMinimum(0.5f);
xAxis.setGranularity(1f);
xAxis.setValueFormatter(new IAxisValueFormatter() {
@Override
public String getFormattedValue(float value, AxisBase axis) {
if (value % 1 == 0&&value>=1) {
return mMonths[(int) value % mMonths.length-1];
} else {
return "";
}
}
});
CombinedData data = new CombinedData();
data.setData(generateBarData(1f, 1f));
xAxis.setAxisMaximum(data.getXMax() + 0.25f);
mChart.setData(data);
mChart.setVisibleXRange(4, 6);
mChart.setExtraOffsets(10, 0, 0, 0);
mChart.invalidate();
}