Java Code Examples for com.github.mikephil.charting.components.XAxis#setDrawAxisLine()

The following examples show how to use com.github.mikephil.charting.components.XAxis#setDrawAxisLine() . 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: FragmentTimeBarChart.java    From fingen with Apache License 2.0 5 votes vote down vote up
private void setupBarChart() {
    mBarChart.setDrawBarShadow(false);
    mBarChart.setDrawValueAboveBar(true);
    mBarChart.setDescription("");
    mBarChart.setMaxVisibleValueCount(Integer.MAX_VALUE);
    mBarChart.setPinchZoom(false);
    mBarChart.setDrawGridBackground(false);
    mBarChart.setOnChartValueSelectedListener(this);
    mBarChart.setHighlightPerDragEnabled(false);

    int textColor = ColorUtils.getTextColor(getActivity());

    XAxis xl = mBarChart.getXAxis();
    xl.setPosition(XAxis.XAxisPosition.BOTTOM_INSIDE);
    xl.setDrawAxisLine(true);
    xl.setDrawGridLines(true);
    xl.setGridLineWidth(0.3f);
    xl.setTextColor(textColor);

    YAxis yl = mBarChart.getAxisLeft();
    yl.setDrawAxisLine(true);
    yl.setDrawGridLines(true);
    yl.setGridLineWidth(0.3f);
    yl.setAxisMinValue(0f);
    yl.setTextColor(textColor);

    YAxis yr = mBarChart.getAxisRight();
    yr.setDrawAxisLine(true);
    yr.setDrawGridLines(false);
    yr.setAxisMinValue(0f);
    yr.setTextColor(textColor);

    mBarChart.setXAxisRenderer(new FgHorizontalBarChartRenderer(getActivity(), mBarChart.getViewPortHandler(),
            mBarChart.getXAxis(), mBarChart.getTransformer(YAxis.AxisDependency.LEFT), mBarChart));
    mBarChart.getLegend().setEnabled(false);
}
 
