当前位置: 首页>>代码示例>>Java>>正文


Java XAxis.setGranularity方法代码示例

本文整理汇总了Java中com.github.mikephil.charting.components.XAxis.setGranularity方法的典型用法代码示例。如果您正苦于以下问题:Java XAxis.setGranularity方法的具体用法?Java XAxis.setGranularity怎么用?Java XAxis.setGranularity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.mikephil.charting.components.XAxis的用法示例。


在下文中一共展示了XAxis.setGranularity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setXlabels

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void setXlabels(List<String> labelList)
{
    int valuesSelectedItemPos = cache.getValuesSpinner().getSelectedItemPosition();
    String[] labels = new String[ labelList.size() ];
    labelList.toArray(labels);

    PFAXAxisLabels xFormatter = new PFAXAxisLabels(labels);
    chart.setMarkerView(new PFAMarkerView(context, xFormatter, valuesSelectedItemPos, cache.getNumberScale()));

    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawGridLines(false);
    xAxis.setGranularity(1f);
    xAxis.setLabelCount(5);
    xAxis.setValueFormatter(xFormatter);
}
 
开发者ID:SecUSo,项目名称:privacy-friendly-shopping-list,代码行数:17,代码来源:PFAChart.java

示例2: setHorizontalBarChart

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
/**
 * Set the horizontal bar pattern
 * @param barChart chart
 * @param chartData horizontal bar chart data
 * @param jobs string array of job titles
 * @param typeface Typeface font
 */
public static void setHorizontalBarChart(BarChart barChart, final ChartData<?> chartData,
                                         final String[] jobs, Typeface typeface) {
    barChart.setDrawGridBackground(false);
    XAxis xAxis = barChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    //xAxis.setLabelCount(chartData.getEntryCount());
    xAxis.setLabelCount(jobs.length);
    xAxis.setTypeface(typeface);
    xAxis.setDrawAxisLine(true);
    xAxis.setDrawGridLines(false);
    xAxis.setGranularity(1f);

    YAxis leftAxis = barChart.getAxisLeft();
    leftAxis.setTypeface(typeface);
    leftAxis.setSpaceTop(15f);
    leftAxis.setAxisMinimum(0f);
    leftAxis.setGranularity(1f);
    leftAxis.setDrawAxisLine(true);
    leftAxis.setDrawGridLines(true);
    YAxis axisRight = barChart.getAxisRight();
    axisRight.setTypeface(typeface);
    axisRight.setDrawAxisLine(true);
    axisRight.setDrawGridLines(false);
    axisRight.setGranularity(1f);
    axisRight.setAxisMinimum(0f);

    final Legend legend = barChart.getLegend();
    legend.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
    legend.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    legend.setDrawInside(false);
    legend.setFormSize(8f);
    legend.setXEntrySpace(4f);
    barChart.setData((BarData) chartData);
    barChart.setFitBars(true);
    barChart.animateY(DURATION_LONG);
    xAxis.setValueFormatter(new HorizontalBarValueFormatter(jobs));
}
 
开发者ID:graviton57,项目名称:DOUSalaries,代码行数:46,代码来源:ChartHelper.java

示例3: setXAxis

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
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);
}
 
开发者ID:huazhouwang,项目名称:Synapse,代码行数:14,代码来源:ModelDetailActivity.java

示例4: setupXAxis

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void setupXAxis(BarLineChartBase chart, IAxisValueFormatter formatter) {
    XAxis x = chart.getXAxis();
    x.setGranularity(1.0f);
    x.setDrawGridLines(false);
    x.setPosition(XAxis.XAxisPosition.BOTTOM);
    x.setDrawAxisLine(false);
    x.setCenterAxisLabels(true);
    x.setAxisMinimum(2.0f);
    x.setAxisMaximum(5.0f);
    x.setValueFormatter(formatter);
}
 
开发者ID:jasonwyatt,项目名称:SQLite-Performance,代码行数:12,代码来源:TestSuiteFragment.java

