Skip to content

Commit ae0bbb0

Browse files
committed
Fix #239 => Add category call back message for pie chart
1 parent 6072817 commit ae0bbb0

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

charts/src/main/assets/AAChartView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function configureEventMessageBody(selectedPoint) {
5454
name: selectedPoint.series.name,
5555
x: selectedPoint.x,
5656
y: selectedPoint.y,
57-
category: selectedPoint.category,
57+
category: selectedPoint.category ? selectedPoint.category : selectedPoint.name,
5858
index: selectedPoint.index,
5959
offset: {
6060
plotX: selectedPoint.plotX,

sample/src/main/java/com/github/aachartmodel/aainfographics/demo/basiccontent/SpecialChartActivity.kt

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ import androidx.appcompat.app.AppCompatActivity
3333
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartModel
3434
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartType
3535
import com.github.aachartmodel.aainfographics.aachartcreator.AAChartView
36+
import com.github.aachartmodel.aainfographics.aachartcreator.AAClickEventMessageModel
37+
import com.github.aachartmodel.aainfographics.aachartcreator.AAMoveOverEventMessageModel
3638
import com.github.aachartmodel.aainfographics.demo.R
3739
import com.github.aachartmodel.aainfographics.demo.chartcomposer.SpecialChartComposer
40+
import com.google.gson.Gson
41+
import com.google.gson.GsonBuilder
3842

39-
class SpecialChartActivity : AppCompatActivity() {
43+
class SpecialChartActivity : AppCompatActivity(),
44+
AAChartView.AAChartViewCallBack {
4045

41-
private var aaChartModel: AAChartModel? = null
46+
// private var aaChartModel: AAChartModel? = null
4247

4348
override fun onCreate(savedInstanceState: Bundle?) {
4449
super.onCreate(savedInstanceState)
@@ -47,12 +52,16 @@ class SpecialChartActivity : AppCompatActivity() {
4752
val intent = intent
4853
val chartType = intent.getStringExtra("chartType")
4954

50-
aaChartModel = configureChartModelWithChartType(chartType!!)
55+
val aaChartModel = configureChartModelWithChartType(chartType!!)
56+
aaChartModel.clickEventEnabled(true)
57+
.touchEventEnabled(true)
58+
5159
val aaChartView: AAChartView = findViewById(R.id.AAChartView)
52-
aaChartView.aa_drawChartWithChartModel(aaChartModel!!)
60+
aaChartView.callBack = this
61+
aaChartView.aa_drawChartWithChartModel(aaChartModel)
5362
}
5463

55-
private fun configureChartModelWithChartType(chartType: String): AAChartModel? {
64+
private fun configureChartModelWithChartType(chartType: String): AAChartModel {
5665
when (chartType) {
5766
AAChartType.Column.value -> return SpecialChartComposer.configurePolarColumnChart()
5867
AAChartType.Bar.value -> return SpecialChartComposer.configurePolarBarChart()
@@ -76,6 +85,31 @@ class SpecialChartActivity : AppCompatActivity() {
7685
}
7786

7887
return SpecialChartComposer.configurePolarColumnChart()
88+
89+
}
90+
91+
override fun chartViewDidFinishLoad(aaChartView: AAChartView) {
92+
//do nothing
7993
}
8094

95+
override fun chartViewClickEventMessage(
96+
aaChartView: AAChartView,
97+
clickEventMessage: AAClickEventMessageModel
98+
) {
99+
val gson = GsonBuilder().setPrettyPrinting().create()
100+
val clickEventMessageModelJson = gson.toJson(clickEventMessage)
101+
102+
// 打印点击事件信息
103+
println("🖱🖱🖱获取点击事件 clickMessageModel = $clickEventMessageModelJson")
104+
}
105+
106+
107+
override fun chartViewMoveOverEventMessage(
108+
aaChartView: AAChartView,
109+
messageModel: AAMoveOverEventMessageModel
110+
) {
111+
//do nothing
112+
}
113+
114+
81115
}

0 commit comments

Comments
 (0)