Example 2
Source File: BarGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public BarGraph(Context context, BarChart chart, String name) {
    mChart = chart;
    mChartName = name;
    mChart.setHorizontalScrollBarEnabled(true);
    mChart.setVerticalScrollBarEnabled(true);
    mChart.setDrawBorders(true);
    mChart.setNoDataText(context.getString(R.string.no_chart_data_available));

    mContext = context;
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    l.setEnabled(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextColor(ColorTemplate.getHoloBlue());
    xAxis.setDrawAxisLine(false);
    xAxis.setGranularityEnabled(true);
    xAxis.setGranularity(1f);

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setAxisMinimum(0f);
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setTextColor(ColorTemplate.getHoloBlue());
    leftAxis.setGranularityEnabled(true);
    leftAxis.setGranularity((float) 1);

    mChart.setFitBars(true);
    leftAxis.setAxisMinimum(0f);

    mChart.getAxisRight().setEnabled(false);
}
 
Example 3
Source File: PowerChart.java    From AndroidApp with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setFormatting() {
    powerChart.setDrawGridBackground(false);
    powerChart.getLegend().setEnabled(false);
    powerChart.getAxisRight().setEnabled(false);
    powerChart.getDescription().setEnabled(false);
    powerChart.setNoDataText("");
    powerChart.setHardwareAccelerationEnabled(true);

    YAxis yAxis = powerChart.getAxisLeft();
    yAxis.setEnabled(true);
    yAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    yAxis.setDrawTopYLabelEntry(false);
    yAxis.setDrawGridLines(false);
    yAxis.setDrawAxisLine(false);
    yAxis.setTextColor(ContextCompat.getColor(context, R.color.lightGrey));
    yAxis.setTextSize(context.getResources().getInteger(R.integer.chartDateTextSize));
    yAxis.setValueFormatter(new IntegerYAxisValueFormatter());

    XAxis xAxis = powerChart.getXAxis();
    xAxis.setDrawAxisLine(false);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawLabels(true);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextColor(ContextCompat.getColor(context, R.color.lightGrey));
    xAxis.setValueFormatter(new HoursMinutesXAxisValueFormatter(chartLabels));

    xAxis.setTextSize(context.getResources().getInteger(R.integer.chartDateTextSize));
}
 
Example 4
Source File: MeasurementActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
public void initVueMeter(){
    mChart.setDrawBarShadow(false);
    mChart.setDescription("");
    mChart.setPinchZoom(false);
    mChart.setDrawGridBackground(false);
    mChart.setMaxVisibleValueCount(0);
    mChart.setScaleXEnabled(false); // Disable scaling on the X-axis
    // XAxis parameters: hide all
    XAxis xlv = mChart.getXAxis();
    xlv.setPosition(XAxisPosition.BOTTOM);
    xlv.setDrawAxisLine(false);
    xlv.setDrawGridLines(false);
    xlv.setDrawLabels(false);
    // YAxis parameters (left): main axis for dB values representation
    YAxis ylv = mChart.getAxisLeft();
    ylv.setDrawAxisLine(false);
    ylv.setDrawGridLines(true);
    ylv.setAxisMaxValue(110.f);
    ylv.setStartAtZero(true);
    ylv.setTextColor(Color.WHITE);
    ylv.setGridColor(Color.WHITE);
    ylv.setValueFormatter(new dBValueFormatter());
    // YAxis parameters (right): no axis, hide all
    YAxis yrv = mChart.getAxisRight();
    yrv.setEnabled(false);
    //return true;
}
 
Example 5
Source File: ModelDetailActivity.java    From Synapse with Apache License 2.0 5 votes vote down vote up
private void setXAxis(int epochs) {
    final XAxis axis = mChart.getXAxis();
    axis.setEnabled(true);
    axis.setAxisMinimum(1F);
    axis.setAxisMaximum(epochs);
    axis.setPosition(XAxis.XAxisPosition.BOTTOM);
    axis.setDrawAxisLine(true);
    axis.setDrawGridLines(false);
    axis.setGranularity(1F);
    axis.setAvoidFirstLastClipping(true);

    mChart.getAxisRight().setDrawAxisLine(true);
}
 
Example 6
Source File: CalibrationLinearityActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void initLine() {
    LineChart lineChart = getLineChart();
    if(lineChart == null) {
        return;
    }
    lineChart.setDescription("");

    lineChart.setDrawGridBackground(false);

    // enable scaling and dragging

    Legend l = lineChart.getLegend();
    l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
    l.setTextColor(Color.WHITE);

    YAxis yl = lineChart.getAxisLeft();
    yl.setTextColor(Color.WHITE);
    yl.setGridColor(Color.WHITE);
    lineChart.getAxisRight().setEnabled(false);

    XAxis xl = lineChart.getXAxis();
    xl.setDrawGridLines(false);
    xl.setTextColor(Color.WHITE);
    xl.setGridColor(Color.WHITE);
    xl.setPosition(XAxis.XAxisPosition.BOTTOM);
    xl.setDrawAxisLine(true);
    xl.setLabelRotationAngle(-90);
    xl.setDrawLabels(true);
    xl.setLabelsToSkip(0);
}
 
Example 7
Source File: RecordingsAdapter.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Setup chart (axis, grid, etc.).
 *
 * @param lineChart      chart to setup.
 * @param data           chart with the data.
 * @param firstTimestamp seconds timestamp of the first record (used as initial reference).
 */
private void setupChart(LineChart lineChart, LineData data, long firstTimestamp) {
    // General setup
    lineChart.setDrawGridBackground(false);
    lineChart.setDrawBorders(false);
    lineChart.setViewPortOffsets(50, 0, 50, 50);
    lineChart.getDescription().setEnabled(false);
    lineChart.getLegend().setEnabled(false);
    lineChart.setTouchEnabled(false);
    lineChart.setNoDataText(context.getString(R.string.no_flight_act_data_available));
    // X axis setup
    IAxisValueFormatter xAxisFormatter = new HourAxisValueFormatter(firstTimestamp);
    XAxis xAxis = lineChart.getXAxis();
    xAxis.setValueFormatter(xAxisFormatter);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setCenterAxisLabels(false);
    xAxis.setTextColor(ContextCompat.getColor(context, R.color.colorIcons));
    // Y axis setup
    YAxis yAxis = lineChart.getAxisLeft();
    yAxis.setAxisMaximum(40);
    yAxis.setAxisMinimum(0);
    yAxis.setDrawLabels(false);
    yAxis.setDrawAxisLine(false);
    yAxis.setDrawGridLines(true);
    lineChart.getAxisRight().setEnabled(false);
    // Add data
    lineChart.setData(data);
}
 
Example 8
Source File: BarChartCard.java    From ResearchStack with Apache License 2.0 4 votes vote down vote up
private void initializeViews() {
    titleTextView = (TextView) findViewById(R.id.view_chart_bar_title);
    titleTextView.setText(titleText);
    titleTextView.setTextColor(titleTextColor);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);
    titleTextView.setTypeface(Typeface.create(titleTextTypeface, Typeface.NORMAL));

    expand = (ImageView) findViewById(R.id.view_chart_line_expand);
    if (expandTintColor != 0) {
        Drawable drawable = expand.getDrawable();
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, expandTintColor);
        expand.setImageDrawable(drawable);
    }

    chart = (BarChart) findViewById(R.id.view_chart_bar);
    chart.getLegend().setEnabled(false);
    chart.setDescription("");
    chart.setDrawBorders(false);
    chart.setDrawValueAboveBar(false);
    chart.setDrawGridBackground(false);
    chart.setDrawBarShadow(false);
    chart.setDrawHighlightArrow(false);
    chart.setPinchZoom(false);
    chart.setExtraLeftOffset(0);
    chart.setExtraRightOffset(0);
    chart.setExtraBottomOffset(8);
    chart.setExtraTopOffset(0);
    chart.setTouchEnabled(true);
    chart.setDragEnabled(true);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawAxisLine(false);
    xAxis.setYOffset(16);
    xAxis.setDrawGridLines(false);
    xAxis.setLabelsToSkip(0);
    xAxis.setTextSize(chartXAxisTextSize);
    xAxis.setTextColor(chartXAxisTextColor);
    xAxis.setTypeface(Typeface.create(chartXAxisTextTypeface, Typeface.NORMAL));

    YAxis yAxisLeft = chart.getAxisLeft();
    yAxisLeft.setDrawAxisLine(false);
    yAxisLeft.setDrawGridLines(false);
    yAxisLeft.setDrawZeroLine(false);
    yAxisLeft.setDrawLabels(false);

    YAxis yAxisRight = chart.getAxisRight();
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawZeroLine(false);
    yAxisRight.setDrawLabels(false);
}
 
