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


Java ChartData类代码示例

本文整理汇总了Java中com.github.mikephil.charting.data.ChartData的典型用法代码示例。如果您正苦于以下问题:Java ChartData类的具体用法?Java ChartData怎么用?Java ChartData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: generateBarData

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
protected BarData generateBarData(int dataSets, float range, int count) {
        
        ArrayList<IBarDataSet> sets = new ArrayList<IBarDataSet>();
        
        for(int i = 0; i < dataSets; i++) {
           
            ArrayList<BarEntry> entries = new ArrayList<BarEntry>();
            
//            entries = FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "stacked_bars.txt");
            
            for(int j = 0; j < count; j++) {        
                entries.add(new BarEntry((float) (Math.random() * range) + range / 4, j));
            }
            
            BarDataSet ds = new BarDataSet(entries, getLabel(i));
            ds.setColors(ColorTemplate.VORDIPLOM_COLORS);
            sets.add(ds);
        }
        
        BarData d = new BarData(ChartData.generateXVals(0, count), sets);
        d.setValueTypeface(tf);
        return d;
    }
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:24,代码来源:SimpleFragment.java

示例2: generateScatterData

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
protected ScatterData generateScatterData(int dataSets, float range, int count) {
    
    ArrayList<IScatterDataSet> sets = new ArrayList<IScatterDataSet>();
    
    ScatterShape[] shapes = ScatterChart.getAllPossibleShapes();
    
    for(int i = 0; i < dataSets; i++) {
       
        ArrayList<Entry> entries = new ArrayList<Entry>();
        
        for(int j = 0; j < count; j++) {        
            entries.add(new Entry((float) (Math.random() * range) + range / 4, j));
        }
        
        ScatterDataSet ds = new ScatterDataSet(entries, getLabel(i));
        ds.setScatterShapeSize(12f);
        ds.setScatterShape(shapes[i % shapes.length]);
        ds.setColors(ColorTemplate.COLORFUL_COLORS);
        ds.setScatterShapeSize(9f);
        sets.add(ds);
    }
    
    ScatterData d = new ScatterData(ChartData.generateXVals(0, count), sets);
    d.setValueTypeface(tf);
    return d;
}
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:27,代码来源:SimpleFragment.java

示例3: drawHighlighted

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    Chart chart = mChart.get();
    if (chart == null) return;

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer)
            data = ((BarChartRenderer)renderer).mChart.getBarData();
        else if (renderer instanceof LineChartRenderer)
            data = ((LineChartRenderer)renderer).mChart.getLineData();
        else if (renderer instanceof CandleStickChartRenderer)
            data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
        else if (renderer instanceof ScatterChartRenderer)
            data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
        else if (renderer instanceof BubbleChartRenderer)
            data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();

        int dataIndex = data == null ? -1
                : ((CombinedData)chart.getData()).getAllData().indexOf(data);

        mHighlightBuffer.clear();

        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
                mHighlightBuffer.add(h);
        }

        renderer.drawHighlighted(c, mHighlightBuffer.toArray(new Highlight[mHighlightBuffer.size()]));
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:CombinedChartRenderer.java

示例4: setPieChart

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
/**
 * Set the pie pattern
 * @param pieChart chart
 * @param chartData pie chart data
 * @param title chart title
 * @param tf Typeface font
 */
