private void initChart() { // 初始化,必须保证XYMultipleSeriesDataset对象中的XYSeries数量和 // XYMultipleSeriesRenderer对象中的XYSeriesRenderer数量一样多 line1 = new XYSeries("折线1"); line2 = new XYSeries("折线2"); renderer1 = new XYSeriesRenderer(); renderer2 = new XYSeriesRenderer(); mDataset = new XYMultipleSeriesDataset(); mXYMultipleSeriesRenderer = new XYMultipleSeriesRenderer(); // 对XYSeries和XYSeriesRenderer的对象的参数赋值 // initLine(line1); // initLine(line2); initRenderer(renderer1, Color.GREEN, PointStyle.CIRCLE, true); initRenderer(renderer2, Color.CYAN, PointStyle.TRIANGLE, true); // 将XYSeries对象和XYSeriesRenderer对象分别添加到XYMultipleSeriesDataset对象和XYMultipleSeriesRenderer对象中。 mDataset.addSeries(line1); mDataset.addSeries(line2); mXYMultipleSeriesRenderer.addSeriesRenderer(renderer1); mXYMultipleSeriesRenderer.addSeriesRenderer(renderer2); // 配置chart参数 setChartSettings(mXYMultipleSeriesRenderer, "X", "Y", 0, 10, 0, 100, Color.RED, Color.WHITE); // 通过该函数获取到一个View 对象 chart = ChartFactory.getLineChartView(this, mDataset, mXYMultipleSeriesRenderer); // 将该View 对象添加到layout中。 dynamic_chart_line_layout.addView( chart, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); }
private void initView(View view) { // TODO Auto-generated method stub mLightView = (TextView) view.findViewById(R.id.info_light_data); XYSeries series = new XYSeries(""); mDataset.addSeries(series); mCurrentSeries = series; XYSeriesRenderer renderer = new XYSeriesRenderer(); mRenderer.addSeriesRenderer(renderer); renderer.setPointStyle(PointStyle.CIRCLE); renderer.setFillPoints(true); renderer.setDisplayChartValues(true); renderer.setDisplayChartValuesDistance(20); renderer.setChartValuesTextSize(15); mCurrentRenderer = renderer; // set data mCurrentSeries.clear(); LinearLayout parentLayout = (LinearLayout) view.findViewById(R.id.chart_layout); mChartView = ChartFactory.getLineChartView(getActivity(), mDataset, mRenderer); parentLayout.addView( mChartView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); // 平均值 Date day = TimeController.getToday(); day = TimeController.getDayDiffDay(-6, day); for (int i = 1; i <= 7; i++) { mRenderer.addXTextLabel(i, TimeController.getDayString(day)); Integer light = getAverageLight(day); mCurrentSeries.add(i, light); day = TimeController.getTomorrow(day); } mChartView.repaint(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cost_graph); parentTabbedActivity = (TabbedOutputActivity) getParent(); calculatorList = parentTabbedActivity.getCalculators(); GraphicalView savingsChart = ChartFactory.getLineChartView(this, getCostsDataset(), getCostsRenderer()); setContentView(savingsChart); }
@Override protected void onResume() { super.onResume(); if (mChartView == null) { LinearLayout layout = (LinearLayout) findViewById(R.id.chart); layout.setVisibility(View.INVISIBLE); mChartView = ChartFactory.getLineChartView(this, mDataset, mRenderer); // enable the chart click events mRenderer.setClickEnabled(true); mRenderer.setSelectableBuffer(10); mChartView.setOnClickListener( new View.OnClickListener() { public void onClick(View v) {} }); layout.addView( mChartView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); } else { mChartView.repaint(); } }
private void initView(View view) { // TODO Auto-generated method stub mLightView = (TextView) view.findViewById(R.id.info_light_data); XYSeries series = new XYSeries(""); mDataset.addSeries(series); mCurrentSeries = series; XYSeriesRenderer renderer = new XYSeriesRenderer(); mRenderer.addSeriesRenderer(renderer); renderer.setPointStyle(PointStyle.CIRCLE); renderer.setFillPoints(true); renderer.setDisplayChartValues(true); renderer.setDisplayChartValuesDistance(20); renderer.setChartValuesTextSize(15); mCurrentRenderer = renderer; // set data mCurrentSeries.clear(); LinearLayout parentLayout = (LinearLayout) view.findViewById(R.id.chart_layout); mChartView = ChartFactory.getLineChartView(getActivity(), mDataset, mRenderer); parentLayout.addView( mChartView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); }
/** Called when the fragment is first created. */ @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ScrollView view = (ScrollView) inflater.inflate(R.layout.clima, container, false); context = getActivity(); ((MainActivity) context).setFooter(R.id.footer_sensor); RelativeLayout row1 = (RelativeLayout) view.findViewById(R.id.temp); RelativeLayout row2 = (RelativeLayout) view.findViewById(R.id.humi); RelativeLayout row3 = (RelativeLayout) view.findViewById(R.id.baro); Animation animation = AnimationUtils.loadAnimation(context, R.anim.push_top_in); row1.startAnimation(animation); row2.startAnimation(animation); row3.startAnimation(animation); humidity = (TextView) view.findViewById(R.id.humidity); barometric = (TextView) view.findViewById(R.id.barometric); temperature = (TextView) view.findViewById(R.id.temperature); app = (Node) context.getApplication(); sensor = app.getSensor(); // Tempurature LinearLayout chart1 = (LinearLayout) view.findViewById(R.id.chart1); tempRenderer = Node.getGraphStyle(tempRenderer, context); tempChartView = ChartFactory.getLineChartView(context, tempDataset, tempRenderer); chart1.addView( tempChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); tempChartView.repaint(); tempSeries = new XYSeries("temp"); tempDataset.addSeries(tempSeries); XYSeriesRenderer renderer1 = new XYSeriesRenderer(); tempRenderer.addSeriesRenderer(renderer1); // renderer.setPointStyle(PointStyle.CIRCLE); // renderer.setFillPoints(true); renderer1.setLineWidth(4); renderer1.setColor(Color.RED); tempArray = new ArrayList<Double>(); // Humidity LinearLayout chart2 = (LinearLayout) view.findViewById(R.id.chart2); humiRenderer = Node.getGraphStyle(humiRenderer, context); humiChartView = ChartFactory.getLineChartView(context, humiDataset, humiRenderer); chart2.addView( humiChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); humiChartView.repaint(); humiSeries = new XYSeries("humi"); humiDataset.addSeries(humiSeries); XYSeriesRenderer renderer2 = new XYSeriesRenderer(); humiRenderer.addSeriesRenderer(renderer2); // renderer.setPointStyle(PointStyle.CIRCLE); // renderer.setFillPoints(true); renderer2.setLineWidth(4); renderer2.setColor(Color.RED); humiArray = new ArrayList<Double>(); // Pressure LinearLayout chart3 = (LinearLayout) view.findViewById(R.id.chart3); presRenderer = Node.getGraphStyle(presRenderer, context); presChartView = ChartFactory.getLineChartView(context, presDataset, presRenderer); chart3.addView( presChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); presChartView.repaint(); presSeries = new XYSeries("pres"); presDataset.addSeries(presSeries); XYSeriesRenderer renderer3 = new XYSeriesRenderer(); presRenderer.addSeriesRenderer(renderer3); // renderer.setPointStyle(PointStyle.CIRCLE); // renderer.setFillPoints(true); renderer3.setLineWidth(4); renderer3.setColor(Color.RED); presArray = new ArrayList<Double>(); return view; }
public GraphicalView getView(Context context) { view = ChartFactory.getLineChartView(context, mDataset, mRenderer); return view; }
public View getmChartView() { mChartView = ChartFactory.getLineChartView(getActivity(), mDataset, mRenderer); return mChartView; }
public WifiChart() { mDataset = new XYMultipleSeriesDataset(); mRenderer = new XYMultipleSeriesRenderer(); mChartView = ChartFactory.getLineChartView(getActivity(), mDataset, mRenderer); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); return; } dispRunTime = (TextView) findViewById(R.id.dispRunTime); dispTemp = (TextView) findViewById(R.id.dispTemp); dispRoc = (TextView) findViewById(R.id.dispRoc); dispWRoC = (TextView) findViewById(R.id.dispTargRoc); dispMaxT = (TextView) findViewById(R.id.dispMaxTemp); alarmSet = (ZoomControls) findViewById(R.id.alarmSet); dispAlarmTemp = (TextView) findViewById(R.id.AlarmTemp); // dispLogData = (ListView) findViewById(R.id.listLogData); // ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, // android.R.layout.simple_list_item_1, logValues); // setListAdapter(adapter); tempBar = (SeekBar) findViewById(R.id.tempBar); tempBar.setOnSeekBarChangeListener(this); tempBar.setMax(100); tempBar.setProgress(50); Log.v(TAG, "onCreate - add data"); mDataset.addSeries(liveGraphXYSeries); Log.v(TAG, "onCreate - set render"); mRenderer.setAxisTitleTextSize(14); mRenderer.setChartTitleTextSize(16); mRenderer.setLabelsTextSize(13); mRenderer.setLegendTextSize(13); mRenderer.setPointSize(5f); mRenderer.setMargins(new int[] {10, 20, 8, 10}); // mRenderer.setXAxisMax(600); mRenderer.setYAxisMax(240); int[] colors = new int[] {Color.GREEN}; PointStyle[] styles = new PointStyle[] {PointStyle.POINT}; int length = colors.length; for (int i = 0; i < length; i++) { Log.v(TAG, "onCreate - add renderes"); XYSeriesRenderer r = new XYSeriesRenderer(); r.setColor(colors[i]); r.setPointStyle(styles[i]); mRenderer.addSeriesRenderer(r); } Button start = (Button) findViewById(R.id.ButtonStart); Button stop = (Button) findViewById(R.id.ButtonStop); Button reset = (Button) findViewById(R.id.buttonReset); Button acceptTemps = (Button) findViewById(R.id.buttonAcceptVariance); start.setOnClickListener(startClickHandler); stop.setOnClickListener(stopClickHandler); reset.setOnClickListener(resetClickHandler); acceptTemps.setOnClickListener(acceptTempsClickHandler); alarmSet.setOnZoomInClickListener(tempUpClickHandler); alarmSet.setOnZoomOutClickListener(tempDownClickHandler); Intent a = new Intent(this, TempService.class); startService(a); // Binding ..this block can also start service if not started already Intent bindIntent = new Intent(this, TempService.class); bindService(bindIntent, serviceConncetion, Context.BIND_AUTO_CREATE); // Register Broadcast Receiver IntentFilter filter = new IntentFilter(TempService.MYOWNACTIONFILTER); registerReceiver(myReceiver, filter); // Set our 'default' temp - entire array is set so the average is what we expect. for (int i = 0; i < 5; i++) tempValues[i] = runTemp; // dispTemp.setText("Temp: " + String.valueOf(tempValues[0])); Log.v(TAG, "onCreate - main"); if (mChartView == null) { Log.v(TAG, "onCreate - before chart layout"); LinearLayout layout = (LinearLayout) findViewById(R.id.chart); Log.v(TAG, "onCreate - before chart Factory"); mChartView = ChartFactory.getLineChartView(this, mDataset, mRenderer); Log.v(TAG, "onCreate - before chart addview"); layout.addView( mChartView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); } else { mChartView.repaint(); } final EditText edittext = (EditText) findViewById(R.id.simulateSpeed); edittext.setOnKeyListener( new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" button if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) { // Perform action on key press currentSimulateSpeed = Integer.parseInt(edittext.getText().toString()); tempUpdService.simluateMode(currentSimulateMode, currentSimulateSpeed); return true; } return false; } }); final CheckBox checkbox = (CheckBox) findViewById(R.id.cSimulate); if (checkbox != null) { checkbox.setOnClickListener( new OnClickListener() { public void onClick(View v) { // Perform action on clicks, depending on whether it's now checked if (((CheckBox) v).isChecked()) { currentSimulateMode = true; } else { currentSimulateMode = false; } tempUpdService.simluateMode(currentSimulateMode, currentSimulateSpeed); } }); } OnClickListener radio_listener = new OnClickListener() { public void onClick(View v) { // Perform action on clicks RadioButton rb = (RadioButton) v; Toast.makeText(Coffee2ohActivity.this, rb.getText(), Toast.LENGTH_SHORT).show(); switch (v.getId()) { case R.id.runAuto: tempUpdService.setRunMode(TempService.RunModeAuto); break; case R.id.runOff: tempUpdService.setRunMode(TempService.RunModeStop); break; case R.id.runHold: tempUpdService.setRunMode(TempService.RunModeHold); break; case R.id.runManual: tempUpdService.setRunMode(TempService.RunModeManual); break; } } }; final RadioButton rbAuto = (RadioButton) findViewById(R.id.runAuto); final RadioButton rbStop = (RadioButton) findViewById(R.id.runOff); final RadioButton rbHold = (RadioButton) findViewById(R.id.runHold); final RadioButton rbManual = (RadioButton) findViewById(R.id.runManual); rbAuto.setOnClickListener(radio_listener); rbManual.setOnClickListener(radio_listener); rbStop.setOnClickListener(radio_listener); if (rbHold != null) { rbHold.setOnClickListener(radio_listener); } } // End OnCreate
public void AChart() { // mDataset = new XYMultipleSeriesDataset(); // mRenderer = new XYMultipleSeriesRenderer(); // mCurrentRenderer = new XYSeriesRenderer(); mRenderer.setApplyBackgroundColor(true); // 设置是否显示背景色 mRenderer.setBackgroundColor(Color.argb(50, 214, 241, 255)); // 设置背景色 mRenderer.setAxisTitleTextSize(32); // 设置轴标题文字的大小 mRenderer.setAxesColor(Color.BLACK); // 坐标轴颜色 mRenderer.setChartTitleTextSize(32); // ?设置整个图表标题文字大小 mRenderer.setChartTitle(appState.userID); mRenderer.setXLabelsColor(Color.BLACK); // 设置X轴刻度颜色 mRenderer.setYLabelsColor(0, Color.BLACK); // 设置Y轴刻度颜色 mRenderer.setLabelsTextSize(32); // 设置刻度显示文字的大小(XY轴都会被设置) mRenderer.setLegendTextSize(32); // 图例文字大小 mRenderer.setMargins(new int[] {30, 30, 50, 10}); // 设置图表的外边框(上/左/下/右) mRenderer.setMarginsColor(Color.argb(50, 214, 241, 255)); // 边框颜色 mRenderer.setZoomButtonsVisible(false); // 是否显示放大缩小按钮 mRenderer.setShowGrid(true); // 显示网格 mRenderer.setPointSize(10); // 设置点的大小(图上显示的点的大小和图例中点的大小都会被设置) String seriesTitle = "I-Sleep"; if (mDataset.getSeriesCount() > 0) { mDataset.removeSeries(0); mRenderer.removeAllRenderers(); } XYSeries series = new XYSeries(seriesTitle); // 定义XYSeries mDataset.addSeries(series); // 在XYMultipleSeriesDataset中添加XYSeries mCurrentSeries = series; // 设置当前需要操作的XYSeries \ addPoint(); XYSeriesRenderer renderer = new XYSeriesRenderer(); // 定义XYSeriesRenderer mRenderer.addSeriesRenderer(renderer); // 将单个XYSeriesRenderer增加到XYMultipleSeriesRenderer renderer.setPointStyle(PointStyle.CIRCLE); // 点的类型是圆形 renderer.setFillPoints(true); // 设置点是否实心 renderer.setColor(Color.BLUE); // 折线颜色 mCurrentRenderer = renderer; // if (mChartView == null) { if (layout != null) { layout.removeAllViews(); } layout = (LinearLayout) getActivity().findViewById(R.id.chart); mChartView = ChartFactory.getLineChartView(getActivity().getApplicationContext(), mDataset, mRenderer); mRenderer.setClickEnabled(true); // 设置图表是否允许点击 mRenderer.setSelectableBuffer(100); // 设置点的缓冲半径值(在某点附件点击时,多大范围内都算点击这个点) mChartView.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // 这段代码处理点击一个点后,获得所点击的点在哪个序列中以及点的坐标. // -->start SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint(); double[] xy = mChartView.toRealPoint(0); if (seriesSelection == null) { // Toast.makeText(getActivity().getApplicationContext(), "No chart // element was clicked", Toast.LENGTH_SHORT).show(); } else { // Toast.makeText(getActivity().getApplicationContext(), // "Chart element in series index " + // seriesSelection.getSeriesIndex() // + " data point index " + seriesSelection.getPointIndex() + " // was clicked" // + " closest point value X=" + seriesSelection.getXValue() + // ", Y=" + seriesSelection.getValue() // + " clicked point value X=" + (float) xy[0] + ", Y=" + // (float) xy[1], Toast.LENGTH_SHORT).show(); // tv_graphdata.setText("X = " + // String.valueOf(seriesSelection.getXValue()) + // " Y = " + String.valueOf(seriesSelection.getValue())); tv_graphdata.setText( appState.userID + " " + appState.userName + " " + "Duration:" + duration[(int) seriesSelection.getXValue() - 1] + "hours\n" + "Starttime:" + starttime[(int) seriesSelection.getXValue() - 1] + "\n" + "Endtime:" + endtime[(int) seriesSelection.getXValue() - 1]); tv_graphdata.setTextSize(16); // 播放音频 if (!"".equals(recfile[(int) seriesSelection.getXValue() - 1])) { playRecWithSysPlayer(recfile[(int) seriesSelection.getXValue() - 1]); } else { Toast.makeText(getActivity(), "There's no record.", Toast.LENGTH_LONG).show(); } } // -->end } }); mChartView.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint(); if (seriesSelection == null) { // Toast.makeText(XYChartBuilder.this, "No chart element was long // pressed",Toast.LENGTH_SHORT); return false; // no chart element was long pressed, so let something // else handle the event } else { // Toast.makeText(XYChartBuilder.this, "Chart element in series index " // + seriesSelection.getSeriesIndex() + " data point index " // + seriesSelection.getPointIndex() + " was long pressed", // Toast.LENGTH_SHORT); return true; // the element was long pressed - the event has been // handled } } }); // 这段代码处理放大缩小 // -->start mChartView.addZoomListener( new ZoomListener() { public void zoomApplied(ZoomEvent e) { String type = "out"; if (e.isZoomIn()) { type = "in"; } System.out.println("Zoom " + type + " rate " + e.getZoomRate()); } public void zoomReset() { System.out.println("Reset"); } }, true, true); // -->end // 设置拖动图表时后台打印出图表坐标的最大最小值. mChartView.addPanListener( new PanListener() { public void panApplied() { System.out.println( "New X range=[" + mRenderer.getXAxisMin() + ", " + mRenderer.getXAxisMax() + "], Y range=[" + mRenderer.getYAxisMax() + ", " + mRenderer.getYAxisMax() + "]"); } }); layout.addView( mChartView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); boolean enabled = mDataset.getSeriesCount() > 0; // } else { // mChartView.repaint(); // } }
private void OpenChart() { int x[] = {10, 18, 32, 21, 48, 60, 53, 80}; XYSeries xySeries = new XYSeries("X Series"); for (int i = 0; i < 8; i++) { xySeries.add(i, x[i]); } XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); dataset.addSeries(xySeries); XYSeriesRenderer renderer = new XYSeriesRenderer(); renderer.setColor(Color.GREEN); renderer.setPointStyle(PointStyle.DIAMOND); renderer.setDisplayChartValues(true); renderer.setLineWidth(2); renderer.setFillPoints(true); XYMultipleSeriesRenderer multipleSeriesRenderer = new XYMultipleSeriesRenderer(); multipleSeriesRenderer.setChartTitle("X-Y Chart"); multipleSeriesRenderer.setXTitle("X Values"); multipleSeriesRenderer.setYTitle("Y values"); multipleSeriesRenderer.setZoomButtonsVisible(true); multipleSeriesRenderer.setXLabels(0); multipleSeriesRenderer.setPanEnabled(false); multipleSeriesRenderer.setShowGrid(true); multipleSeriesRenderer.setClickEnabled(true); for (int i = 0; i < 8; i++) { multipleSeriesRenderer.addXTextLabel(i, mMonth[i]); } multipleSeriesRenderer.addSeriesRenderer(renderer); LinearLayout chart_container = (LinearLayout) findViewById(R.id.chart_layout); mChart = (GraphicalView) ChartFactory.getLineChartView(getBaseContext(), dataset, multipleSeriesRenderer); mChart.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { SeriesSelection series_selection = mChart.getCurrentSeriesAndPoint(); if (series_selection != null) { int series_index = series_selection.getSeriesIndex(); String select_seriese = "X Series"; if (series_index == 0) { select_seriese = "X Series"; } else { select_seriese = "Y Series"; } String month = mMonth[(int) series_selection.getXValue()]; int amount = (int) series_selection.getValue(); Toast.makeText( getBaseContext(), select_seriese + "in" + month + ":" + amount, Toast.LENGTH_LONG) .show(); } } }); chart_container.addView(mChart); }