⑴ android中listview的itemclick的getLineChartView方法錯誤
你要先寫個適配器 ,定位點擊的item的position , 這樣才能捕捉到
item的點擊事件 , 不然即使實現了點擊事件 , item的位置也不會確定的 ,
甚至會亂掉 。
⑵ 如何在android畫分析圖(例如 柱狀圖、趨勢圖、餅圖)
目前android上圖標引擎並不少見,像aChartEngine就能很好的完成繪圖:
aChartEngine支持:1、linechart(折線圖)2、areachart(面積圖;分區圖,對比圖)3、scatterchart(散點圖)4、timechart(時間圖;進度表)5、barchart(條形圖;柱狀圖)6、piechart(餅圖)7、bubblechart(氣泡圖)8、doughnutchart(圓環圖)9、range(high-low)barchart(范圍條形圖)10、dialchart/gauge(撥號盤/壓力表)11、combined(anycombinationofline,cubicline,scatter,bar,rangebar,bubble)chart(組合圖)12、cubiclinechart(立方折線圖)
上述所有支持的圖表類型,都可以包含多個系列,都支持水平(默認)或垂直方式展示圖表,並且支持許多其他的自定義功能。所有圖表都可以建立為一個view,也可以建立為一個用於啟動activity的intent.
下面是一個餅狀圖的源碼事例:
package org.achartengine.chartdemo.demo.chart;
import org.achartengine.ChartFactory;
import org.achartengine.renderer.DefaultRenderer;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
public class BudgetPieChart extends AbstractDemoChart {
public String getName() {
return "Budget chart";
}
public String getDesc() {
return "The budget per project for this year (pie chart)";
}
public Intent execute(Context context) {
double[] values = new double[] { 12, 14, 11, 10, 19 };//餅圖分層5塊,每塊代表的數值
int[] colors = new int[] { Color.BLUE, Color.GREEN, Color.MAGENTA, Color.YELLOW, Color.CYAN };//每塊餅圖的顏色
DefaultRenderer renderer = buildCategoryRenderer(colors);
renderer.setZoomButtonsVisible(true);//設置顯示放大縮小按鈕
renderer.setZoomEnabled(true);//設置允許放大縮小.
renderer.setChartTitleTextSize(20);//設置圖表標題的文字大小
return ChartFactory.getPieChartIntent(context, buildCategoryDataset("Project budget", values),
renderer, "Budget");//構建Intent, buildCategoryDataset是調用AbstraDemoChart的構建方法.
}
}
⑶ 安卓怎麼在linechart 讓圖例斜著
如果series1是你的lineseries的id的話series1.y實際上是你的series1在lineChart中的y方向離chart頂部的距離(只是一個位置),而不是你理解的open屬性的值或y坐標,如果你沒有手動設置過這個值,那麼它的值應為0,也就是說你的else語句是永遠成立的。 我沒用過linechart設置其中部分線段的顏色(沒有什麼思路),但可以通過lineseries1的items數組中的各個對象或者定製lineseries1的itemrenderer來設置各個點的顏色
⑷ android用 MPAndroidChart空間生成曲線,怎麼更改初始放大倍數初始刻度值
1,將MPAndroidChart添加進Android Project
新建AndroidChartDemo
從GitHub下載所需的mpandroidchartlibrary-2-0-9.jar
將下載好的jar包添加進工程下的libs文件夾下,並滑鼠右鍵 Add as Libary
2,完成主界面布局
主界面布局是幾個比較簡單的button,代碼如下:
layout->activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_marginTop="50dp"
android:layout_marginBottom="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/btn_linechart"
android:text="@string/linechart"
android:textColor="#ffffff"
android:textSize="18sp"
android:background="#8CEBFF"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="@+id/btn_barchart"
android:text="@string/barchart"
android:textColor="#ffffff"
android:textSize="18sp"
android:background="#8CEBFF"
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<Button
android:id="@+id/btn_horizontalchart"
android:text="@string/horizontalchart"
android:textColor="#ffffff"
android:textSize="18sp"
android:background="#C5FF8C"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_combinedchart"
android:text="@string/combinedchart"
android:textColor="#ffffff"
android:textSize="18sp"
android:background="#FF6600"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_piechart"
android:text="@string/piechart"
android:textColor="#ffffff"
android:textSize="18sp"
android:background="#FF6600"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_scatterchart"
android:text="@string/scatterchart"
android:textColor="#ffffff"
android:textSize="18sp"
android:background="#FF6600"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_candlechart"
android:text="@string/candlechart"
android:textColor="#ffffff"
android:textSize="18sp"
android:background="#FF6600"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/btn_radarchart"
android:text="@string/radarchart"
android:textColor="#ffffff"
android:textSize="18sp"
android:background="#FF6600"
android:layout_marginTop="10dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
⑸ android中linechart折線圖和barchart柱狀圖能在一起嗎
橫縱軸縮放,多指縮放,展現動畫、高亮、保存到 sdcard、從文件讀取圖表
achartengine
強大的圖表繪制工具,支持折線圖、面積圖、散點圖、時間圖、柱狀圖、條圖、餅圖、氣泡圖、圓環圖、范圍(高至低)條形圖、撥號圖/表、立方線圖及各種圖的結合
GraphView
繪制圖表和曲線圖的View,可用於Android上的曲形圖、柱狀圖、波浪圖展示
HoloGraphLibrary
⑹ 如何在 Android 應用中使用 FontAwesome 圖標
FontAwesome 可以節省許多時間,原因如下:
首先,你不需要擔心不同手機上的屏幕解析度問題。如果你使用png圖片,你需要在包裡面對每個圖標至少包含四種不同的版本。不僅如此,在某些超清屏幕上,你的圖標可能會出現顆粒感。這顯然是要避免的。但如果使用FontAwesome,你只需包含一個"TTF」文件。
其次,你可以依賴於當今最豐富的免費圖標集之一。而且因為其在web上被廣泛的使用,現在用戶已經習慣了FontAwesome的風格。你不必再浪費時間去尋找漂亮的豐富的可以免費商用的圖標集合,我並不是說不存在這樣的圖標集,因為確實存在,但是非常稀少。
1. FontAwesome 的工作原理
我們先花點時間來了解一下FontAwesome 的工作原理。FontAwesome 圖標集背後的思想非常簡單,圖標被視為字元(character)。你可以能已經注意到一些奇怪的字元被作為文本對待,你可以輕易的拷貝 β 字元或者 ∑ 字元。你甚至可以在普通的文本編輯框中這樣做。還可以改變它們的大小和顏色。這是因為瀏覽器 - 以及文本編輯框 - 把這些字元視為文本。
FontAwesome 通過包含廣泛的圖標擴展了這一概念。你可以把它比喻成用圖標指定的不能打出的Unicode字元。
FontAwesome
看一眼 FontAwesome's cheatsheet 就知道我在說什麼了。你選擇列表中的一個圖標,記下它的Unicode的字元,在TextView中使用它告訴安卓使用FontAwesome字體來渲染。
2. 導入字體文件
讓我們來看一個例子。下載和導入FontAwesome 的TrueType 文件到項目。你可以從 GitHub上下載FontAwesome 的assets。
當你下載了FontAwesome之後,你會發現裡麵包含了一些文件和文件夾。大部分都是對web項目有用的。我們只對位於fonts目錄的 fontawesome-webfont.ttf感興趣。
在你的安卓項目中,導航到 app > src > main。 main 目錄應該包含了一個叫 assets的文件夾。如果沒有就創建一個。在assets 文件夾中創建另一個fonts文件夾,並把fontawesome-webfont.ttf 添加到這個文件夾。
主義 fonts 文件夾並不是必須的。你可以直接把FontAwesome 的字體文件放在 assets 目錄,但是把相同類型的文件放在專門的目錄裡面比較方便。只要FontAwesome 字體在assets 或者子目錄之下就行。
3. 創建一個幫助類
現在你已經成功的把FontAwesome 字體文件包含在了自己的安卓項目里,是時候使用它了。我們會創建一個幫助類來讓事情變得簡單點。這個類要使用到android.graphics.Typeface。Typeface類指定typeface 以及一個字體的特徵。它用於指明text在繪制(以及測量)的時候該如何顯示。
創建一個新的名叫FontManager的java類:
1
2
3
4
5
6
7
8
9
10
public class FontManager {
public static final String ROOT = "fonts/",
FONTAWESOME = ROOT + "fontawesome-webfont.ttf";
public static Typeface getTypeface(Context context, String font) {
return Typeface.createFromAsset(context.getAssets(), font);
}
}
如果你想在項目中使用其他的字體,把字體放在helper 類裡面就可以了。類似於:
1
yourTextView.setTypeface(FontManager.getTypeface(FontManager.YOURFONT));
我們需要做的就這么多,但是我們可以做的更好。使用上面的方法的話,我們需要為每個想當成圖標來使用的TextView創建一個變數。但作為一個程序員,我們都很懶,對吧?
圖標一般都是包含在一個ViewGroup,比如一個RelativeLayout或者LinearLayout中。我們可以寫一個方法,爬遍指定xml parent 並且遞歸的覆蓋每個TextView的字體。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class FontManager {
// ...
public static void markAsIconContainer(View v, Typeface typeface) {
if (v instanceof ViewGroup) {
ViewGroup vg = (ViewGroup) v;
for (int i = 0; i < vg.getChildCount(); i++) {
View child = vg.getChildAt(i);
markAsIconContainer(child);
}
} else if (v instanceof TextView) {
((TextView) v).setTypeface(typeface);
}
}
}
假設你的布局文件是這樣的:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/icons_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1" />
</LinearLayout>
要把這三個TextView標記為圖標,我們重寫onCreate方法,並添加如下代碼片段:
1
2
Typeface iconFont = FontManager.getTypeface(getApplicationContext(), FontManager.FONTAWESOME);
FontManager.markAsIconContainer(findViewById(R.id.icons_container), iconFont);
4. 使用你想要的圖標
現在輪到有意思的部分了。訪問 FontAwesome的GitHub頁面 並瀏覽所給的圖標。選擇三個你喜歡的。我准備選擇三個chart圖標,分別是 area chart icon, pie chart icon, 以及 line chart icon。
在你的項目中,進入 values 文件夾並創建一個新的文件:icons.xml。這個文件將被作為字典使用,它將把Unicode 字元和相應的圖標用可讀的名字匹配起來。這意味著我們需要為每個圖標創建一個入口。
1
2
3
4
5
<resources>
<string name="fa_icon_areachart"></string>
<string name="fa_icon_piechart"></string>
<string name="fa_icon_linechart"></string>
</resources>
你可以在FontAwesome cheatsheet或者圖標的 詳情頁面 找到你感興趣圖標的代碼。
下一步就是在布局的TextView裡面引用這些字元串。這是最終的樣子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/fa_icon_areachart" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/fa_icon_piechart" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:text="@string/fa_icon_linechart" />
如果你打開Android Studio的布局編輯器,你會看到它無法渲染這些圖標。這是不正常的。編譯並啟動應用,你又會發現圖標是正常渲染了的。
看起啦很小是吧?改變圖標的大小很簡單,你只需改變textSize屬性就是了。改變圖標的顏色也一樣簡單,編輯textColor屬性就是了。
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="1"
android:textSize="45sp"
android:textColor="#9b59b6"
android:text="@string/fa_icon_areachart" />
⑺ android studiodatachart怎麼用
1.先從git上面clone下來所需要的項目依賴,復制MPChartLib到我們的項目中(與app)同級。
2.打開settings.gradle 輸入
include 'MPChartLib'
打開app.build.gradle 輸入
compile project (':MPChartLib')
3.在布局文件中加入LineChart
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.wingsofts.mpchartdemo.MainActivity">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/lineChart"
android:layout_width="match_parent"
android:layout_height="match_parent">
</com.github.mikephil.charting.charts.LineChart>
</RelativeLayout>
4.在代碼中操作數據集。這里介紹一下涉及到的類
XAxis 為 X軸的類
Entry 為每個點的類