Java Code Examples for com.github.mikephil.charting.components.YAxis#setEnabled()

The following examples show how to use com.github.mikephil.charting.components.YAxis#setEnabled() . 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: SleepChartActivity.java    From Mi-Band with GNU General Public License v2.0 6 votes vote down vote up
private void createChartLegend() {
    /*
    Legend l = mChart.getLegend();
    l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART_INSIDE);
    l.setYOffset(0f);
    l.setYEntrySpace(0f);
    l.setTextSize(8f);
    */

    XAxis x = mChart.getXAxis();
    x.setDrawLabels(true);
    x.setDrawGridLines(false);
    x.setEnabled(true);
    x.setDrawLimitLinesBehindData(true);

    YAxis y = mChart.getAxisLeft();
    y.setAxisMaxValue(1f);
    y.setDrawTopYLabelEntry(false);
    y.setEnabled(true);

    mChart.getAxisRight().setEnabled(false);
}
 
Example 2
Source File: StatisticsFragment.java    From HeartBeat with Apache License 2.0 6 votes vote down vote up
@Override
protected void onPreExecute() {
    mChart.setDoubleTapToZoomEnabled(false);
    mChart.setTouchEnabled(false);
    mChart.setDragEnabled(false);
    mChart.setScaleEnabled(false);
    mChart.setDescription("");
    mChart.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background));
    mChart.setDrawGridBackground(false);
    mChart.setDrawBarShadow(false);
    mChart.setDrawOrder(
            new CombinedChart.DrawOrder[]{
                    CombinedChart.DrawOrder.BAR,
                    CombinedChart.DrawOrder.LINE
            });
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setValueFormatter(new IntValueFormatter());
    leftAxis.setDrawGridLines(false);
    XAxis xAxis = mChart.getXAxis();
    xAxis.setDrawGridLines(false);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setEnabled(false);
}
 
Example 3
Source File: PFAChart.java    From privacy-friendly-shopping-list with Apache License 2.0 6 votes vote down vote up
private void setupYAxis()
{
    int valuesSelectedItemPos = cache.getValuesSpinner().getSelectedItemPosition();
    YAxis leftAxis = this.chart.getAxisLeft();
    leftAxis.setLabelCount(10, false);
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setSpaceTop(20f);
    leftAxis.setAxisMinValue(0f);
    leftAxis.setValueFormatter(new PFAYAxisLabels(context, valuesSelectedItemPos, cache.getNumberScale()));

    if ( valuesSelectedItemPos == StatisticsQuery.QUANTITY )
    {
        leftAxis.setGranularity(1f); // interval 1
    }

    YAxis rightAxis = this.chart.getAxisRight();
    rightAxis.setEnabled(false);
}
 
Example 4
Source File: TrafficFragment.java    From gito-github-client with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void chartStyling(LineChart chart) {
    chart.setTouchEnabled(false);
    chart.setDescription("");
    chart.setAutoScaleMinMaxEnabled(false);
    chart.setNoDataTextColor(SettingsActivity.ThemePreferenceFragment.isLight(getContext()) ? Color.BLACK : Color.WHITE);
    YAxis axisRight = chart.getAxisRight();
    axisRight.setEnabled(false);
    chart.getLegend().setEnabled(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        chart.setNestedScrollingEnabled(false);
    }

    XAxis xAxis = chart.getXAxis();
    chartXAxisStyling(xAxis);
    YAxis yAxis = chart.getAxisLeft();
    chartYAxisStyling(yAxis);
}
 
Example 5
Source File: RecordingFragment.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Configure styles of weather charts.
 *
 * @param entries   chart data.
 * @param formatter value formatter.
 * @param minVal    min value to show.
 * @param maxVal    max value to show.
 * @return chart formatted.
 */