示例5: init

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void init(Context context, AttributeSet attrs, int defStyle) {
    setDrawBarShadow(false);
    setDrawValueAboveBar(true);
    getDescription().setEnabled(false);
    setMaxVisibleValueCount(60);
    setDrawGridBackground(false);

    XAxis xl = getXAxis();
    xl.setPosition(XAxis.XAxisPosition.BOTTOM);
    xl.setDrawAxisLine(true);
    xl.setDrawGridLines(false);
    xl.setGranularity(10f);
    xl.setTextColor(Color.GRAY);

    YAxis yl = getAxisLeft();
    yl.setDrawAxisLine(false);
    yl.setDrawGridLines(false);
    yl.setDrawLabels(false);
    yl.setAxisMinimum(0f);
    yl.setTextColor(Color.GRAY);

    YAxis yr = getAxisRight();
    yr.setDrawAxisLine(true);
    yr.setDrawGridLines(false);
    yr.setAxisMinimum(0f);
    yl.setTextColor(Color.GRAY);

    setFitBars(true);
    animateY(2500);

    Legend l = getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    l.setFormSize(8f);
    l.setXEntrySpace(4f);

}
 
开发者ID:VidyaSastry,项目名称:Opal-Chat-AnalyticsDashboard,代码行数:40,代码来源:MyHorizontalBarChart.java

示例6: getFormattedLineChart

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
/**
 * Formats a line chart in a standardized manner
 * @param c App context
 * @param chart LineChart to format
 * @param listener Listener to attach to chart
 * @param xLabels Labels to use for the x-axis
 * @param valueFormatter True if large value formatter should be used
 * @param skip Number of values to skip
 * @param legend True if show legend, false if hide legend
 * @return Formatted linechart
 */
public static LineChart getFormattedLineChart(Context c, LineChart chart, OnChartValueSelectedListener listener, List<String> xLabels, boolean valueFormatter, int skip, boolean legend) {
    Legend cLegend = chart.getLegend();
    cLegend.setEnabled(legend);

    XAxis xAxis = chart.getXAxis();
    xAxis.setGranularity(skip);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setValueFormatter(new XAxisLabelFormatter(xLabels));

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

    YAxis yAxisLeft = chart.getAxisLeft();
    if (valueFormatter) {
        yAxisLeft.setValueFormatter(new LargeNumberAxisFormatter(c));
    }

    if (SettingsActivity.getTheme(c) == SettingsActivity.THEME_NOIR) {
        int textColorNoir = ContextCompat.getColor(c, R.color.colorPrimaryTextNoir);
        cLegend.setTextColor(textColorNoir);
        xAxis.setTextColor(textColorNoir);
        yAxisLeft.setTextColor(textColorNoir);
    }

    chart.setDoubleTapToZoomEnabled(false);
    chart.setDescription(EMPTY_CHART_DESCRIPTION);
    chart.setDragEnabled(true);
    chart.setScaleYEnabled(false);
    chart.setDrawGridBackground(false);
    chart.setOnChartValueSelectedListener(listener);

    return chart;
}
 
开发者ID:lloydtorres,项目名称:stately,代码行数:45,代码来源:RaraHelper.java

示例7: initChart

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void initChart() {
    barChart.setDrawBarShadow(false);
    barChart.setDrawValueAboveBar(true);
    barChart.getDescription().setEnabled(false);
    barChart.setPinchZoom(false);
    barChart.setMaxVisibleValueCount(60);
    barChart.getLegend().setEnabled(false);
    barChart.setDrawGridBackground(false);
    barChart.getAxisRight().setEnabled(false);
    barChart.setScaleYEnabled(false);

    dayAxisValueFormatter = new DayAxisValueFormatter();
    XAxis xAxis = barChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setLabelRotationAngle(270);
    xAxis.setDrawGridLines(false);
    xAxis.setGranularity(1f);
    xAxis.setTextColor(getOutlayTheme().secondaryTextColor);
    xAxis.setValueFormatter(dayAxisValueFormatter);


    YAxis leftAxis = barChart.getAxisLeft();
    leftAxis.setValueFormatter(new AmountValueFormatter());
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setTextColor(getOutlayTheme().secondaryTextColor);
    leftAxis.setSpaceTop(15f);
    leftAxis.setAxisMinimum(0f);
}
 
开发者ID:bmelnychuk,项目名称:outlay,代码行数:29,代码来源:AnalysisFragment.java

示例8: onCreate

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_combined);

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

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

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

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

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

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxisPosition.BOTH_SIDED);
    xAxis.setAxisMinimum(0f);
    xAxis.setGranularity(1f);
    xAxis.setValueFormatter(new IAxisValueFormatter() {
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return mMonths[(int) value % mMonths.length];
        }
    });

    CombinedData data = new CombinedData();

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

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

    mChart.setData(data);
    mChart.invalidate();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:60,代码来源:CombinedChartActivity.java

