4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iOSグラフ描画ライブラリ「Charts」を使って超シンプルな円グラフを書く

Last updated at Posted at 2017-11-15

Charts

Charts

超シンプルな円グラフの作り方

凡例も何もないシンプル円グラフを作りたい場合、意外と躓きます。
他のグラフについても似たような流れでシンプルなものが作れます。

let chart = PieChartView(frame: rect)
chart.highlightPerTapEnabled = false  // グラフがタップされたときのハイライトをOFF(任意)
chart.chartDescription?.enabled = false  // グラフの説明を非表示
chart.drawEntryLabelsEnabled = false  // グラフ上のデータラベルを非表示
chart.legend.enabled = false  // グラフの注釈を非表示
chart.rotationEnabled = false // グラフがぐるぐる動くのを無効化

// グラフに表示する適当なデータセットを定義
let dataSet = PieChartDataSet(values: [PieChartDataEntry(value: 10, label: "A"), PieChartDataEntry(value: 90, label: "B")], label: "Data")
dataSet.setColors(UIColor.green, UIColor.blue)

dataSet.drawValuesEnabled = false  // グラフ上のデータ値を非表示

chart.data = PieChartData(dataSet: dataSet)

結果

image.png

こんな感じのただの円グラフが作れます。

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?