public static void setPieChart(PieChart pieChart, ChartData<?> chartData,
                               SpannableString title, Typeface tf) {
    chartData.setValueFormatter(new PercentFormatter());
    chartData.setValueTextSize(11f);
    chartData.setValueTextColor(Color.BLACK);
    chartData.setValueTypeface(tf);

    pieChart.setUsePercentValues(true);
    pieChart.getDescription().setEnabled(false);
    pieChart.setExtraOffsets(5, 10, 5, 5);
    pieChart.setDragDecelerationFrictionCoef(0.95f);
    pieChart.setCenterTextTypeface(tf);
    pieChart.setCenterText(title);
    pieChart.setExtraOffsets(20.f, 0.f, 20.f, 0.f);
    pieChart.setDrawHoleEnabled(true);
    pieChart.setHoleColor(Color.WHITE);
    pieChart.setTransparentCircleColor(Color.WHITE);
    pieChart.setTransparentCircleAlpha(110);
    pieChart.setHoleRadius(58f);
    pieChart.setTransparentCircleRadius(61f);
    pieChart.setDrawCenterText(true);
    pieChart.setRotationAngle(0);
    pieChart.setRotationEnabled(true);// enable rotation of the chart by touch
    pieChart.setHighlightPerTapEnabled(true);
    pieChart.setEntryLabelTextSize(10f);

    Legend l = pieChart.getLegend();
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
    l.setOrientation(Legend.LegendOrientation.VERTICAL);
    l.setDrawInside(false);
    l.setEnabled(false);

    pieChart.setData((PieData) chartData);
    pieChart.animateY(DURATION_MEDIUM, Easing.EasingOption.EaseInOutQuad);
    pieChart.highlightValues(null);// undo all highlights
    pieChart.invalidate();

}
 
开发者ID:graviton57,项目名称:DOUSalaries,代码行数:47,代码来源:ChartHelper.java

示例5: setLineChart

import com.github.mikephil.charting.data.ChartData; //导入依赖的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

示例6: setHorizontalBarChart

import com.github.mikephil.charting.data.ChartData; //导入依赖的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

示例7: setVerticalBarChart

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
/**
 * Set the vertical bar  pattern
 * @param barChart chart
 * @param chartData pie chart data
 * @param typeface Typeface font
 */
public static void setVerticalBarChart(Context context, BarChart barChart, ChartData<?> chartData,
                                        Typeface typeface) {
    // create a custom MarkerView (extend MarkerView) and specify the layout to use for it
    ExperienceMarker marker = new ExperienceMarker(context, R.layout.marker_exp_age);
    marker.setChartView(barChart); // For bounds control
    barChart.setMarker(marker);
    //fix crash com.github.mikephil.charting.charts.Chart.drawMarkers(Chart.java:731)
    barChart.setDrawMarkers(false);

    barChart.getDescription().setEnabled(false);
    barChart.setDrawGridBackground(false);
    barChart.setDrawBarShadow(false);
    XAxis xAxis = barChart.getXAxis();
    xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
    //Sets the number of labels for the x-axis (display all the x-axis values)
   // xAxis.setLabelCount(chartData.getEntryCount());
    xAxis.setTypeface(typeface);
    xAxis.setDrawGridLines(false);
    xAxis.setDrawAxisLine(true);
    YAxis leftAxis = barChart.getAxisLeft();
    leftAxis.setTypeface(typeface);
    leftAxis.setSpaceTop(20f);
    leftAxis.setAxisMinimum(0f);

    YAxis rightAxis = barChart.getAxisRight();
    rightAxis.setTypeface(typeface);
    rightAxis.setSpaceTop(20f);
    rightAxis.setAxisMinimum(0f);
    chartData.setValueTypeface(typeface);
    barChart.setData((BarData) chartData);
    barChart.setFitBars(true);
    barChart.animateY(DURATION_SHORT);
}
 
开发者ID:graviton57,项目名称:DOUSalaries,代码行数:40,代码来源:ChartHelper.java

示例8: GroupBarChartItem

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
public GroupBarChartItem(Context context, ChartData<?> chartData ) {
    super(chartData);
    this.context = context;
    this.typeface = Typeface.createFromAsset(context.getAssets(), "fonts/OpenSans-Regular.ttf");
    this.language = "";
    this.start = 0;
}
 
开发者ID:graviton57,项目名称:DOUSalaries,代码行数:8,代码来源:GroupBarChartItem.java

示例9: HorizontalBarChartItem

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
public HorizontalBarChartItem(Context context, ChartData<?> chartData) {
    super(chartData);
    this.typeface = Typeface.createFromAsset(context.getAssets(), "fonts/OpenSans-Regular.ttf");
    this.jobTitles = AppUtils.reverseArray(
            context.getResources().getStringArray(R.array.array_job_title));
    this.title = "";
}
 
开发者ID:graviton57,项目名称:DOUSalaries,代码行数:8,代码来源:HorizontalBarChartItem.java