private LineDataSet configureWeatherChart(
        LineChart chart, int chartName, int colorLineTempChart, int colorFillTempChart,
        List<Entry> entries, IAxisValueFormatter formatter, double minVal, double maxVal) {
    LineDataSet lineDataSet = new LineDataSet(entries, getString(chartName));
    lineDataSet.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
    lineDataSet.setDrawValues(false);
    lineDataSet.setValueTextSize(10f);
    lineDataSet.setDrawCircles(false);
    lineDataSet.setLineWidth(1.8f);
    lineDataSet.setColor(ContextCompat.getColor(getContext(), colorLineTempChart));
    lineDataSet.setLineWidth(2f);
    lineDataSet.setDrawFilled(true);
    lineDataSet.setFillColor(ContextCompat.getColor(getContext(), colorFillTempChart));
    lineDataSet.setFillAlpha(255);
    // General setup
    chart.setDrawGridBackground(false);
    chart.setDrawBorders(false);
    chart.setViewPortOffsets(0, 0, 0, 0);
    chart.getDescription().setEnabled(false);
    chart.getLegend().setEnabled(false);
    chart.setTouchEnabled(false);
    // X axis setup
    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(false);
    xAxis.setAxisMinimum(0);
    xAxis.setAxisMaximum(lastTimestamp);
    // Y axis setup
    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setEnabled(false);
    leftAxis.setAxisMaximum((float) (maxVal));
    leftAxis.setAxisMinimum((float) (minVal));
    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setAxisMaximum((float) (maxVal));
    rightAxis.setAxisMinimum((float) (minVal));
    rightAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    rightAxis.setValueFormatter(formatter);
    return lineDataSet;
}
 
Example 6
Source File: LineChartHelper.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public LineChart generateLineChartConfig(LineChart lineChart) {

        //XY轴配置
        XAxis xAxis = lineChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); //定制X轴是在图表上方还是下方。
        xAxis.setDrawGridLines(false);
        xAxis.setGranularity(1);
        YAxis yAxisRight = lineChart.getAxisRight();
        yAxisRight.setEnabled(false);
        YAxis yAxisLeft = lineChart.getAxisLeft();
        yAxisLeft.setAxisMinimum(0);
        yAxisLeft.setGranularity(1);

        //背景设置
        lineChart.setDrawGridBackground(false);//表格背景绘制
        lineChart.setBackgroundColor(AppContext.getContext().getResources().getColor(R.color.white));
        //Legend定制
        lineChart.getLegend().setPosition(Legend.LegendPosition.ABOVE_CHART_LEFT);
        lineChart.getLegend().setForm(Legend.LegendForm.CIRCLE);//Legend样式
        //图表描述
        lineChart.setDescription(null);
        // 设置无数据文本提示
        lineChart.setNoDataText("暂无数据");
        //设置单方向和双方向缩放 true x,y方向可以同时控制,false只能控制x方向的缩小放大或者Y方向的缩小放大
        lineChart.setPinchZoom(true);
        return lineChart;
    }
 
Example 7
Source File: BarChartHelper.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public BarChart generateBarChartConfig(BarChart barChart) {
    XAxis xAxis = barChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); //定制X轴是在图表上方还是下方。
    xAxis.setDrawAxisLine(true);
    xAxis.setDrawGridLines(false);
    xAxis.setGranularity(1f);//放大的时候X值不增多


    YAxis yAxisRight = barChart.getAxisRight();
    yAxisRight.setEnabled(false);
    YAxis yAxisLeft = barChart.getAxisLeft();
    yAxisLeft.setAxisMinimum(0);

    barChart.setDrawBarShadow(false);
    barChart.setPinchZoom(true);
    barChart.setFitBars(true);
    // if more than 60 entries are displayed in the chart, no values will be
    // drawn
    barChart.setMaxVisibleValueCount(60);

    barChart.setDrawValueAboveBar(true);

    barChart.getDescription().setEnabled(false);
    barChart.setNoDataText("无数据");

    Legend l = barChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    //设置单方向和双方向缩放 true x,y方向可以同时控制,false只能控制x方向的缩小放大或者Y方向的缩小放大
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setXEntrySpace(4f);
    return barChart;
}
 
Example 8
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 9
Source File: Results.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
public void initSpectrumChart(){
    sChart.setPinchZoom(false);
    sChart.setDoubleTapToZoomEnabled(false);
    sChart.setDrawBarShadow(false);
    sChart.setDescription("");
    sChart.setPinchZoom(false);
    sChart.setDrawGridBackground(false);
    sChart.setHighlightPerTapEnabled(true);
    sChart.setHighlightPerDragEnabled(false);
    sChart.setDrawHighlightArrow(true);
    sChart.setDrawValueAboveBar(true);
    // XAxis parameters: hide all
    XAxis xls = sChart.getXAxis();
    xls.setPosition(XAxisPosition.BOTTOM);
    xls.setDrawAxisLine(true);
    xls.setDrawGridLines(false);
    xls.setLabelRotationAngle(-90);
    xls.setDrawLabels(true);
    xls.setTextColor(Color.WHITE);
    xls.setLabelsToSkip(0);
    // YAxis parameters (left): main axis for dB values representation
    YAxis yls = sChart.getAxisLeft();
    yls.setDrawAxisLine(true);
    yls.setDrawGridLines(true);
    yls.setAxisMaxValue(110.f);
    yls.setStartAtZero(true);
    yls.setTextColor(Color.WHITE);
    yls.setGridColor(Color.WHITE);
    // YAxis parameters (right): no axis, hide all
    YAxis yrs = sChart.getAxisRight();
    yrs.setEnabled(false);
    //return true;
}
 