Example 9
Source File: LineChartActivity2.java    From Stayfit with Apache License 2.0 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_linechart);

        tvX = (TextView) findViewById(R.id.tvXMax);
        tvY = (TextView) findViewById(R.id.tvYMax);
        mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
        mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

        mSeekBarX.setProgress(45);
        mSeekBarY.setProgress(100);

        mSeekBarY.setOnSeekBarChangeListener(this);
        mSeekBarX.setOnSeekBarChangeListener(this);

        mChart = (LineChart) findViewById(R.id.chart1);
        mChart.setOnChartValueSelectedListener(this);
        
        // no description text
        mChart.setDescription("");
        mChart.setNoDataTextDescription("You need to provide data for the chart.");

        // enable touch gestures
        mChart.setTouchEnabled(true);
        
        mChart.setDragDecelerationFrictionCoef(0.9f);

        // enable scaling and dragging
        mChart.setDragEnabled(true);
        mChart.setScaleEnabled(true);
        mChart.setDrawGridBackground(false);
        mChart.setHighlightPerDragEnabled(true);

        // if disabled, scaling can be done on x- and y-axis separately
        mChart.setPinchZoom(true);

        // set an alternative background color
        mChart.setBackgroundColor(Color.LTGRAY);

        // add data
        setData(20, 30);

        mChart.animateX(2500);

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

        // get the legend (only possible after setting data)
        Legend l = mChart.getLegend();

        // modify the legend ...
        // l.setPosition(LegendPosition.LEFT_OF_CHART);
        l.setForm(LegendForm.LINE);
        l.setTypeface(tf);
        l.setTextSize(11f);
        l.setTextColor(Color.WHITE);
        l.setPosition(LegendPosition.BELOW_CHART_LEFT);
//        l.setYOffset(11f);

        XAxis xAxis = mChart.getXAxis();
        xAxis.setTypeface(tf);
        xAxis.setTextSize(12f);
        xAxis.setTextColor(Color.WHITE);
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(false);
        xAxis.setSpaceBetweenLabels(1);

        YAxis leftAxis = mChart.getAxisLeft();
        leftAxis.setTypeface(tf);
        leftAxis.setTextColor(ColorTemplate.getHoloBlue());
        leftAxis.setAxisMaxValue(200f);
        leftAxis.setAxisMinValue(0f);
        leftAxis.setDrawGridLines(true);
        
        YAxis rightAxis = mChart.getAxisRight();
        rightAxis.setTypeface(tf);
        rightAxis.setTextColor(Color.RED);
        rightAxis.setAxisMaxValue(900);
        rightAxis.setAxisMinValue(-200);
        rightAxis.setDrawGridLines(false);
        rightAxis.setDrawZeroLine(false);
    }
 
