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

The following examples show how to use com.github.mikephil.charting.components.YAxis#setLabelCount() . 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: 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 2
Source File: BarChartItem.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_barchart, null);
            holder.chart = (BarChart) convertView.findViewById(R.id.chart);

            convertView.setTag(holder);

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

        // apply styling
        holder.chart.setDescription("");
        holder.chart.setDrawGridBackground(false);
        holder.chart.setDrawBarShadow(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.setSpaceTop(20f);
        leftAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)
       
        YAxis rightAxis = holder.chart.getAxisRight();
        rightAxis.setTypeface(mTf);
        rightAxis.setLabelCount(5, false);
        rightAxis.setSpaceTop(20f);
        rightAxis.setAxisMinValue(0f); // this replaces setStartAtZero(true)

        mChartData.setValueTypeface(mTf);
        
        // set data
        holder.chart.setData((BarData) mChartData);
        
        // do not forget to refresh the chart
//        holder.chart.invalidate();
        holder.chart.animateY(700);

        return convertView;
    }
 
Example 3
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 4
Source File: RadarChartActivitry.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_radarchart);

    mChart = (RadarChart) findViewById(R.id.chart1);

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

    mChart.setDescription("");

    mChart.setWebLineWidth(1.5f);
    mChart.setWebLineWidthInner(0.75f);
    mChart.setWebAlpha(100);

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

    setData();

    mChart.animateXY(
            1400, 1400,
            Easing.EasingOption.EaseInOutQuad,
            Easing.EasingOption.EaseInOutQuad);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setTypeface(tf);
    xAxis.setTextSize(9f);

    YAxis yAxis = mChart.getYAxis();
    yAxis.setTypeface(tf);
    yAxis.setLabelCount(5, false);
    yAxis.setTextSize(9f);
    yAxis.setAxisMinValue(0f);

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.RIGHT_OF_CHART);
    l.setTypeface(tf);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(5f);
}
 
Example 5
Source File: BarChartActivitySinus.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_barchart_sinus);
    
    mSinusData = FileUtils.loadBarEntriesFromAssets(getAssets(),"othersine.txt");

    tvX = (TextView) findViewById(R.id.tvValueCount);

    mSeekBarX = (SeekBar) findViewById(R.id.seekbarValues);

    mChart = (BarChart) findViewById(R.id.chart1);

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

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

    // draw shadows for each bar that show the maximum value
    // mChart.setDrawBarShadow(true);

    // mChart.setDrawXLabels(false);

    mChart.setDrawGridBackground(false);
    // mChart.setDrawYLabels(false);

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

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTTOM);
    xAxis.setTypeface(mTf);
    xAxis.setDrawGridLines(false);
    xAxis.setEnabled(false);

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setTypeface(mTf);
    leftAxis.setLabelCount(6, false);
    leftAxis.setAxisMinValue(-2.5f);
    leftAxis.setAxisMaxValue(2.5f);

    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    rightAxis.setTypeface(mTf);
    rightAxis.setLabelCount(6, false);
    rightAxis.setAxisMinValue(-2.5f);
    rightAxis.setAxisMaxValue(2.5f);

    mSeekBarX.setOnSeekBarChangeListener(this);
    mSeekBarX.setProgress(150); // set data

    Legend l = mChart.getLegend();
    l.setPosition(LegendPosition.BELOW_CHART_LEFT);
    l.setForm(LegendForm.SQUARE);
    l.setFormSize(9f);
    l.setTextSize(11f);
    l.setXEntrySpace(4f);

    mChart.animateXY(2000, 2000);
}
 
