Search in sources :

Example 1 with CombinedData

use of com.github.mikephil.charting.data.CombinedData in project android-client by GenesisVision.

the class ProfitChartView method setChart.

public void setChart(List<Chart> charts) {
    if (charts.isEmpty()) {
        chart.clear();
        return;
    }
    List<Entry> lineEntries = new ArrayList<>();
    // List<BarEntry> barEntries = new ArrayList<>();
    float index = 0;
    for (Chart chart : charts) {
        lineEntries.add(new Entry(index, chart.getTotalProfit().floatValue()));
        // barEntries.add(new BarEntry(index, new float[]{
        // chart.getManagerFund().floatValue() + chart.getInvestorFund().floatValue(),
        // chart.getLoss().floatValue(),
        // chart.getProfit().floatValue()}));
        index++;
    }
    CombinedData data = new CombinedData();
    data.setData(getLineData(lineEntries));
    // data.setData(getBarData(barEntries));
    chart.setData(data);
}
Also used : Entry(com.github.mikephil.charting.data.Entry) BarEntry(com.github.mikephil.charting.data.BarEntry) ArrayList(java.util.ArrayList) CombinedData(com.github.mikephil.charting.data.CombinedData) Chart(io.swagger.client.model.Chart) CombinedChart(com.github.mikephil.charting.charts.CombinedChart)

Example 2 with CombinedData

use of com.github.mikephil.charting.data.CombinedData in project MPAndroidChart by PhilJay.

the class CombinedChartActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_combined);
    setTitle("CombinedChartActivity");
    chart = findViewById(R.id.chart1);
    chart.getDescription().setEnabled(false);
    chart.setBackgroundColor(Color.WHITE);
    chart.setDrawGridBackground(false);
    chart.setDrawBarShadow(false);
    chart.setHighlightFullBarEnabled(false);
    // draw bars behind lines
    chart.setDrawOrder(new DrawOrder[] { DrawOrder.BAR, DrawOrder.BUBBLE, DrawOrder.CANDLE, DrawOrder.LINE, DrawOrder.SCATTER });
    Legend l = chart.getLegend();
    l.setWordWrapEnabled(true);
    l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
    l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
    l.setOrientation(Legend.LegendOrientation.HORIZONTAL);
    l.setDrawInside(false);
    YAxis rightAxis = chart.getAxisRight();
    rightAxis.setDrawGridLines(false);
    // this replaces setStartAtZero(true)
    rightAxis.setAxisMinimum(0f);
    YAxis leftAxis = chart.getAxisLeft();
    leftAxis.setDrawGridLines(false);
    // this replaces setStartAtZero(true)
    leftAxis.setAxisMinimum(0f);
    XAxis xAxis = chart.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 months[(int) value % months.length];
        }
    });
    CombinedData data = new CombinedData();
    data.setData(generateLineData());
    data.setData(generateBarData());
    data.setData(generateBubbleData());
    data.setData(generateScatterData());
    data.setData(generateCandleData());
    data.setValueTypeface(tfLight);
    xAxis.setAxisMaximum(data.getXMax() + 0.25f);
    chart.setData(data);
    chart.invalidate();
}
Also used : Legend(com.github.mikephil.charting.components.Legend) IAxisValueFormatter(com.github.mikephil.charting.formatter.IAxisValueFormatter) AxisBase(com.github.mikephil.charting.components.AxisBase) CombinedData(com.github.mikephil.charting.data.CombinedData) XAxis(com.github.mikephil.charting.components.XAxis) YAxis(com.github.mikephil.charting.components.YAxis)

Example 3 with CombinedData

use of com.github.mikephil.charting.data.CombinedData in project MPAndroidChart by PhilJay.

the class CombinedChartRenderer method drawHighlighted.

@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()]));
    }
}
Also used : ChartData(com.github.mikephil.charting.data.ChartData) Highlight(com.github.mikephil.charting.highlight.Highlight) CombinedData(com.github.mikephil.charting.data.CombinedData) Chart(com.github.mikephil.charting.charts.Chart) CombinedChart(com.github.mikephil.charting.charts.CombinedChart)

Aggregations

CombinedData (com.github.mikephil.charting.data.CombinedData)3 CombinedChart (com.github.mikephil.charting.charts.CombinedChart)2 Chart (com.github.mikephil.charting.charts.Chart)1 AxisBase (com.github.mikephil.charting.components.AxisBase)1 Legend (com.github.mikephil.charting.components.Legend)1 XAxis (com.github.mikephil.charting.components.XAxis)1 YAxis (com.github.mikephil.charting.components.YAxis)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 ChartData (com.github.mikephil.charting.data.ChartData)1 Entry (com.github.mikephil.charting.data.Entry)1 IAxisValueFormatter (com.github.mikephil.charting.formatter.IAxisValueFormatter)1 Highlight (com.github.mikephil.charting.highlight.Highlight)1 Chart (io.swagger.client.model.Chart)1 ArrayList (java.util.ArrayList)1