餘額寶折線高仿

本文章部分參考

仿餘額寶收益圖實現 | 阿土's Blog



	/**
	 * 繪製折線
	 */
	private void initLineChartView() {
		long now = new Date().getTime();// 當前時間
		long t = 86400000;
		GraphViewSeries exampleSeries = new GraphViewSeries("",
				new GraphViewSeriesStyle(Color.rgb(0, 113, 185), DensityUtil
						.dip2px(MyDemoActivity.this, 3)),// 折線顏色(深藍色)
				new GraphViewData[] {
						new GraphViewData(now - 6 * t, Double.parseDouble(str1)),
						new GraphViewData(now - 5 * t, Double.parseDouble(str2)),
						new GraphViewData(now - 4 * t, Double.parseDouble(str3)),
						new GraphViewData(now - 3 * t, Double.parseDouble(str4)),
						new GraphViewData(now - 2 * t, Double.parseDouble(str5)),
						new GraphViewData(now - 1 * t, Double.parseDouble(str6)),
						new GraphViewData(now, Double.parseDouble(str7)) });
		GraphView graphView;
		graphView = new LineGraphView(MyDemoActivity.this, "");
		((LineGraphView) graphView).setDrawBackground(true);

		// ((LineGraphView) graphView)
		// .setBackgroundColor(Color.rgb(191, 230, 248));// 選擇的背景顏色(淡藍色)
		((LineGraphView) graphView).setBackgroundColor(Color
				.parseColor("#200292D7"));// 選擇的背景顏色(淡藍色)
		((LineGraphView) graphView).setDataPointsRadius(0);

		/** 字體色 */
		int fontColor = Color.parseColor("#808080");
		// 風格色//表格線顏色
		graphView.getGraphViewStyle().setGridColor(Color.parseColor("#D8DDE3"));
		graphView.getGraphViewStyle().setHorizontalLabelsColor(fontColor);
		graphView.getGraphViewStyle().setVerticalLabelsColor(fontColor);
		// x軸標籤數
		graphView.getGraphViewStyle().setNumHorizontalLabels(7);
		// y軸標籤數
		graphView.getGraphViewStyle().setNumVerticalLabels(7);
		//
		// 隱藏y軸標籤
		graphView.setShowVerticalLabels(false);
		// 字號 yx軸
		graphView.getGraphViewStyle().setTextSize(
				DensityUtil.dip2px(MyDemoActivity.this, 8));
		// 圖標利率數值字號
		graphView.getGraphViewStyle().setTextSizeDot(
				DensityUtil.dip2px(MyDemoActivity.this, 15));
		// 虛擬字體 爲了空間大一點
		// graphView.getGraphViewStyle().setTextSizeDots(
		// DensityUtil.dip2px(MyDemoActivity.this, 16));
		graphView.getGraphViewStyle().setVerticalLabelsAlign(Align.RIGHT);
		graphView.getGraphViewStyle().setVerticalLabelsWidth(
				DensityUtil.dip2px(MyDemoActivity.this, 37));// 設置寬度(兩列的寬度)

		graphView.addSeries(exampleSeries);

		final SimpleDateFormat dateFormat = new SimpleDateFormat("MM-dd",
				Locale.CHINESE);
		graphView.setCustomLabelFormatter(new CustomLabelFormatter() {
			@Override
			public String formatLabel(double value, boolean isValueX) {
				if (isValueX) {
					Date d = new Date((long) value);
					return dateFormat.format(d);
				}
				return null;
			}
		});

		layoutChart.addView(graphView);
	}
點擊源代碼

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章