Example 6
Source File: ListViewBarChartActivity.java    From Stayfit with Apache License 2.0 4 votes vote down vote up
@Override
        public View getView(int position, View convertView, ViewGroup parent) {

            BarData data = getItem(position);

            ViewHolder holder = null;

            if (convertView == null) {

                holder = new ViewHolder();

                convertView = LayoutInflater.from(getContext()).inflate(
                        R.layout.list_item_barchart, null);
                holder.chart = (BarChart) convertView.findViewById(R.id.chart);

                convertView.setTag(holder);

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

            // apply styling
            data.setValueTypeface(mTf);
            data.setValueTextColor(Color.BLACK);
            holder.chart.setDescription("");
            holder.chart.setDrawGridBackground(false);

            XAxis xAxis = holder.chart.getXAxis();
            xAxis.setPosition(XAxisPosition.BOTTOM);
            xAxis.setTypeface(mTf);
            xAxis.setDrawGridLines(false);
            
            YAxis leftAxis = holder.chart.getAxisLeft();
            leftAxis.setTypeface(mTf);
            leftAxis.setLabelCount(5, false);
            leftAxis.setSpaceTop(15f);
            
            YAxis rightAxis = holder.chart.getAxisRight();
            rightAxis.setTypeface(mTf);
            rightAxis.setLabelCount(5, false);
            rightAxis.setSpaceTop(15f);

            // set data
            holder.chart.setData(data);
            
            // do not forget to refresh the chart
//            holder.chart.invalidate();
            holder.chart.animateY(700, Easing.EasingOption.EaseInCubic);

            return convertView;
        }
 
Example 7
Source File: CubicLineChartActivity.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.setViewPortOffsets(0, 20, 0, 0);
    mChart.setBackgroundColor(Color.rgb(104, 241, 175));

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

    mChart.setDrawGridBackground(false);
    
    tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
    
    XAxis x = mChart.getXAxis();
    x.setEnabled(false);
    
    YAxis y = mChart.getAxisLeft();
    y.setTypeface(tf);
    y.setLabelCount(6, false);
    y.setTextColor(Color.WHITE);
    y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    y.setDrawGridLines(false);
    y.setAxisLineColor(Color.WHITE);
    
    mChart.getAxisRight().setEnabled(false);

    // add data
    setData(45, 100);
    
    mChart.getLegend().setEnabled(false);
    
    mChart.animateXY(2000, 2000);

    // dont forget to refresh the drawing
    mChart.invalidate();
}
 
Example 8
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 9
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 10
Source File: QuotationFragment.java    From bitshares_wallet with MIT License 4 votes vote down vote up
private void initChart() {
    int colorHomeBg = getResources().getColor(android.R.color.transparent);
    int colorLine = getResources().getColor(R.color.common_divider);
    int colorText = getResources().getColor(R.color.text_grey_light);

    mChart.setDescription(null);
    mChart.setDrawGridBackground(true);
    mChart.setBackgroundColor(colorHomeBg);
    mChart.setGridBackgroundColor(colorHomeBg);
    mChart.setScaleYEnabled(false);
    mChart.setPinchZoom(true);

    mChart.setNoDataText(getString(R.string.main_activity_loading));
    mChart.setAutoScaleMinMaxEnabled(true);
    mChart.setDragEnabled(true);
    mChart.setDoubleTapToZoomEnabled(false);

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawGridLines(true);
    xAxis.setGridColor(colorLine);
    xAxis.setTextColor(colorText);
    xAxis.setLabelCount(3);
    //xAxis.setSpaceBetweenLabels(4);

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setLabelCount(4, false);
    leftAxis.setDrawGridLines(true);
    leftAxis.setDrawAxisLine(true);
    leftAxis.setGridColor(colorLine);
    leftAxis.setTextColor(colorText);

    YAxis rightAxis = mChart.getAxisRight();
    rightAxis.setTextSize(8);
    rightAxis.setLabelCount(5, false);
    rightAxis.setDrawGridLines(false);
    rightAxis.setDrawAxisLine(true);
    rightAxis.setGridColor(colorLine);
    rightAxis.setTextColor(colorText);
    rightAxis.setAxisMinimum(0);
}
 
Example 11
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 12
Source File: CubicLineChartActivity.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("CubicLineChartActivity");

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

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

    chart = findViewById(R.id.chart1);
    chart.setViewPortOffsets(0, 0, 0, 0);
    chart.setBackgroundColor(Color.rgb(104, 241, 175));

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

    chart.setDrawGridBackground(false);
    chart.setMaxHighlightDistance(300);

    XAxis x = chart.getXAxis();
    x.setEnabled(false);

    YAxis y = chart.getAxisLeft();
    y.setTypeface(tfLight);
    y.setLabelCount(6, false);
    y.setTextColor(Color.WHITE);
    y.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    y.setDrawGridLines(false);
    y.setAxisLineColor(Color.WHITE);

    chart.getAxisRight().setEnabled(false);

    // add data
    seekBarY.setOnSeekBarChangeListener(this);
    seekBarX.setOnSeekBarChangeListener(this);

    // lower max, as cubic runs significantly slower than linear
    seekBarX.setMax(700);

    seekBarX.setProgress(45);
    seekBarY.setProgress(100);

    chart.getLegend().setEnabled(false);

    chart.animateXY(2000, 2000);

    // don't forget to refresh the drawing
    chart.invalidate();
}
 
