@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss"); // défini un nouveau format de date en string ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_statistics_linechart, container, false); LineChart chart = (LineChart) rootView.findViewById(R.id.firstChart); chart.setLogEnabled(true); chart.setNoDataTextDescription(getString(R.string.no_data)); ArrayList<DrinkIncome> incomesByDrink = getIncomes(); ArrayList<Entry> Income1 = new ArrayList<Entry>(); // creation d'un arrayList d'entrées pour le tableau ArrayList<Entry[]> drink2 = new ArrayList<Entry[]>(); ArrayList<Entry> drink3 = new ArrayList<Entry>(); ArrayList<Entry> drink4 = new ArrayList<Entry>(); ArrayList<Entry> drink5 = new ArrayList<Entry>(); ArrayList<String> xVals = new ArrayList<String>(); // creation d'une arrayList pour les valeurs des abscisses Iterator<DrinkIncome> it = incomesByDrink.iterator(); for (int i = 0; it.hasNext() && i < 5; i++) { DrinkIncome s = it.next(); Entry element = new Entry(s.getIncome(), i); Income1.add(element); // xVals.add(df.format(s.getDateOrder())); xVals.add("J-" + i); } LineDataSet setBestDrinks = new LineDataSet(Income1, getString(R.string.daily_incomes)); setBestDrinks.setDrawFilled(true); setBestDrinks.setColors( new int[] {R.color.blue1, R.color.blue2, R.color.blue3, R.color.blue1}, rootView.getContext()); ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); dataSets.add(setBestDrinks); LineData data = new LineData(xVals, dataSets); chart.setData(data); return rootView; }
/** * There is one chart for each signal type. Returns the chart component of a specific signal type. * * @return */ public LineChart getChart(String signalTypeId) { if (!charts.containsKey(signalTypeId)) { // Create a chart component // chart = (LineChart) findViewById(R.id.chart); final LineChart chart = new LineChart(this); // chart.setUnit("Db"); chart.setUnit(""); // chart.setDrawUnitsInChart(true); chart.setDrawYValues(false); chart.setDrawBorder(false); chart.setTouchEnabled(true); chart.setDragEnabled(true); chart.setNoDataTextDescription("No data gathered."); chart.setDescription("Samples"); chart.setPinchZoom(true); // if disabled, scaling can be done on x- and y-axis separately // set an alternative background color // mChart.setBackgroundColor(Color.GRAY) // Creates a chart tab. // http://www.java2s.com/Code/Android/UI/DynamicTabDemo.htm // http://www.java2s.com/Code/Android/UI/UsingatabcontentfactoryforthecontentviaTabHostTabSpecsetContentandroidwidgetTabHostTabContentFactory.htm TabHost.TabSpec spec = tabHost.newTabSpec(signalTypeId); spec.setIndicator(signalTypeId); spec.setContent( new TabHost.TabContentFactory() { public View createTabContent(String tag) { return chart; } }); tabHost.addTab(spec); // addContentToTab(tabHost.getChildCount(), chart); charts.put(signalTypeId, chart); tabHost.invalidate(); } return charts.get(signalTypeId); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = inflater.inflate(R.layout.kommfort, container, false); RelativeLayout relativ = (RelativeLayout) rootView.findViewById(R.id.bak); mLineChart = (LineChart) relativ.findViewById(R.id.linechartkommfort); mLineChart.setOnChartValueSelectedListener(this); // no description text mLineChart.setDescription("Beschleunigungskraefte"); mLineChart.setNoDataTextDescription("You need to provide data for the chart."); // enable highlighting mLineChart.setHighlightEnabled(true); // enable touch gestures mLineChart.setTouchEnabled(true); // enable scaling and dragging mLineChart.setDragEnabled(true); mLineChart.setScaleEnabled(true); mLineChart.setDrawGridBackground(false); // if disabled, scaling can be done on x- and y-axis separately mLineChart.setPinchZoom(true); // set an alternative background color mLineChart.setBackgroundColor(Color.WHITE); LineData data = new LineData(); data.setValueTextColor(Color.BLACK); // add empty data mLineChart.setData(data); // get the legend (only possible after setting data) Legend l = mLineChart.getLegend(); // modify the legend ... // l.setPosition(LegendPosition.LEFT_OF_CHART); l.setForm(Legend.LegendForm.LINE); l.setTextColor(Color.BLACK); XAxis xl = mLineChart.getXAxis(); xl.setTextColor(Color.BLACK); xl.setDrawGridLines(false); xl.setAvoidFirstLastClipping(true); YAxis leftAxis = mLineChart.getAxisLeft(); leftAxis.setTextColor(Color.BLACK); leftAxis.setAxisMaxValue(2f); leftAxis.setAxisMinValue(-2f); leftAxis.setStartAtZero(false); leftAxis.setDrawGridLines(true); YAxis rightAxis = mLineChart.getAxisRight(); rightAxis.setEnabled(false); Button zukamm = (Button) rootView.findViewById(R.id.butonzumkreis); // TextView zubesh=(TextView) rootView.findViewById(R.id.zubeschleunigungskraefte); // Layout button=(Layout) rootView.findViewById(R.id.); zukamm.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), KammsherKreis.class); Kommfort.this.startActivity(intent); } }); /** * zubesh.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { * Intent myIntent = new Intent(getActivity(), Beschleunigungskraefte.class); * getActivity().startActivityForResult(myIntent,100); } }); */ return rootView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.activity_realtime_chart); // Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // setSupportActionBar(toolbar); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_realtime_chart); // mChart = (LineChart) findViewById(R.id.chart1); mChart.setOnChartValueSelectedListener(this); mChart.setDescription("Sleep Cycle live chart"); mChart.setNoDataTextDescription("No sleep data available."); mChart.setTouchEnabled(true); mChart.setDragEnabled(true); mChart.setScaleEnabled(true); mChart.setPinchZoom(true); LineData data = new LineData(); mChart.setData(data); Typeface tf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); Legend l = mChart.getLegend(); l.setForm(Legend.LegendForm.LINE); l.setTypeface(tf); l.setTextColor(Color.WHITE); XAxis xl = mChart.getXAxis(); xl.setTypeface(tf); xl.setTextColor(Color.WHITE); xl.setDrawGridLines(false); xl.setAvoidFirstLastClipping(true); xl.setSpaceBetweenLabels(5); xl.setEnabled(true); YAxis leftAxis = mChart.getAxisLeft(); leftAxis.setTypeface(tf); leftAxis.setTextColor(Color.WHITE); leftAxis.setAxisMaxValue(100f); leftAxis.setAxisMinValue(0f); leftAxis.setStartAtZero(false); leftAxis.setDrawGridLines(true); YAxis rightAxis = mChart.getAxisRight(); rightAxis.setEnabled(false); // FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); // fab.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) // .setAction("Action", null).show(); // } // }); }