Example 10
Source File: StackedBarActivityNegative.java    From Stayfit with Apache License 2.0 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_age_distribution);

    setTitle("Age Distribution Austria");

    mChart = (HorizontalBarChart) findViewById(R.id.chart1);
    mChart.setOnChartValueSelectedListener(this);
    mChart.setDrawGridBackground(false);
    mChart.setDescription("");

    // scaling can now only be done on x- and y-axis separately
    mChart.setPinchZoom(false);

    mChart.setDrawBarShadow(false);
    mChart.setDrawValueAboveBar(true);
    
    mChart.getAxisLeft().setEnabled(false);
    mChart.getAxisRight().setAxisMaxValue(25f);
    mChart.getAxisRight().setAxisMinValue(-25f);
    mChart.getAxisRight().setDrawGridLines(false);
    mChart.getAxisRight().setDrawZeroLine(true);
    mChart.getAxisRight().setLabelCount(7, false);
    mChart.getAxisRight().setValueFormatter(new CustomFormatter());
    mChart.getAxisRight().setTextSize(9f);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextSize(9f);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.BELOW_CHART_RIGHT);
    l.setFormSize(8f);
    l.setFormToTextSpace(4f);
    l.setXEntrySpace(6f);

    // IMPORTANT: When using negative values in stacked bars, always make sure the negative values are in the array first
    ArrayList<BarEntry> yValues = new ArrayList<BarEntry>();
    yValues.add(new BarEntry(new float[]{ -10, 10 }, 0));
    yValues.add(new BarEntry(new float[]{ -12, 13 }, 1));
    yValues.add(new BarEntry(new float[]{ -15, 15 }, 2));
    yValues.add(new BarEntry(new float[]{ -17, 17 }, 3));
    yValues.add(new BarEntry(new float[]{ -19, 20 }, 4));
    yValues.add(new BarEntry(new float[]{ -19, 19 }, 5));
    yValues.add(new BarEntry(new float[]{ -16, 16 }, 6));
    yValues.add(new BarEntry(new float[]{ -13, 14 }, 7));
    yValues.add(new BarEntry(new float[]{ -10, 11 }, 8));
    yValues.add(new BarEntry(new float[]{ -5, 6 }, 9));
    yValues.add(new BarEntry(new float[]{ -1, 2 }, 10));

    BarDataSet set = new BarDataSet(yValues, "Age Distribution");
    set.setValueFormatter(new CustomFormatter());
    set.setValueTextSize(7f);
    set.setAxisDependency(YAxis.AxisDependency.RIGHT);
    set.setBarSpacePercent(40f);
    set.setColors(new int[] {Color.rgb(67,67,72), Color.rgb(124,181,236)});
    set.setStackLabels(new String[]{
            "Men", "Women"
    });

    String []xVals = new String[]{"0-10", "10-20", "20-30", "30-40", "40-50", "50-60", "60-70", "70-80", "80-90", "90-100", "100+"};

    BarData data = new BarData(xVals, set);
    mChart.setData(data);
    mChart.invalidate();
}
 
Example 11
Source File: RecordingFragment.java    From go-bees with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Configure bees chart and the data.
 *
 * @param recordsList list of records.
 */
private void setupBeesChart(List<Record> recordsList) {
    // Setup data
    referenceTimestamp = recordsList.get(0).getTimestamp().getTime() / 1000;
    Record[] records = recordsList.toArray(new Record[recordsList.size()]);
    List<Entry> entries = new ArrayList<>();
    int maxNumBees = 0;
    for (Record record : records) {
        // Convert timestamp to seconds and relative to first timestamp
        long timestamp = record.getTimestamp().getTime() / 1000 - referenceTimestamp;
        int numBees = record.getNumBees();
        entries.add(new Entry(timestamp, numBees));
        // Get max num of bees
        if (numBees > maxNumBees) {
            maxNumBees = numBees;
        }
    }
    lastTimestamp = (long) entries.get(entries.size() - 1).getX();
    // Style char lines (type, color, etc.)
    LineDataSet lineDataSet = new LineDataSet(entries, getString(R.string.num_bees));
    lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    lineDataSet.setCubicIntensity(0.2f);
    lineDataSet.setDrawValues(false);
    lineDataSet.setDrawCircles(false);
    lineDataSet.setLineWidth(1.8f);
    lineDataSet.setColor(ContextCompat.getColor(getContext(), R.color.colorAccent));
    // General setup
    beesChart.setDrawGridBackground(false);
    beesChart.setDrawBorders(false);
    beesChart.setViewPortOffsets(80, 40, 80, 50);
    beesChart.getDescription().setEnabled(false);
    beesChart.getLegend().setEnabled(false);
    beesChart.setTouchEnabled(true);
    beesChart.setDragEnabled(false);
    beesChart.setScaleEnabled(false);
    beesChart.setPinchZoom(false);
    BeesMarkerView mv = new BeesMarkerView(getContext(), R.layout.recording_bees_marker_vew);
    mv.setChartView(beesChart);
    beesChart.setMarker(mv);
    beesChart.setNoDataText(getString(R.string.no_flight_act_data_available));
    // X axis setup
    IAxisValueFormatter xAxisFormatter = new HourAxisValueFormatter(referenceTimestamp);
    XAxis xAxis = beesChart.getXAxis();
    xAxis.setValueFormatter(xAxisFormatter);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextColor(Color.BLACK);
    // Y axis setup
    YAxis leftAxis = beesChart.getAxisLeft();
    leftAxis.setAxisMaximum(maxNumBees > 40 ? maxNumBees + 2 : 40);
    leftAxis.setAxisMinimum(0);
    leftAxis.setDrawGridLines(true);
    leftAxis.setDrawAxisLine(false);
    YAxis rightAxis = beesChart.getAxisRight();
    rightAxis.setAxisMaximum(maxNumBees > 40 ? maxNumBees + 2 : 40);
    rightAxis.setAxisMinimum(0);
    rightAxis.setDrawGridLines(true);
    rightAxis.setDrawAxisLine(false);
    // Add data
    beesChart.setData(new LineData(lineDataSet));
}
 
