當前位置: 首頁>>代碼示例>>Java>>正文


Java XAxis.setLabelCount方法代碼示例

本文整理匯總了Java中com.github.mikephil.charting.components.XAxis.setLabelCount方法的典型用法代碼示例。如果您正苦於以下問題:Java XAxis.setLabelCount方法的具體用法?Java XAxis.setLabelCount怎麽用?Java XAxis.setLabelCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.github.mikephil.charting.components.XAxis的用法示例。


在下文中一共展示了XAxis.setLabelCount方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: setLineChart

import com.github.mikephil.charting.components.XAxis; //導入方法依賴的package包/類
/**
 * Set the line chart pattern
 * @param lineChart chart
 * @param chartData pie chart data
 * @param month data
 * @param typeface Typeface font
 */
public static void setLineChart(Context context, LineChart lineChart, ChartData<?> chartData,
                                final String[] month, Typeface typeface) {
    // apply styling
    lineChart.getDescription().setEnabled(false);
    lineChart.setDrawGridBackground(false);
    // create a custom MarkerView (extend MarkerView) and specify the layout to use for it
    SalaryMarker marker = new SalaryMarker(context, R.layout.marker_salary_detail);
    marker.setChartView(lineChart); // For bounds control
    lineChart.setMarker(marker);
    //fix crash com.github.mikephil.charting.charts.Chart.drawMarkers(Chart.java:731)
    lineChart.setDrawMarkers(false);

    XAxis xAxis = lineChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setTypeface(typeface);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(true);
    xAxis.setValueFormatter(new LineChartValueFormatter(month));
    xAxis.setLabelCount(month.length / 2, true);//xAxis label count

    YAxis leftAxis = lineChart.getAxisLeft();
    leftAxis.setTypeface(typeface);
    leftAxis.setLabelCount(9, false);
    leftAxis.setAxisMinimum(0f);
    YAxis rightAxis = lineChart.getAxisRight();
    rightAxis.setTypeface(typeface);
    rightAxis.setDrawGridLines(false);
    rightAxis.setAxisMinimum(0f);
    Legend l = lineChart.getLegend();
    l.setWordWrapEnabled(true);
    l.setTypeface(typeface);
    l.setFormSize(14f);
    l.setTextSize(9f);
    lineChart.setData((LineData) chartData);
    lineChart.animateX(DURATION_SHORT);

}
 
開發者ID:graviton57,項目名稱:DOUSalaries,代碼行數:45,代碼來源:ChartHelper.java

示例3: 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

示例4: createChart

import com.github.mikephil.charting.components.XAxis; //導入方法依賴的package包/類
private static void createChart(Chart barChart, List<Pair<String, Integer>> chartData, String title, Context context){

        int count = chartData.size() > 10 ? 10 : chartData.size();

        String[] stateNames = new String[count];
        for (int i=0; i<count; ++i) {
            Pair<String, Integer> record = chartData.get(i);
            stateNames[i] = record.first;
        }

        StateAxisValueFormatter stateAxisValueFormatter = new StateAxisValueFormatter(stateNames);

        barChart.getDescription().setEnabled(false);
        barChart.setTouchEnabled(false);

        XAxis xl = barChart.getXAxis();
        xl.setPosition(XAxis.XAxisPosition.BOTTOM);
        xl.setDrawAxisLine(true);
        xl.setDrawGridLines(true);
        xl.setGridLineWidth(0.3f);
        xl.setTextSize(11f);
        xl.setTextColor(Color.BLACK);
        xl.setLabelCount(count);
        xl.setValueFormatter(stateAxisValueFormatter);

        // setting data
        Legend l = barChart.getLegend();
        l.setDirection(Legend.LegendDirection.LEFT_TO_RIGHT);
        l.setFormSize(11f);
        l.setTextSize(11f);
        l.setXEntrySpace(4f);

        setData(barChart, chartData, title,context);
    }
 
開發者ID:fga-gpp-mds,項目名稱:2016.2-CidadeDemocratica,代碼行數:35,代碼來源:CharterGenerator.java

示例5: 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

示例6: onCreateView