Example 13
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 14
Source File: BarChartItem.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_barchart, null);
            holder.chart = convertView.findViewById(R.id.chart);

            convertView.setTag(holder);

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

        // apply styling
        holder.chart.getDescription().setEnabled(false);
        holder.chart.setDrawGridBackground(false);
        holder.chart.setDrawBarShadow(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.setSpaceTop(20f);
        leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

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

        mChartData.setValueTypeface(mTf);

        // set data
        holder.chart.setData((BarData) mChartData);
        holder.chart.setFitBars(true);

        // do not forget to refresh the chart
//        holder.chart.invalidate();
        holder.chart.animateY(700);

        return convertView;
    }
 
Example 15
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 16
Source File: RadarChartActivity.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_radarchart);

    setTitle("RadarChartActivity");

    chart = findViewById(R.id.chart1);
    chart.setBackgroundColor(Color.rgb(60, 65, 82));

    chart.getDescription().setEnabled(false);

    chart.setWebLineWidth(1f);
    chart.setWebColor(Color.LTGRAY);
    chart.setWebLineWidthInner(1f);
    chart.setWebColorInner(Color.LTGRAY);
    chart.setWebAlpha(100);

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

    setData();

    chart.animateXY(1400, 1400, Easing.EaseInOutQuad);

    XAxis xAxis = chart.getXAxis();
    xAxis.setTypeface(tfLight);
    xAxis.setTextSize(9f);
    xAxis.setYOffset(0f);
    xAxis.setXOffset(0f);
    xAxis.setValueFormatter(new ValueFormatter() {

        private final String[] mActivities = new String[]{"Burger", "Steak", "Salad", "Pasta", "Pizza"};

        @Override
        public String getFormattedValue(float value) {
            return mActivities[(int) value % mActivities.length];
        }
    });
    xAxis.setTextColor(Color.WHITE);

    YAxis yAxis = chart.getYAxis();
    yAxis.setTypeface(tfLight);
    yAxis.setLabelCount(5, false);
    yAxis.setTextSize(9f);
    yAxis.setAxisMinimum(0f);
    yAxis.setAxisMaximum(80f);
    yAxis.setDrawLabels(false);

    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setTypeface(tfLight);
    l.setXEntrySpace(7f);
    l.setYEntrySpace(5f);
    l.setTextColor(Color.WHITE);
}
 
Example 17
Source File: BarChartActivitySinus.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_sinus);

    setTitle("BarChartActivitySinus");

    data = FileUtils.loadBarEntriesFromAssets(getAssets(), "othersine.txt");

    tvX = findViewById(R.id.tvValueCount);

    seekBarX = findViewById(R.id.seekbarValues);

    chart = findViewById(R.id.chart1);

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

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

    // draw shadows for each bar that show the maximum value
    // chart.setDrawBarShadow(true);

    // chart.setDrawXLabels(false);

    chart.setDrawGridBackground(false);
    // chart.setDrawYLabels(false);

    XAxis xAxis = chart.getXAxis();
    xAxis.setEnabled(false);

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setTypeface(tfLight);
    leftAxis.setLabelCount(6, false);
    leftAxis.setAxisMinimum(-2.5f);
    leftAxis.setAxisMaximum(2.5f);
    leftAxis.setGranularityEnabled(true);
    leftAxis.setGranularity(0.1f);

    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    rightAxis.setTypeface(tfLight);
    rightAxis.setLabelCount(6, false);
    rightAxis.setAxisMinimum(-2.5f);
    rightAxis.setAxisMaximum(2.5f);
    rightAxis.setGranularity(0.1f);

    seekBarX.setOnSeekBarChangeListener(this);
    seekBarX.setProgress(150); // set data

    Legend l = chart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setForm(LegendForm.SQUARE);
    l.setFormSize(9f);
    l.setTextSize(11f);
    l.setXEntrySpace(4f);

    chart.animateXY(1500, 1500);
}
 