Example 12
Source File: BarChartActivity.java    From iMoney with Apache License 2.0 4 votes vote down vote up
@Override
    protected void initData() {
        ivBack.setVisibility(View.VISIBLE);
        ivSetting.setVisibility(View.GONE);
        tvTitle.setText("柱状图");

        //初始化字体库
        mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
        //图表的描述
        barChart.setDescription("三星note7爆炸事件关注度");
        //设置网格背景
        barChart.setDrawGridBackground(false);
        //是否设置阴影的显示
        barChart.setDrawBarShadow(false);

        //获取x轴
        XAxis xAxis = barChart.getXAxis();
        //设置x轴的显示位置
        xAxis.setPosition(XAxis.XAxisPosition.TOP);
        //设置x轴的字体
        xAxis.setTypeface(mTf);
        //是否绘制x轴网格线
        xAxis.setDrawGridLines(false);
        //是否绘制x轴轴线
        xAxis.setDrawAxisLine(true);

        //获取y轴
        YAxis leftAxis = barChart.getAxisLeft();
        //设置y轴的字体
        leftAxis.setTypeface(mTf);
        //参数1:设置显示的区间的个数。参数2:是否均匀分布。fasle:均匀显示区间的端点值。
        leftAxis.setLabelCount(5, false);
        //设置最高的柱状图距离顶端的距离
        leftAxis.setSpaceTop(50f);

        YAxis rightAxis = barChart.getAxisRight();
        rightAxis.setEnabled(false);//是否显示右边的y轴

        BarData mChartData = generateDataBar();
        mChartData.setValueTypeface(mTf);

        // set data
        barChart.setData(mChartData);

        // do not forget to refresh the chart
//        barChart.invalidate();
        barChart.animateY(700);
    }
 
Example 13
Source File: LineChartCard.java    From ResearchStack with Apache License 2.0 4 votes vote down vote up
private void initializeViews() {
    titleTextView = (TextView) findViewById(R.id.view_chart_line_title);
    titleTextView.setText(titleText);
    titleTextView.setTextColor(titleTextColor);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);
    titleTextView.setTypeface(Typeface.create(titleTextTypeface, Typeface.NORMAL));

    expand = (ImageView) findViewById(R.id.view_chart_line_expand);
    if (expandTintColor != 0) {
        Drawable drawable = expand.getDrawable();
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, expandTintColor);
        expand.setImageDrawable(drawable);
    }

    chart = (LineChart) findViewById(R.id.view_chart_line);
    chart.getLegend().setEnabled(false);
    chart.setDescription("");
    chart.setDrawBorders(false);
    chart.setDrawGridBackground(false);
    chart.setPinchZoom(false);
    chart.setTouchEnabled(true);
    chart.setDragEnabled(true);
    chart.setExtraLeftOffset(0);
    chart.setExtraBottomOffset(8);
    chart.setExtraTopOffset(0);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawAxisLine(false);
    xAxis.setDrawGridLines(false);
    xAxis.setLabelsToSkip(0);
    xAxis.setXOffset(16);
    xAxis.setTextSize(chartXAxisTextSize);
    xAxis.setTextColor(chartXAxisTextColor);
    xAxis.setTypeface(Typeface.create(chartXAxisTextTypeface, Typeface.NORMAL));

    YAxis yAxisLeft = chart.getAxisLeft();
    yAxisLeft.setDrawAxisLine(false);
    yAxisLeft.setDrawGridLines(false);
    yAxisLeft.setDrawZeroLine(false);
    yAxisLeft.setDrawLabels(true);
    yAxisLeft.setShowOnlyMinMax(true);
    yAxisLeft.setXOffset(16);
    yAxisLeft.setTextSize(chartYAxisTextSize);
    yAxisLeft.setTextColor(chartYAxisTextColor);
    yAxisLeft.setTypeface(Typeface.create(chartYAxisTextTypeface, Typeface.NORMAL));

    YAxis yAxisRight = chart.getAxisRight();
    yAxisRight.setDrawAxisLine(false);
    yAxisRight.setDrawGridLines(false);
    yAxisRight.setDrawZeroLine(false);
    yAxisRight.setDrawLabels(false);
    yAxisRight.setSpaceTop(0);
}
 