Example 10
Source File: RealtimeLineChartActivity.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_realtime_linechart);

    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);

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

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

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

    LineData data = new LineData();
    data.setValueTextColor(Color.WHITE);

    // add empty data
    mChart.setData(data);

    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.setTextColor(Color.WHITE);

    XAxis xl = mChart.getXAxis();
    xl.setTypeface(tf);
    xl.setTextColor(Color.WHITE);
    xl.setDrawGridLines(false);
    xl.setAvoidFirstLastClipping(true);
    xl.setSpaceBetweenLabels(5);
    xl.setEnabled(true);

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(tf);
    leftAxis.setTextColor(Color.WHITE);
    leftAxis.setAxisMaxValue(100f);
    leftAxis.setAxisMinValue(0f);
    leftAxis.setDrawGridLines(true);

    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setEnabled(false);

}
 
Example 11
Source File: CandleStickChartActivity.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_candlechart);

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

        mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
        mSeekBarX.setOnSeekBarChangeListener(this);

        mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);
        mSeekBarY.setOnSeekBarChangeListener(this);

        mChart = (CandleStickChart) findViewById(R.id.chart1);
        mChart.setBackgroundColor(Color.WHITE);

        mChart.setDescription("");

        // if more than 60 entries are displayed in the chart, no values will be
        // drawn
        mChart.setMaxVisibleValueCount(60);

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

        mChart.setDrawGridBackground(false);

        XAxis xAxis = mChart.getXAxis();
        xAxis.setPosition(XAxisPosition.BOTTOM);
        xAxis.setSpaceBetweenLabels(2);
        xAxis.setDrawGridLines(false);

        YAxis leftAxis = mChart.getAxisLeft();  
//        leftAxis.setEnabled(false);
        leftAxis.setLabelCount(7, false);
        leftAxis.setDrawGridLines(false);
        leftAxis.setDrawAxisLine(false);
        
        YAxis rightAxis = mChart.getAxisRight();
        rightAxis.setEnabled(false);
//        rightAxis.setStartAtZero(false);

        // setting data
        mSeekBarX.setProgress(40);
        mSeekBarY.setProgress(100);
        
        mChart.getLegend().setEnabled(false);

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

        // mChart.setDrawLegend(false);
    }
 
Example 12
Source File: InvertedLineChartActivity.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);
    mChart.setDrawGridBackground(false);
    
    // no description text
    mChart.setDescription("");

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

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

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

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

    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);

    // set the marker to the chart
    mChart.setMarkerView(mv);
    
    XAxis xl = mChart.getXAxis();
    xl.setAvoidFirstLastClipping(true);
    
    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setInverted(true);
    leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
    
    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setEnabled(false);

    // add data
    setData(25, 50);

    // // restrain the maximum scale-out factor
    // mChart.setScaleMinima(3f, 3f);
    //
    // // center the view to a specific position inside the chart
    // mChart.centerViewPort(10, 50);

    // 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);

    // dont forget to refresh the drawing
    mChart.invalidate();
}
 
Example 13
Source File: Utils.java    From Aria2App with GNU General Public License v3.0 4 votes vote down vote up
public static void setupChart(@NonNull LineChart chart, boolean small, @ColorRes @Nullable Integer fgColorRes) {
    chart.clear();

    int fgColor;
    Context context = chart.getContext();
    if (fgColorRes == null)
        fgColor = CommonUtils.resolveAttrAsColor(context, R.attr.colorOnSurface);
    else
        fgColor = ContextCompat.getColor(context, fgColorRes);

    chart.setDescription(null);
    chart.setDrawGridBackground(false);
    chart.setBackgroundColor(Color.alpha(0));
    chart.setTouchEnabled(false);

    Legend legend = chart.getLegend();
    legend.setTextColor(fgColor);
    legend.setEnabled(true);

    LineData data = new LineData();
    data.setValueTextColor(fgColor);
    chart.setData(data);

    YAxis ya = chart.getAxisLeft();
    ya.setAxisLineColor(fgColor);
    ya.setTextColor(fgColor);
    ya.setTextSize(small ? 8 : 9);
    ya.setAxisMinimum(0);
    ya.setDrawAxisLine(false);
    ya.setLabelCount(small ? 4 : 8, true);
    ya.setEnabled(true);
    ya.setDrawGridLines(true);
    ya.setGridColor(fgColor);
    ya.setValueFormatter(new CustomYAxisValueFormatter());

    chart.getAxisRight().setEnabled(false);
    chart.getXAxis().setEnabled(false);

    data.addDataSet(initUploadSet(context));
    data.addDataSet(initDownloadSet(context));

    chart.invalidate();
}
 
