Java Code Examples for com.github.mikephil.charting.components.Legend#setWordWrapEnabled()

The following examples show how to use com.github.mikephil.charting.components.Legend#setWordWrapEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ScatterChartFrag.java    From StockChart-MPAndroidChart with MIT License 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.frag_simple_scatter, container, false);

    chart = v.findViewById(R.id.scatterChart1);
    chart.getDescription().setEnabled(false);

    Typeface tf = Typeface.createFromAsset(context.getAssets(), "OpenSans-Light.ttf");

    MyMarkerView mv = new MyMarkerView(getActivity(), R.layout.custom_marker_view);
    mv.setChartView(chart); // For bounds control
    chart.setMarker(mv);

    chart.setDrawGridBackground(false);
    chart.setData(generateScatterData(6, 10000, 200));

    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(true);
    xAxis.setPosition(XAxisPosition.BOTTOM);

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setTypeface(tf);

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setTypeface(tf);
    rightAxis.setDrawGridLines(false);

    Legend l = chart.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);
    chart.setExtraBottomOffset(16f);

    return v;
}
 
Example 2
Source File: TestSuiteFragment.java    From SQLite-Performance with The Unlicense 5 votes vote down vote up
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);
    }
}
 
Example 3
Source File: ScatterChartFrag.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 4
Source File: TempChart.java    From octoandroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: CombinedChartActivity.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_combined);

    setTitle("CombinedChartActivity");

    chart = findViewById(R.id.chart1);
    chart.getDescription().setEnabled(false);
    chart.setBackgroundColor(Color.WHITE);
    chart.setDrawGridBackground(false);
    chart.setDrawBarShadow(false);
    chart.setHighlightFullBarEnabled(false);

    // draw bars behind lines
    chart.setDrawOrder(new DrawOrder[]{
            DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER
    });

    Legend l = chart.getLegend();
    l.setWordWrapEnabled(true);
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setDrawGridLines(false);
    leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setAxisMinimum(0f);
    xAxis.setGranularity(1f);
    xAxis.setValueFormatter(new ValueFormatter() {
        @Override
        public String getFormattedValue(float value) {
            return months[(int) value % months.length];
        }
    });

    CombinedData data = new CombinedData();

    data.setData(generateLineData());
    data.setData(generateBarData());
    data.setData(generateBubbleData());
    data.setData(generateScatterData());
    data.setData(generateCandleData());
    data.setValueTypeface(tfLight);

    xAxis.setAxisMaximum(data.getXMax() + 0.25f);

    chart.setData(data);
    chart.invalidate();
}
 
Example 6
Source File: ChartBaseManager.java    From react-native-mp-android-chart with MIT License 4 votes vote down vote up
/**
 * 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
}
 
Example 7
Source File: StatisticsFragment.java    From openScale with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    statisticsView = inflater.inflate(R.layout.fragment_statistics, container, false);

    txtGoalWeight = statisticsView.findViewById(R.id.txtGoalWeight);
    txtGoalWeight.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    txtGoalDiff = statisticsView.findViewById(R.id.txtGoalDiff);
    txtGoalDiff.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    txtGoalDayLeft = statisticsView.findViewById(R.id.txtGoalDayLeft);
    txtGoalDayLeft.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));

    txtLabelGoalWeight = statisticsView.findViewById(R.id.txtLabelGoalWeight);
    txtLabelGoalWeight.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    txtLabelGoalDiff = statisticsView.findViewById(R.id.txtLabelGoalDiff);
    txtLabelGoalDiff.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    txtLabelDayLeft = statisticsView.findViewById(R.id.txtLabelDayLeft);
    txtLabelDayLeft.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));

    viewMeasurementsStatistics = new ArrayList<>();

    viewMeasurementsStatistics.add(new WeightMeasurementView(statisticsView.getContext()));
    viewMeasurementsStatistics.add(new WaterMeasurementView(statisticsView.getContext()));
    viewMeasurementsStatistics.add(new MuscleMeasurementView(statisticsView.getContext()));
    viewMeasurementsStatistics.add(new FatMeasurementView(statisticsView.getContext()));
    viewMeasurementsStatistics.add(new BoneMeasurementView(statisticsView.getContext()));
    viewMeasurementsStatistics.add(new BMIMeasurementView(statisticsView.getContext()));

    ArrayList<LegendEntry> legendEntriesWeek = new ArrayList<>();

    for (int i = 0; i< viewMeasurementsStatistics.size(); i++) {
        LegendEntry legendEntry = new LegendEntry();
        legendEntry.label = i + " - " + viewMeasurementsStatistics.get(i).getName().toString();
        legendEntriesWeek.add(legendEntry);
    }

    MarkerView mv = new ChartMarkerView(statisticsView.getContext(), R.layout.chart_markerview);

    radarChartWeek = statisticsView.findViewById(R.id.radarPastWeek);
    radarChartWeek.getXAxis().setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    radarChartWeek.getDescription().setEnabled(false);
    radarChartWeek.getYAxis().setEnabled(false);
    radarChartWeek.setExtraTopOffset(10);
    radarChartWeek.setRotationEnabled(false);
    Legend weekLegend = radarChartWeek.getLegend();
    weekLegend.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    weekLegend.setWordWrapEnabled(true);
    weekLegend.setExtra(legendEntriesWeek);
    weekLegend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    mv.setChartView(radarChartWeek);
    radarChartWeek.setMarker(mv);

    radarChartMonth = statisticsView.findViewById(R.id.radarPastMonth);
    radarChartMonth.getXAxis().setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    radarChartMonth.getDescription().setEnabled(false);
    radarChartMonth.getYAxis().setEnabled(false);
    radarChartMonth.setExtraTopOffset(10);
    radarChartMonth.setRotationEnabled(false);
    Legend monthLegend = radarChartMonth.getLegend();
    monthLegend.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
    monthLegend.setWordWrapEnabled(true);
    monthLegend.setExtra(legendEntriesWeek);
    monthLegend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    mv.setChartView(radarChartMonth);
    radarChartMonth.setMarker(mv);

    OpenScale.getInstance().getScaleMeasurementsLiveData().observe(getViewLifecycleOwner(), new Observer<List<ScaleMeasurement>>() {
        @Override
        public void onChanged(List<ScaleMeasurement> scaleMeasurements) {
            updateOnView(scaleMeasurements);
        }
    });

    return statisticsView;
}