Example 18
Source File: ListViewBarChartActivity.java    From StockChart-MPAndroidChart with MIT License 4 votes vote down vote up
@SuppressLint("InflateParams")
        @NonNull
        @Override
        public View getView(int position, View convertView, @NonNull ViewGroup parent) {

            BarData data = getItem(position);

            ViewHolder holder;

            if (convertView == null) {

                holder = new ViewHolder();

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

                convertView.setTag(holder);

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

            // apply styling
            if (data != null) {
                data.setValueTypeface(tfLight);
                data.setValueTextColor(Color.BLACK);
            }
            holder.chart.getDescription().setEnabled(false);
            holder.chart.setDrawGridBackground(false);

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

            YAxis leftAxis = holder.chart.getAxisLeft();
            leftAxis.setTypeface(tfLight);
            leftAxis.setLabelCount(5, false);
            leftAxis.setSpaceTop(15f);

            YAxis rightAxis = holder.chart.getAxisRight();
            rightAxis.setTypeface(tfLight);
            rightAxis.setLabelCount(5, false);
            rightAxis.setSpaceTop(15f);

            // set data
            holder.chart.setData(data);
            holder.chart.setFitBars(true);

            // do not forget to refresh the chart
//            holder.chart.invalidate();
            holder.chart.animateY(700);

            return convertView;
        }
 
Example 19
Source File: YAxisChartBase.java    From react-native-mp-android-chart with MIT License 4 votes vote down vote up
protected void setYAxisConfig(YAxis axis, ReadableMap propMap) {
    if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMaxValue")) {
        axis.setAxisMaxValue((float) propMap.getDouble("axisMaxValue"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "axisMinValue")) {
        axis.setAxisMinValue((float) propMap.getDouble("axisMinValue"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "inverted")) {
        axis.setInverted(propMap.getBoolean("inverted"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceTop")) {
        axis.setSpaceTop((float) propMap.getDouble("spaceTop"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "spaceBottom")) {
        axis.setSpaceBottom((float) propMap.getDouble("spaceBottom"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "showOnlyMinMax")) {
        axis.setShowOnlyMinMax(propMap.getBoolean("showOnlyMinMax"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "labelCount")) {
        boolean labelCountForce = false;
        if (BridgeUtils.validate(propMap, ReadableType.Boolean, "labelCountForce")) {
            labelCountForce = propMap.getBoolean("labelCountForce");
        }
        axis.setLabelCount(propMap.getInt("labelCount"), labelCountForce);
    }
    if (BridgeUtils.validate(propMap, ReadableType.String, "position")) {
        axis.setPosition(YAxis.YAxisLabelPosition.valueOf(propMap.getString("position")));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Number, "granularity")) {
        axis.setGranularity((float) propMap.getDouble("granularity"));
    }
    if (BridgeUtils.validate(propMap, ReadableType.Boolean, "granularityEnabled")) {
        axis.setGranularityEnabled(propMap.getBoolean("granularityEnabled"));
    }


    // formatting
    if (BridgeUtils.validate(propMap, ReadableType.String, "valueFormatter")) {
        String valueFormatter = propMap.getString("valueFormatter");

        if ("largeValue".equals(valueFormatter)) {
            axis.setValueFormatter(new LargeValueFormatter());
        } else if ("percent".equals(valueFormatter)) {
            axis.setValueFormatter(new PercentFormatter());
        } else {
            axis.setValueFormatter(new CustomFormatter(valueFormatter));
        }
    }

    // TODO docs says the remaining config needs to be applied before setting data. Test it
    // zero line
    if (BridgeUtils.validate(propMap, ReadableType.Map, "zeroLine")) {
        ReadableMap zeroLineConfig = propMap.getMap("zeroLine");

        if (BridgeUtils.validate(zeroLineConfig, ReadableType.Boolean, "enabled")) {
            axis.setDrawZeroLine(zeroLineConfig.getBoolean("enabled"));
        }
        if (BridgeUtils.validate(zeroLineConfig, ReadableType.Number, "lineWidth")) {
            axis.setZeroLineWidth((float) zeroLineConfig.getDouble("lineWidth"));
        }
        if (BridgeUtils.validate(zeroLineConfig, ReadableType.String, "lineColor")) {
            axis.setZeroLineColor(Color.parseColor(zeroLineConfig.getString("lineColor")));
        }
    }
}
 
Example 20
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();
}