Example 14
Source File: ChartFragment.java    From Liapp with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    view = inflater.inflate(R.layout.fragment_lastscanchart, container, false);

    LineChart cv_LastScan = (LineChart) view.findViewById(R.id.cv_LastScan);

    cv_LastScan.setOnChartGestureListener(new myChartGestureListener(cv_LastScan));

    XAxis xAxis = cv_LastScan.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTextSize(10f);
    xAxis.setTextColor(getResources().getColor(R.color.colorGlucoseNow));
    xAxis.enableGridDashedLine(5f, 5f, 0f);
    xAxis.setDrawLimitLinesBehindData(true);

    YAxis yAxisLeft = cv_LastScan.getAxisLeft();
    YAxis yAxisRight = cv_LastScan.getAxisRight();

    yAxisRight.setEnabled(false);

    yAxisLeft.setTextSize(18f); // set the textsize
    yAxisLeft.setTextColor(getResources().getColor(R.color.colorGlucoseNow));
    yAxisLeft.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    yAxisLeft.setStartAtZero(true);
    yAxisLeft.setYOffset(-6f);
    yAxisLeft.setAxisMinValue(0.0f);

    Legend legend = cv_LastScan.getLegend();
    legend.setEnabled(false);

    // no description text
    cv_LastScan.setDescription("");
    cv_LastScan.setNoDataText(getResources().getString(R.string.no_data));
    cv_LastScan.setNoDataTextDescription("");

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

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

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


    MyMarkerView mv = new MyMarkerView(view.getContext(), R.layout.custom_marker_view);

    // set the marker to the chart
    cv_LastScan.setMarkerView(mv);

    try {
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
            cv_LastScan.setHardwareAccelerationEnabled(false);

        } else {
           cv_LastScan.setHardwareAccelerationEnabled(true);
        }
    } catch (Exception e) {
    }

    refresh();

    return (view);
}
 
Example 15
Source File: LineChartActivity.java    From iMoney with Apache License 2.0 4 votes vote down vote up
@Override
protected void initData() {
    ivBack.setVisibility(View.VISIBLE);
    tvTitle.setText("折线图");
    ivSetting.setVisibility(View.GONE);

    // 加载本地的字体库
    mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
    // 设置图表的描述
    lineChart.setDescription("我的资产的变化情况");
    // 是否设置网格背景
    lineChart.setDrawGridBackground(false);

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

    // 设置Y轴
    YAxis leftAxis = lineChart.getAxisLeft();
    // 设置Y轴的子体
    leftAxis.setTypeface(mTf);
    // 参数1:设置左边区间的个数,参数2:是否需要均匀分布:false均匀
    leftAxis.setLabelCount(5, false);

    YAxis rightAxis = lineChart.getAxisRight();
    rightAxis.setTypeface(mTf);
    rightAxis.setLabelCount(5, false);
    rightAxis.setDrawGridLines(false);
    // 设置右边为不显示状态
    rightAxis.setEnabled(false);

    // set data
    lineChart.setData(generateDataLine());

    // do not forget to refresh the chart
    // lineChart.invalidate();
    lineChart.animateX(750); // 设置x轴方向的动画
}
 
Example 16
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 17
Source File: CandleStickChartActivity.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_candlechart);

        setTitle("CandleStickChartActivity");

        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.setBackgroundColor(Color.WHITE);

        chart.getDescription().setEnabled(false);

        // if more than 60 entries are displayed in the chart, no values will be
        // drawn
        chart.setMaxVisibleValueCount(60);

        // 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.setDrawGridLines(false);

        YAxis leftAxis = chart.getAxisLeft();
//        leftAxis.setEnabled(false);
        leftAxis.setLabelCount(7, false);
        leftAxis.setDrawGridLines(false);
        leftAxis.setDrawAxisLine(false);

        YAxis rightAxis = chart.getAxisRight();
        rightAxis.setEnabled(false);
//        rightAxis.setStartAtZero(false);

        // setting data
        seekBarX.setProgress(40);
        seekBarY.setProgress(100);

        chart.getLegend().setEnabled(false);
    }
 