示例9: onCreate

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_barchart);

        tvX = (TextView) findViewById(R.id.tvXMax);
        tvX.setTextSize(10);
        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 = (BarChart) findViewById(R.id.chart1);
        mChart.setOnChartValueSelectedListener(this);
        mChart.getDescription().setEnabled(false);

//        mChart.setDrawBorders(true);

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

        mChart.setDrawBarShadow(false);

        mChart.setDrawGridBackground(false);

        // 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(mChart); // For bounds control
        mChart.setMarker(mv); // Set the marker to the chart

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

        Legend l = mChart.getLegend();
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
        l.setOrientation(Legend.LegendOrientation.VERTICAL);
        l.setDrawInside(true);
        l.setTypeface(mTfLight);
        l.setYOffset(0f);
        l.setXOffset(10f);
        l.setYEntrySpace(0f);
        l.setTextSize(8f);

        XAxis xAxis = mChart.getXAxis();
        xAxis.setTypeface(mTfLight);
        xAxis.setGranularity(1f);
        xAxis.setCenterAxisLabels(true);
        xAxis.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {
                return String.valueOf((int) value);
            }
        });

        YAxis leftAxis = mChart.getAxisLeft();
        leftAxis.setTypeface(mTfLight);
        leftAxis.setValueFormatter(new LargeValueFormatter());
        leftAxis.setDrawGridLines(false);
        leftAxis.setSpaceTop(35f);
        leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)

        mChart.getAxisRight().setEnabled(false);
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:71,代码来源:BarChartActivityMultiDataset.java

示例10: onCreate

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
@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);

    tvX = (TextView) findViewById(R.id.tvXMax);
    mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
    mSeekBarX.setProgress(100);
    tvX.setText("100");

    mSeekBarX.setOnSeekBarChangeListener(this);

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

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

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

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

    // add data
    setData(100, 30);
    mChart.invalidate();

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

    XAxis xAxis = mChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.TOP_INSIDE);
    xAxis.setTypeface(mTfLight);
    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 IAxisValueFormatter() {

        private SimpleDateFormat mFormat = new SimpleDateFormat("dd MMM HH:mm");

        @Override
        public String getFormattedValue(float value, AxisBase axis) {

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

    YAxis leftAxis = mChart.getAxisLeft();
    leftAxis.setPosition(YAxis.YAxisLabelPosition.INSIDE_CHART);
    leftAxis.setTypeface(mTfLight);
    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 = mChart.getAxisRight();
    rightAxis.setEnabled(false);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:79,代码来源:LineChartTime.java

示例11: onCreate

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
@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);

    mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf");
    mChart = (BarChart) findViewById(R.id.chart1);
    mChart.setBackgroundColor(Color.WHITE);
    mChart.setExtraTopOffset(-30f);
    mChart.setExtraBottomOffset(10f);
    mChart.setExtraLeftOffset(70f);
    mChart.setExtraRightOffset(70f);

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

    mChart.getDescription().setEnabled(false);

    // 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.setTypeface(mTf);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(false);
    xAxis.setTextColor(Color.LTGRAY);
    xAxis.setTextSize(13f);
    xAxis.setLabelCount(5);
    xAxis.setCenterAxisLabels(true);
    xAxis.setGranularity(1f);

    YAxis left = mChart.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);
    mChart.getAxisRight().setEnabled(false);
    mChart.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 IAxisValueFormatter() {
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            return data.get(Math.min(Math.max((int) value, 0), data.size()-1)).xAxisValue;
        }
    });

    setData(data);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:66,代码来源:BarChartPositiveNegative.java

示例12: onCreate

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_horizontalbarchart);

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

        mSeekBarX = (SeekBar) findViewById(R.id.seekBar1);
        mSeekBarY = (SeekBar) findViewById(R.id.seekBar2);

        mChart = (HorizontalBarChart) findViewById(R.id.chart1);
        mChart.setOnChartValueSelectedListener(this);
        // mChart.setHighlightEnabled(false);

        mChart.setDrawBarShadow(false);

        mChart.setDrawValueAboveBar(true);

        mChart.getDescription().setEnabled(false);

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

        XAxis xl = mChart.getXAxis();
        xl.setPosition(XAxisPosition.BOTTOM);
        xl.setTypeface(mTfLight);
        xl.setDrawAxisLine(true);
        xl.setDrawGridLines(false);
        xl.setGranularity(10f);

        YAxis yl = mChart.getAxisLeft();
        yl.setTypeface(mTfLight);
        yl.setDrawAxisLine(true);
        yl.setDrawGridLines(true);
        yl.setAxisMinimum(0f); // this replaces setStartAtZero(true)