import com.github.mikephil.charting.components.XAxis; //導入方法依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.chart_frag, container, false);

    // Set up timeline chart
    chart = view.findViewById(R.id.timeline);
    entries = new ArrayList<>();

    // Set up the x-axis
    XAxis xAxis = chart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);

    formatter = DateTimeFormatter.ofPattern("MMM d");
    dates = new ArrayList<>();

    int numDays = 14;
    LocalDate today = LocalDate.now();
    minimumDate = today.minusDays(numDays);
    LocalDate currentDay = minimumDate;

    dateMap = new HashMap<>();

    for (int i = 0; i < numDays + 1; i++) {
        float index = (float) i;

        String dateString = currentDay.format(formatter);
        dates.add(dateString);
        dateMap.put(dateString, i);

        BarEntry barEntry = new BarEntry(index, new float[] { 0, 0, 0, 0 });
        entries.add(barEntry);

        currentDay = currentDay.plusDays(1);
    }

    xAxis.setValueFormatter(new MyXAxisValueFormatter(dates));
    xAxis.setLabelCount(numDays);
    xAxis.setGranularity(1f);
    xAxis.setLabelRotationAngle(45f);

    UserAccount currentUser = HabitUpApplication.getCurrentUser();

    // Get user events
    ArrayList<HabitEvent> eventList = currentUser.getEventList().getEvents();

    for (HabitEvent event : eventList) {
        if (withinDateRange(event.getCompletedate(), minimumDate)) {
            addChartEntry(event);
        }
    }

    set = new BarDataSet(entries, "");
    int red = Color.parseColor(Attributes.getColour("Physical"));
    int purple = Color.parseColor(Attributes.getColour("Mental"));
    int green = Color.parseColor(Attributes.getColour("Discipline"));
    int blue = Color.parseColor(Attributes.getColour("Social"));
    int[] colors = {red, purple, green, blue};
    set.setColors(colors);
    set.setStackLabels(new String[]{"Physical", "Mental", "Discipline", "Social"});
    set.setDrawValues(false);

    BarData data = new BarData(set);
    data.setBarWidth(0.6f);

    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setValueFormatter(new MyYAxisValueFormatter());
    leftAxis.setGranularity(1f);
    leftAxis.setAxisMinimum(0f);
    chart.getAxisRight().setEnabled(false);

    chart.setData(data);
    chart.setFitBars(true);
    chart.getXAxis().setDrawGridLines(false);
    chart.getAxisLeft().setDrawGridLines(false);
    chart.getDescription().setEnabled(false);
    animateChart();
    chart.invalidate();

    return view;
}
 
開發者ID:CMPUT301F17T29,項目名稱:HabitUp,代碼行數:82,代碼來源:ChartFragment.java

示例7: 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 xAxis = getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    xAxis.setDrawGridLines(false);
    xAxis.setGranularity(1f);
    xAxis.setLabelCount(7);
    xAxis.setTextColor(Color.GRAY);

    YAxis leftAxis = getAxisLeft();
    leftAxis.setDrawGridLines(false);
    leftAxis.setLabelCount(8, false);
    leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
    leftAxis.setSpaceTop(15f);
    leftAxis.setAxisMinimum(0f);
    leftAxis.setTextColor(Color.GRAY);

    YAxis rightAxis = getAxisRight();
    rightAxis.setDrawGridLines(false);
    rightAxis.setDrawAxisLine(false);
    rightAxis.setLabelCount(8, false);
    rightAxis.setDrawLabels(false);
    rightAxis.setSpaceTop(15f);
    rightAxis.setAxisMinimum(0f);

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

}
 
開發者ID:VidyaSastry,項目名稱:Opal-Chat-AnalyticsDashboard,代碼行數:42,代碼來源:MyBarChart.java

示例8: initChart