Example 14
Source File: BaseView.java    From android-kline with Apache License 2.0 4 votes vote down vote up
protected void initBottomChart(AppCombinedChart chart) {
        chart.setScaleEnabled(true);
        chart.setDrawBorders(false);
        chart.setBorderWidth(1);
        chart.setDragEnabled(true);
        chart.setScaleYEnabled(false);
        chart.setAutoScaleMinMaxEnabled(true);
        chart.setDragDecelerationEnabled(false);
        chart.setHighlightPerDragEnabled(false);
        Legend lineChartLegend = chart.getLegend();
        lineChartLegend.setEnabled(false);


        XAxis xAxisVolume = chart.getXAxis();
        xAxisVolume.setDrawLabels(true);
        xAxisVolume.setDrawAxisLine(false);
        xAxisVolume.setDrawGridLines(false);
        xAxisVolume.setTextColor(mAxisColor);
        xAxisVolume.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxisVolume.setLabelCount(3, true);
        xAxisVolume.setAvoidFirstLastClipping(true);
        xAxisVolume.setAxisMinimum(-0.5f);

        xAxisVolume.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                if (mData.isEmpty()) {
                    return "";
                }
                if (value < 0) {
                    value = 0;
                }
                if (value < mData.size()) {
                    return DateUtils.formatDate(mData.get((int) value).getDate(), mDateFormat);
                }
                return "";
            }
        });

        YAxis axisLeftVolume = chart.getAxisLeft();
        axisLeftVolume.setDrawLabels(true);
        axisLeftVolume.setDrawGridLines(false);
        axisLeftVolume.setLabelCount(3, true);
        axisLeftVolume.setDrawAxisLine(false);
        axisLeftVolume.setTextColor(mAxisColor);
        axisLeftVolume.setSpaceTop(10);
        axisLeftVolume.setSpaceBottom(0);
        axisLeftVolume.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
        /*axisLeftVolume.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                String s;
                if (value > 10000) {
                    s = (int) (value / 10000) + "w";
                } else if (value > 1000) {
                    s = (int) (value / 1000) + "k";
                } else {
                    s = (int) value + "";
                }
                return String.format(Locale.getDefault(), "%1$5s", s);
            }
        });
*/
        Transformer leftYTransformer = chart.getRendererLeftYAxis().getTransformer();
        ColorContentYAxisRenderer leftColorContentYAxisRenderer = new ColorContentYAxisRenderer(chart.getViewPortHandler(), chart.getAxisLeft(), leftYTransformer);
        leftColorContentYAxisRenderer.setLabelInContent(true);
        leftColorContentYAxisRenderer.setUseDefaultLabelXOffset(false);
        chart.setRendererLeftYAxis(leftColorContentYAxisRenderer);

        //右边y
        YAxis axisRightVolume = chart.getAxisRight();
        axisRightVolume.setDrawLabels(false);
        axisRightVolume.setDrawGridLines(false);
        axisRightVolume.setDrawAxisLine(false);

    }
 