//        yl.setInverted(true);

        YAxis yr = mChart.getAxisRight();
        yr.setTypeface(mTfLight);
        yr.setDrawAxisLine(true);
        yr.setDrawGridLines(false);
        yr.setAxisMinimum(0f); // this replaces setStartAtZero(true)
//        yr.setInverted(true);

        setData(12, 50);
        mChart.setFitBars(true);
        mChart.animateY(2500);

        // setting data
        mSeekBarY.setProgress(50);
        mSeekBarX.setProgress(12);

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

        Legend l = mChart.getLegend();
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.LEFT);
        l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
        l.setDrawInside(false);
        l.setFormSize(8f);
        l.setXEntrySpace(4f);
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:76,代码来源:HorizontalBarChartActivity.java

示例13: setUpBarChart

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void setUpBarChart() {
    BarData barData = generateBarData(project.getTimeSpent());

    XAxis xAxis = barChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setAxisLineColor(Color.WHITE);
    xAxis.setTextColor(Color.WHITE);
    xAxis.setDrawGridLines(false);
    xAxis.setGranularity(1f);
    xAxis.setValueFormatter(new FormatUtils().getBarXAxisValueFormatterInstance(referenceTime));
    xAxis.setAxisLineWidth(2f);

    YAxis leftAxis = barChart.getAxisLeft();
    leftAxis.removeAllLimitLines();
    leftAxis.setDrawGridLines(false);
    leftAxis.setAxisLineColor(Color.WHITE);
    leftAxis.setTextColor(Color.WHITE);
    leftAxis.setGranularity(60 * 60);
    leftAxis.setValueFormatter(new IAxisValueFormatter() {
        @Override
        public String getFormattedValue(float value, AxisBase axis) {

            int hours = (int) TimeUnit.SECONDS.toHours((long) Math.ceil(value));

            return (hours == 0)
                    ? "" : context.getString(R.string.hours, hours);
        }
    });
    leftAxis.setAxisLineWidth(2f);

    int maxYData = (int) (Math.ceil(barData.getYMax()) + 3600);

    leftAxis.setAxisMaximum(maxYData);
    leftAxis.setAxisMinimum(0f);

    CustomMarkerView customMarkerView = new CustomMarkerView(context, R.layout.marker_view, referenceTime);
    barChart.setMarker(customMarkerView);

    barChart.getAxisRight().setEnabled(false);
    barChart.getLegend().setEnabled(false);
    barChart.getDescription().setEnabled(false);
    barChart.setBackground(context.getResources().getDrawable(R.color.colorPrimaryDark));
    barChart.setDrawGridBackground(false);
    barChart.setDragEnabled(false);
    barChart.setScaleEnabled(false);
    barChart.setDragDecelerationEnabled(false);
    barChart.setPinchZoom(false);
    barChart.setDoubleTapToZoomEnabled(false);
    barChart.setDrawBorders(false);
    barChart.setData(barData);

    customMarkerView.setChartView(barChart);

    barChart.setVisibility(View.VISIBLE);
    barChart.animateY(1500, Easing.EasingOption.Linear);
}
 
开发者ID:Protino,项目名称:CodeWatch,代码行数:57,代码来源:ProjectDetailsFragment.java

