Browse Source

Fix #239 => Add `category` call back message for pie chart

An An 2 months ago
parent
commit
ae0bbb0ce4

+ 1 - 1
charts/src/main/assets/AAChartView.js

@@ -54,7 +54,7 @@ function configureEventMessageBody(selectedPoint) {
         name: selectedPoint.series.name,
         x: selectedPoint.x,
         y: selectedPoint.y,
-        category: selectedPoint.category,
+        category: selectedPoint.category ? selectedPoint.category : selectedPoint.name,
         index: selectedPoint.index,
         offset: {
             plotX: selectedPoint.plotX,

+ 39 - 5
sample/src/main/java/com/github/aachartmodel/aainfographics/demo/basiccontent/SpecialChartActivity.kt

@@ -33,12 +33,17 @@ import androidx.appcompat.app.AppCompatActivity
 import com.github.aachartmodel.aainfographics.aachartcreator.AAChartModel
 import com.github.aachartmodel.aainfographics.aachartcreator.AAChartType
 import com.github.aachartmodel.aainfographics.aachartcreator.AAChartView
+import com.github.aachartmodel.aainfographics.aachartcreator.AAClickEventMessageModel
+import com.github.aachartmodel.aainfographics.aachartcreator.AAMoveOverEventMessageModel
 import com.github.aachartmodel.aainfographics.demo.R
 import com.github.aachartmodel.aainfographics.demo.chartcomposer.SpecialChartComposer
+import com.google.gson.Gson
+import com.google.gson.GsonBuilder
 
-class SpecialChartActivity : AppCompatActivity() {
+class SpecialChartActivity : AppCompatActivity(),
+    AAChartView.AAChartViewCallBack {
 
-    private var aaChartModel: AAChartModel? = null
+//    private var aaChartModel: AAChartModel? = null
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -47,12 +52,16 @@ class SpecialChartActivity : AppCompatActivity() {
         val intent = intent
         val chartType = intent.getStringExtra("chartType")
 
-        aaChartModel = configureChartModelWithChartType(chartType!!)
+        val aaChartModel = configureChartModelWithChartType(chartType!!)
+        aaChartModel.clickEventEnabled(true)
+            .touchEventEnabled(true)
+
         val aaChartView: AAChartView = findViewById(R.id.AAChartView)
-        aaChartView.aa_drawChartWithChartModel(aaChartModel!!)
+        aaChartView.callBack = this
+        aaChartView.aa_drawChartWithChartModel(aaChartModel)
     }
 
-    private fun configureChartModelWithChartType(chartType: String): AAChartModel? {
+    private fun configureChartModelWithChartType(chartType: String): AAChartModel {
         when (chartType) {
             AAChartType.Column.value -> return SpecialChartComposer.configurePolarColumnChart()
             AAChartType.Bar.value -> return SpecialChartComposer.configurePolarBarChart()
@@ -76,6 +85,31 @@ class SpecialChartActivity : AppCompatActivity() {
         }
 
         return SpecialChartComposer.configurePolarColumnChart()
+
+    }
+
+    override fun chartViewDidFinishLoad(aaChartView: AAChartView) {
+        //do nothing
     }
 
+    override fun chartViewClickEventMessage(
+        aaChartView: AAChartView,
+        clickEventMessage: AAClickEventMessageModel
+    ) {
+        val gson = GsonBuilder().setPrettyPrinting().create()
+        val clickEventMessageModelJson = gson.toJson(clickEventMessage)
+
+        // 打印点击事件信息
+        println("🖱🖱🖱获取点击事件 clickMessageModel = $clickEventMessageModelJson")
+    }
+
+
+    override fun chartViewMoveOverEventMessage(
+        aaChartView: AAChartView,
+        messageModel: AAMoveOverEventMessageModel
+    ) {
+        //do nothing
+    }
+
+
 }