Example 15
Source File: LineChartItem.java    From memorize with MIT License 4 votes vote down vote up
@SuppressLint("InflateParams")
@Override
public View getView(int position, View convertView, Context c) {

    ViewHolder holder;

    if (convertView == null) {

        holder = new ViewHolder();

        convertView = LayoutInflater.from(c).inflate(
                R.layout.stats_item_linechart, null);
        holder.chart = convertView.findViewById(R.id.chart);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // apply styling
    // holder.chart.setValueTypeface(mTf);
    holder.chart.getDescription().setEnabled(false);
    holder.chart.setDrawGridBackground(false);

    XAxis xAxis = holder.chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(true);

    YAxis leftAxis = holder.chart.getAxisLeft();
    leftAxis.setLabelCount(5, false);
    leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

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

    // set data
    holder.chart.setData((LineData) mChartData);

    // do not forget to refresh the chart
    // holder.chart.invalidate();
    holder.chart.animateX(750);

    return convertView;
}
 
Example 16
Source File: LineChartItem.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@SuppressLint("InflateParams")
@Override
public View getView(int position, View convertView, Context c) {

    ViewHolder holder;

    if (convertView == null) {

        holder = new ViewHolder();

        convertView = LayoutInflater.from(c).inflate(
                R.layout.list_item_linechart, null);
        holder.chart = convertView.findViewById(R.id.chart);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // apply styling
    // holder.chart.setValueTypeface(mTf);
    holder.chart.getDescription().setEnabled(false);
    holder.chart.setDrawGridBackground(false);

    XAxis xAxis = holder.chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(mTf);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(true);

    YAxis leftAxis = holder.chart.getAxisLeft();
    leftAxis.setTypeface(mTf);
    leftAxis.setLabelCount(5, false);
    leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

    YAxis rightAxis = holder.chart.getAxisRight();
    rightAxis.setTypeface(mTf);
    rightAxis.setLabelCount(5, false);
    rightAxis.setDrawGridLines(false);
    rightAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

    // set data
    holder.chart.setData((LineData) mChartData);

    // do not forget to refresh the chart
    // holder.chart.invalidate();
    holder.chart.animateX(750);

    return convertView;
}
 
Example 17
Source File: LineChartActivity2.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_linechart);

        setTitle("LineChartActivity2");

        tvX = findViewById(R.id.tvXMax);
        tvY = findViewById(R.id.tvYMax);

        seekBarX = findViewById(R.id.seekBar1);
        seekBarX.setOnSeekBarChangeListener(this);

        seekBarY = findViewById(R.id.seekBar2);
        seekBarY.setOnSeekBarChangeListener(this);

        chart = findViewById(R.id.chart1);
        chart.setOnChartValueSelectedListener(this);

        // no description text
        chart.getDescription().setEnabled(false);

        // enable touch gestures
        chart.setTouchEnabled(true);

        chart.setDragDecelerationFrictionCoef(0.9f);

        // enable scaling and dragging
        chart.setDragEnabled(true);
        chart.setScaleEnabled(true);
        chart.setDrawGridBackground(false);
        chart.setHighlightPerDragEnabled(true);

        // if disabled, scaling can be done on x- and y-axis separately
        chart.setPinchZoom(true);

        // set an alternative background color
        chart.setBackgroundColor(Color.LTGRAY);

        // add data
        seekBarX.setProgress(20);
        seekBarY.setProgress(30);

        chart.animateX(1500);

        // get the legend (only possible after setting data)
        Legend l = chart.getLegend();

        // modify the legend ...
        l.setForm(LegendForm.LINE);
        l.setTypeface(tfLight);
        l.setTextSize(11f);
        l.setTextColor(Color.WHITE);
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
        l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
        l.setDrawInside(false);
//        l.setYOffset(11f);

        XAxis xAxis = chart.getXAxis();
        xAxis.setTypeface(tfLight);
        xAxis.setTextSize(11f);
        xAxis.setTextColor(Color.WHITE);
        xAxis.setDrawGridLines(false);
        xAxis.setDrawAxisLine(false);

        YAxis leftAxis = chart.getAxisLeft();
        leftAxis.setTypeface(tfLight);
        leftAxis.setTextColor(ColorTemplate.getHoloBlue());
        leftAxis.setAxisMaximum(200f);
        leftAxis.setAxisMinimum(0f);
        leftAxis.setDrawGridLines(true);
        leftAxis.setGranularityEnabled(true);

        YAxis rightAxis = chart.getAxisRight();
        rightAxis.setTypeface(tfLight);
        rightAxis.setTextColor(Color.RED);
        rightAxis.setAxisMaximum(900);
        rightAxis.setAxisMinimum(-200);
        rightAxis.setDrawGridLines(false);
        rightAxis.setDrawZeroLine(false);
        rightAxis.setGranularityEnabled(false);
    }
 