示例14: setUpBarChart

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
private void setUpBarChart(int dailyGoal, List<Integer> progressSoFar) {

        BarData barData = generateBarData(dailyGoal, progressSoFar);

        //Set up a limit line indicating the goal
        LimitLine limitLine = new LimitLine(dailyGoal * 60 * 60, context.getString(R.string.goal));
        limitLine.setLineWidth(4f);
        limitLine.setLineColor(blue400);
        limitLine.setTextSize(12f);
        limitLine.setTextColor(Color.WHITE);

        //Format Xaxis
        XAxis xAxis = goalBarChart.getXAxis();
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
        xAxis.setDrawGridLines(false);
        xAxis.setAxisLineColor(Color.WHITE);
        xAxis.setTextColor(Color.WHITE);
        xAxis.setGranularity(1f);
        xAxis.setValueFormatter(new FormatUtils().getBarXAxisValueFormatterInstance(referenceTime));
        xAxis.setAxisLineWidth(2f);

        //Format Yaxis
        YAxis leftAxis = goalBarChart.getAxisLeft();
        leftAxis.removeAllLimitLines();
        leftAxis.addLimitLine(limitLine);
        leftAxis.setDrawGridLines(false);
        leftAxis.setAxisLineColor(Color.WHITE);
        leftAxis.setTextColor(Color.WHITE);
        leftAxis.setGranularity(60 * 60);
        leftAxis.setValueFormatter(new IAxisValueFormatter() {
            @Override
            public String getFormattedValue(float value, AxisBase axis) {

                /* Do not display zero value and format the value as time*/
                return (value == 0)
                        ? "" : FormatUtils.getFormattedTime(context, (int) value);
            }
        });
        leftAxis.setAxisLineWidth(2f);

        //Set a maximum value on purpose so that marker view is visible
        int maximum;
        int maxYData = (int) TimeUnit.SECONDS.toHours((long) Math.ceil(barData.getYMax()));
        maximum = (maxYData > dailyGoal) ? maxYData : dailyGoal;
        maximum += 2;
        leftAxis.setAxisMaximum(maximum * 60 * 60);
        leftAxis.setAxisMinimum(0f);

        // Setup a marker view to display details of the selected dataItem
        CustomMarkerView customMarkerView = new CustomMarkerView(context, R.layout.marker_view, referenceTime);
        goalBarChart.setMarker(customMarkerView);

        // Disable interactions
        goalBarChart.getAxisRight().setEnabled(false);
        goalBarChart.getLegend().setEnabled(false);
        goalBarChart.getDescription().setEnabled(false);
        goalBarChart.setBackgroundColor(windowColor);
        goalBarChart.setDrawGridBackground(false);
        goalBarChart.setDragEnabled(false);
        goalBarChart.setScaleEnabled(false);
        goalBarChart.setDragDecelerationEnabled(false);
        goalBarChart.setPinchZoom(false);
        goalBarChart.setDoubleTapToZoomEnabled(false);
        goalBarChart.setDrawBorders(false);
        goalBarChart.setData(barData);

        customMarkerView.setChartView(goalBarChart);

        goalBarChart.setVisibility(View.VISIBLE);
        goalBarChart.animateY(1500, Easing.EasingOption.Linear);
    }
 
开发者ID:Protino,项目名称:CodeWatch,代码行数:72,代码来源:GoalsDetailFragment.java

示例15: populateUserStatsChart

import com.github.mikephil.charting.components.XAxis; //导入方法依赖的package包/类
/**
 * Show user stats graph
 */
private void populateUserStatsChart() {
    final String[] userStatsChartXAxisLabel = getActivity().getResources().getStringArray(R.array.user_stats_x_axis_labels);
    final BarChart chart = getActivity().findViewById(R.id.user_stats_chart);
    chart.setTouchEnabled(false);
    XAxis xAxis = chart.getXAxis();
    xAxis.setGranularity(1);
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setValueFormatter(new IAxisValueFormatter() {
        /**
         * Format the value
         * @param value - value to fit to the axis
         * @param axis - the axis to fit to
         * @return Returns the formatted value
         */
        @Override
        public String getFormattedValue(float value, AxisBase axis) {
            int v = (int) value;
            return userStatsChartXAxisLabel[v];
        }
    });
    xAxis.setDrawGridLines(false);
    xAxis.setTextSize(11f);
    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setEnabled(false);
    chart.getAxisLeft().setGranularity(1);
    chart.getDescription().setEnabled(false);

    if (mUser != null) {
        int[] colors = getActivity().getResources().getIntArray(R.array.user_stats_chart_colors);
        List<BarEntry> entries = new ArrayList<>();
        entries.add(new BarEntry(0f, mUser.getPlantsAdded()));
        entries.add(new BarEntry(1f, mUser.getPlantsDeleted()));
        entries.add(new BarEntry(2f, mUser.getWaterCount()));
        entries.add(new BarEntry(3f, mUser.getMeasureCount()));
        entries.add(new BarEntry(4f, mUser.getPhotoCount()));

        BarDataSet barDataSet = new BarDataSet(entries, "Plant Operations");
        barDataSet.setColors(ColorTemplate.createColors(colors));
        barDataSet.setValueTextSize(11f);

        BarData data = new BarData(barDataSet);
        data.setBarWidth(0.9f); // set custom bar width
        chart.setData(data);
        chart.invalidate(); // refresh
    }
}
 
开发者ID:iskandergaba,项目名称:Botanist,代码行数:50,代码来源:AccountController.java


注:本文中的com.github.mikephil.charting.components.XAxis.setGranularity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。