Example 18
Source File: InvertedLineChartActivity.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("InvertedLineChartActivity");

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

    seekBarX = findViewById(R.id.seekBar1);
    seekBarY = findViewById(R.id.seekBar2);

    seekBarY.setOnSeekBarChangeListener(this);
    seekBarX.setOnSeekBarChangeListener(this);

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

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

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

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

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

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

    // create a custom MarkerView (extend MarkerView) and specify the layout
    // to use for it
    MyMarkerView mv = new MyMarkerView(this, R.layout.custom_marker_view);
    mv.setChartView(chart); // For bounds control
    chart.setMarker(mv); // Set the marker to the chart

    XAxis xl = chart.getXAxis();
    xl.setAvoidFirstLastClipping(true);
    xl.setAxisMinimum(0f);

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

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setEnabled(false);

    // add data
    seekBarX.setProgress(25);
    seekBarY.setProgress(50);

    // // restrain the maximum scale-out factor
    // chart.setScaleMinima(3f, 3f);
    //
    // // center the view to a specific position inside the chart
    // chart.centerViewPort(10, 50);

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

    // modify the legend ...
    l.setForm(LegendForm.LINE);

    // don't forget to refresh the drawing
    chart.invalidate();
}
 
Example 19
Source File: LineChartTime.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_time);

    setTitle("LineChartTime");

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

    chart = findViewById(R.id.chart1);

    // 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);

    // set an alternative background color
    chart.setBackgroundColor(Color.WHITE);
    chart.setViewPortOffsets(0f, 0f, 0f, 0f);

    // add data
    seekBarX.setProgress(100);

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

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE);
    xAxis.setTypeface(tfLight);
    xAxis.setTextSize(10f);
    xAxis.setTextColor(Color.WHITE);
    xAxis.setDrawAxisLine(false);
    xAxis.setDrawGridLines(true);
    xAxis.setTextColor(Color.rgb(255, 192, 56));
    xAxis.setCenterAxisLabels(true);
    xAxis.setGranularity(1f); // one hour
    xAxis.setValueFormatter(new ValueFormatter() {

        private final SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm", Locale.ENGLISH);

        @Override
        public String getFormattedValue(float value) {

            long millis = TimeUnit.HOURS.toMillis((long) value);
            return mFormat.format(new Date(millis));
        }
    });

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    leftAxis.setTypeface(tfLight);
    leftAxis.setTextColor(ColorTemplate.getHoloBlue());
    leftAxis.setDrawGridLines(true);
    leftAxis.setGranularityEnabled(true);
    leftAxis.setAxisMinimum(0f);
    leftAxis.setAxisMaximum(170f);
    leftAxis.setYOffset(-9f);
    leftAxis.setTextColor(Color.rgb(255, 192, 56));

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setEnabled(false);
}
 
Example 20
Source File: MeasurementSpectrumFragment.java    From NoiseCapture with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    if(view == null) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_measurement_spectrum, container, false);
        BarChart sChart = (BarChart) view.findViewById(R.id.spectrumChart);
        sChart.setDrawBarShadow(false);
        sChart.setDescription("");
        sChart.getLegend().setEnabled(false);
        sChart.setTouchEnabled(false);
        sChart.setPinchZoom(false);
        sChart.setDrawGridBackground(false);
        sChart.setMaxVisibleValueCount(0);
        sChart.setHorizontalScrollBarEnabled(false);
        sChart.setVerticalScrollBarEnabled(false);
        sChart.setNoDataTextDescription(getText(R.string.no_data_text_description).toString());
        // XAxis parameters:
        XAxis xls = sChart.getXAxis();
        xls.setPosition(XAxis.XAxisPosition.BOTTOM);
        xls.setDrawAxisLine(true);
        xls.setDrawGridLines(false);
        xls.setDrawLabels(true);
        xls.setTextColor(Color.WHITE);
        xls.setAvoidFirstLastClipping(false);
        // YAxis parameters (left): main axis for dB values representation
        YAxis yls = sChart.getAxisLeft();
        yls.setDrawAxisLine(true);
        yls.setDrawGridLines(true);
        yls.setAxisMaxValue(100.f);
        yls.setAxisMinValue(0f);
        yls.setTextColor(Color.WHITE);
        yls.setGridColor(Color.WHITE);
        yls.setSpaceBottom(0);
        yls.setSpaceTop(0);
        yls.setValueFormatter(new SPLValueFormatter());
        // YAxis parameters (right): no axis, hide all
        YAxis yrs = sChart.getAxisRight();
        yrs.setEnabled(false);
    }
    return view;
}