Example 18
Source File: BarChartPositiveNegative.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_barchart_noseekbar);

    setTitle("BarChartPositiveNegative");

    chart = findViewById(R.id.chart1);
    chart.setBackgroundColor(Color.WHITE);
    chart.setExtraTopOffset(-30f);
    chart.setExtraBottomOffset(10f);
    chart.setExtraLeftOffset(70f);
    chart.setExtraRightOffset(70f);

    chart.setDrawBarShadow(false);
    chart.setDrawValueAboveBar(true);

    chart.getDescription().setEnabled(false);

    // scaling can now only be done on x- and y-axis separately
    chart.setPinchZoom(false);

    chart.setDrawGridBackground(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(tfRegular);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextColor(Color.LTGRAY);
    xAxis.setTextSize(13f);
    xAxis.setLabelCount(5);
    xAxis.setCenterAxisLabels(true);
    xAxis.setGranularity(1f);

    YAxis left = chart.getAxisLeft();
    left.setDrawLabels(false);
    left.setSpaceTop(25f);
    left.setSpaceBottom(25f);
    left.setDrawAxisLine(false);
    left.setDrawGridLines(false);
    left.setDrawZeroLine(true); // draw a zero line
    left.setZeroLineColor(Color.GRAY);
    left.setZeroLineWidth(0.7f);
    chart.getAxisRight().setEnabled(false);
    chart.getLegend().setEnabled(false);

    // THIS IS THE ORIGINAL DATA YOU WANT TO PLOT
    final List<Data> data = new ArrayList<>();
    data.add(new Data(0f, -224.1f, "12-29"));
    data.add(new Data(1f, 238.5f, "12-30"));
    data.add(new Data(2f, 1280.1f, "12-31"));
    data.add(new Data(3f, -442.3f, "01-01"));
    data.add(new Data(4f, -2280.1f, "01-02"));

    xAxis.setValueFormatter(new ValueFormatter() {
        @Override
        public String getFormattedValue(float value) {
            return data.get(Math.min(Math.max((int) value, 0), data.size()-1)).xAxisValue;
        }
    });

    setData(data);
}
 
Example 19
Source File: MiniDateGraph.java    From fastnfitness with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public MiniDateGraph(Context context, LineChart chart, String name) {
    mChart = chart;
    mChartName = name;
    mChart.getDescription().setEnabled(false);
    mChart.setDoubleTapToZoomEnabled(false);
    mChart.setHorizontalScrollBarEnabled(false);
    mChart.setVerticalScrollBarEnabled(false);
    mChart.setAutoScaleMinMaxEnabled(false);
    mChart.setDrawBorders(false);
    mChart.setViewPortOffsets(6f, 6f, 6f, 6f);
    mChart.animateY(1000, Easing.EaseInOutBack); // animate horizontal 3000 milliseconds
    mChart.setClickable(false);

    mChart.getAxisRight().setDrawLabels(false);
    mChart.getAxisLeft().setDrawLabels(false);
    mChart.getLegend().setEnabled(false);
    mChart.setPinchZoom(false);
    mChart.setDescription(null);
    mChart.setTouchEnabled(false);
    mChart.setDoubleTapToZoomEnabled(false);
    mChart.setNoDataText(context.getString(R.string.no_chart_data_available));

    mContext = context;
    // get the legend (only possible after setting data)
    Legend l = mChart.getLegend();
    l.setEnabled(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setDrawLabels(false);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextColor(ColorTemplate.getHoloBlue());
    xAxis.setDrawAxisLine(false);
    xAxis.setDrawGridLines(false);
    xAxis.setCenterAxisLabels(false);
    xAxis.setGranularity(1); // 1 jour

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setEnabled(false);
    leftAxis.setDrawZeroLine(false);
    leftAxis.setDrawLabels(false);
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setTextColor(ColorTemplate.getHoloBlue());
    leftAxis.setDrawGridLines(false);
    leftAxis.setGranularityEnabled(false);

    mChart.getAxisRight().setEnabled(false);
}
 
Example 20
Source File: LineChartItem.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(int position, View convertView, Context c) {

    ViewHolder holder = null;

    if (convertView == null) {

        holder = new ViewHolder();

        convertView = LayoutInflater.from(c).inflate(
                R.layout.list_item_linechart, null);
        holder.chart = (LineChart) convertView.findViewById(R.id.chart);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // apply styling
    // holder.chart.setValueTypeface(mTf);
    holder.chart.setDescription("");
    holder.chart.setDrawGridBackground(false);

    XAxis xAxis = holder.chart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(mTf);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(true);

    YAxis leftAxis = holder.chart.getAxisLeft();
    leftAxis.setTypeface(mTf);
    leftAxis.setLabelCount(5, false);
    leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
    
    YAxis rightAxis = holder.chart.getAxisRight();
    rightAxis.setTypeface(mTf);
    rightAxis.setLabelCount(5, false);
    rightAxis.setDrawGridLines(false);
    rightAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)

    // set data
    holder.chart.setData((LineData) mChartData);

    // do not forget to refresh the chart
    // holder.chart.invalidate();
    holder.chart.animateX(750);

    return convertView;
}