示例10: LineChartItem

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
public LineChartItem(Context context, ChartData<?> chartData, String language) {
    super(chartData);
    this.typeface = Typeface.createFromAsset(context.getAssets(), "fonts/OpenSans-Regular.ttf");
    this.context = context;
    this.title = language;
    this.month = AppUtils.reverseArray(
            context.getResources().getStringArray(R.array.array_period_date));
}
 
开发者ID:graviton57,项目名称:DOUSalaries,代码行数:9,代码来源:LineChartItem.java

示例11: generateLineData

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
protected LineData generateLineData() {
        
//        DataSet ds1 = new DataSet(n, "O(n)");  
//        DataSet ds2 = new DataSet(nlogn, "O(nlogn)"); 
//        DataSet ds3 = new DataSet(nsquare, "O(n\u00B2)");
//        DataSet ds4 = new DataSet(nthree, "O(n\u00B3)");
        
        ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
        
        LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "sine.txt"), "Sine function");
        LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "cosine.txt"), "Cosine function");
        
        ds1.setLineWidth(2f);
        ds2.setLineWidth(2f);
        
        ds1.setDrawCircles(false);
        ds2.setDrawCircles(false);
        
        ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
        ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]);
        
        // load DataSets from textfiles in assets folders
        sets.add(ds1);
        sets.add(ds2);
        
//        sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "n.txt"));
//        sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "nlogn.txt"));
//        sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "square.txt"));
//        sets.add(FileUtils.dataSetFromAssets(getActivity().getAssets(), "three.txt"));
        
        int max = Math.max(sets.get(0).getEntryCount(), sets.get(1).getEntryCount());
        
        LineData d = new LineData(ChartData.generateXVals(0, max),  sets);
        d.setValueTypeface(tf);
        return d;
    }
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:37,代码来源:SimpleFragment.java

示例12: getComplexity

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
protected LineData getComplexity() {
    
    ArrayList<ILineDataSet> sets = new ArrayList<ILineDataSet>();
    
    LineDataSet ds1 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "n.txt"), "O(n)");
    LineDataSet ds2 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "nlogn.txt"), "O(nlogn)");
    LineDataSet ds3 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "square.txt"), "O(n\u00B2)");
    LineDataSet ds4 = new LineDataSet(FileUtils.loadEntriesFromAssets(getActivity().getAssets(), "three.txt"), "O(n\u00B3)");
    
    ds1.setColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    ds2.setColor(ColorTemplate.VORDIPLOM_COLORS[1]);
    ds3.setColor(ColorTemplate.VORDIPLOM_COLORS[2]);
    ds4.setColor(ColorTemplate.VORDIPLOM_COLORS[3]);
    
    ds1.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[0]);
    ds2.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[1]);
    ds3.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[2]);
    ds4.setCircleColor(ColorTemplate.VORDIPLOM_COLORS[3]);
    
    ds1.setLineWidth(2.5f);
    ds1.setCircleRadius(3f);
    ds2.setLineWidth(2.5f);
    ds2.setCircleRadius(3f);
    ds3.setLineWidth(2.5f);
    ds3.setCircleRadius(3f);
    ds4.setLineWidth(2.5f);
    ds4.setCircleRadius(3f);
    
    
    // load DataSets from textfiles in assets folders
    sets.add(ds1);        
    sets.add(ds2);
    sets.add(ds3);
    sets.add(ds4);
    
    LineData d = new LineData(ChartData.generateXVals(0, ds1.getEntryCount()), sets);
    d.setValueTypeface(tf);
    return d;
}
 
开发者ID:rahulmaddineni,项目名称:Stayfit,代码行数:40,代码来源:SimpleFragment.java