import com.github.mikephil.charting.components.XAxis; //導入方法依賴的package包/類
/**
     * 初始化報表
     *
     * @param showAnimation 是否顯示動畫
     */
    void initChart(boolean showAnimation) {

        int screenWidth = Utils.getScreenWidth(mContext);
        combinedChart.getLayoutParams().height = screenWidth * 300 / 640;

        //啟用縮放和拖動
        combinedChart.setDragEnabled(true);//拖動
        combinedChart.setScaleEnabled(false);//縮放
        combinedChart.setOnChartValueSelectedListener(this);
        combinedChart.getDescription().setEnabled(false);
        combinedChart.setBackgroundColor(ContextCompat.getColor(mContext, R.color.co10));
        combinedChart.setDrawGridBackground(false);
        combinedChart.setDrawBarShadow(false);
        combinedChart.setHighlightFullBarEnabled(false);

        Legend l = combinedChart.getLegend();
        l.setForm(Legend.LegendForm.NONE);//底部樣式
        l.setTextColor(ContextCompat.getColor(mContext, R.color.transparent));
        l.setWordWrapEnabled(false);
        l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
        l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
        l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
        l.setDrawInside(false);

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

        YAxis leftAxis = combinedChart.getAxisLeft();
        leftAxis.setDrawGridLines(false);
        leftAxis.setGranularityEnabled(false);
        leftAxis.setDrawAxisLine(false);
        leftAxis.setAxisMinimum(0f); // this replaces setStartAtZero(true)
        leftAxis.setTextColor(ContextCompat.getColor(mContext, R.color.co4));

        updateTitle(items.get(dateSelected));
        XAxis xAxis = combinedChart.getXAxis();
        xAxis.setTypeface(mTfLight);
        xAxis.setEnabled(true);//設置軸啟用或禁用 如果禁用以下的設置全部不生效
        xAxis.setDrawAxisLine(true);//是否繪製軸線
        xAxis.setDrawGridLines(false);//設置x軸上每個點對應的線
        xAxis.setDrawLabels(true);//繪製標簽  指x軸上的對應數值
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);//設置x軸的顯示位置
        xAxis.setTextSize(10f); //設置X軸文字大小
        xAxis.setGranularityEnabled(true);//是否允許X軸上值重複出現
        xAxis.setTextColor(ContextCompat.getColor(this, R.color.co4));//設置X軸文字顏色
//        //設置豎線的顯示樣式為虛線
//        //lineLength控製虛線段的長度
//        //spaceLength控製線之間的空間
        xAxis.enableGridDashedLine(10f, 10f, 0f);
        xAxis.setAxisMinimum(0f);//設置x軸的最小值
        xAxis.setAxisMaximum(mDatas.length);//設置最大值
        xAxis.setAvoidFirstLastClipping(true);//圖表將避免第一個和最後一個標簽條目被減掉在圖表或屏幕的邊緣
        xAxis.setLabelRotationAngle(0f);//設置x軸標簽字體的旋轉角度
//        設置x軸顯示標簽數量  還有一個重載方法第二個參數為布爾值強製設置數量 如果啟用會導致繪製點出現偏差
        xAxis.setLabelCount(10);
        xAxis.setGridLineWidth(10f);//設置豎線大小
//        xAxis.setGridColor(Color.RED);//設置豎線顏色
        xAxis.setAxisLineColor(Color.GRAY);//設置x軸線顏色
        xAxis.setAxisLineWidth(1f);//設置x軸線寬度

        CombinedData combinedData = new CombinedData();
        combinedData.setData(generateLineData());
        combinedData.setData(generateBarData());
        combinedData.setValueTypeface(mTfLight);
        xAxis.setAxisMaximum(combinedData.getXMax() + 0.25f);
        //X軸的數據格式
        ValueFormatter xAxisFormatter = new ValueFormatter(combinedChart);
        xAxisFormatter.setmValues(xAxisValue);
        xAxis.setValueFormatter(xAxisFormatter);//格式化x軸標簽顯示字符
        combinedChart.setData(combinedData);
        combinedChart.invalidate();
        if (showAnimation) {
            combinedChart.animateY(2000);
        }
    }
 
開發者ID:jay16,項目名稱:shengyiplus-android,代碼行數:81,代碼來源:HomeTricsActivity.java


注:本文中的com.github.mikephil.charting.components.XAxis.setLabelCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。