示例13: drawHighlighted

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {

    Chart chart = mChart.get();
    if (chart == null) return;

    for (DataRenderer renderer : mRenderers) {
        ChartData data = null;

        if (renderer instanceof BarChartRenderer)
            data = ((BarChartRenderer)renderer).mChart.getBarData();
        else if (renderer instanceof LineChartRenderer)
            data = ((LineChartRenderer)renderer).mChart.getLineData();
        else if (renderer instanceof CandleStickChartRenderer)
            data = ((CandleStickChartRenderer)renderer).mChart.getCandleData();
        else if (renderer instanceof ScatterChartRenderer)
            data = ((ScatterChartRenderer)renderer).mChart.getScatterData();
        else if (renderer instanceof BubbleChartRenderer)
            data = ((BubbleChartRenderer)renderer).mChart.getBubbleData();

        int dataIndex = data == null
                ? -1
                : ((CombinedData)chart.getData()).getAllData().indexOf(data);

        ArrayList<Highlight> dataIndices = new ArrayList<>();
        for (Highlight h : indices) {
            if (h.getDataIndex() == dataIndex || h.getDataIndex() == -1)
                dataIndices.add(h);
        }

        renderer.drawHighlighted(c, dataIndices.toArray(new Highlight[dataIndices.size()]));

    }
}
 
开发者ID:pencil-box,项目名称:NetKnight,代码行数:35,代码来源:CombinedChartRenderer.java

示例14: getSelectionDetailsAtIndex

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
/**
 * Returns a list of SelectionDetail object corresponding to the given xIndex.
 *
 * @param xIndex
 * @return
 */
@Override
protected List<SelectionDetail> getSelectionDetailsAtIndex(int xIndex, int dataSetIndex) {

    List<SelectionDetail> vals = new ArrayList<SelectionDetail>();
    float[] pts = new float[2];

    CombinedData data = (CombinedData) mChart.getData();

    // get all chartdata objects
    List<ChartData> dataObjects = data.getAllData();

    for (int i = 0; i < dataObjects.size(); i++) {

        for(int j = 0; j < dataObjects.get(i).getDataSetCount(); j++) {

            IDataSet dataSet = dataObjects.get(i).getDataSetByIndex(j);

            // dont include datasets that cannot be highlighted
            if (!dataSet.isHighlightEnabled())
                continue;

            // extract all y-values from all DataSets at the given x-index
            final float yVals[] = dataSet.getYValsForXIndex(xIndex);
            for (float yVal : yVals) {
                pts[1] = yVal;

                mChart.getTransformer(dataSet.getAxisDependency()).pointValuesToPixel(pts);

                if (!Float.isNaN(pts[1])) {
                    vals.add(new SelectionDetail(pts[1], yVal, i, j, dataSet));
                }
            }
        }
    }

    return vals;
}
 
开发者ID:pencil-box,项目名称:NetKnight,代码行数:44,代码来源:CombinedHighlighter.java

示例15: setData

import com.github.mikephil.charting.data.ChartData; //导入依赖的package包/类
/**
 *
 * Dataset config details: https://github.com/PhilJay/MPAndroidChart/wiki/DataSet-classes-in-detail
 */
@ReactProp(name = "data")
public void setData(Chart chart, ReadableMap propMap) {
    if (!BridgeUtils.validate(propMap, ReadableType.Array, "datasets")) {
        return;
    }

    String[] xValues = new String[0];
    if (BridgeUtils.validate(propMap, ReadableType.Array, "xValues")) {
        xValues = BridgeUtils.convertToStringArray(propMap.getArray("xValues"));
    }

    ChartData<IDataSet<U>> chartData = createData(xValues);

    ReadableArray datasets = propMap.getArray("datasets");
    for (int i = 0; i < datasets.size(); i++) {
        ReadableMap dataset = datasets.getMap(i);

        // TODO validation
        ReadableArray yValues = dataset.getArray("yValues");
        String label = dataset.getString("label");

        ArrayList<U> entries = createEntries(yValues);

        IDataSet<U> lineDataSet = createDataSet(entries, label);

        if (BridgeUtils.validate(dataset, ReadableType.Map, "config")) {
            dataSetConfig(lineDataSet, dataset.getMap("config"));
        }

        chartData.addDataSet(lineDataSet);
    }

    chart.setData(chartData);
    chart.invalidate();
}
 
开发者ID:mskec,项目名称:react-native-mp-android-chart,代码行数:40,代码来源:ChartBaseManager.java


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