An An 2 жил өмнө
parent
commit
bd72970c02

+ 16 - 1
charts/src/main/java/com/github/aachartmodel/aainfographics/aaoptionsmodel/AAChart.kt

@@ -112,11 +112,26 @@ class AAChart {
         return this
     }
     
-    fun resetZoomButton(prop: AAResetZoomButton): AAChart? {
+    fun resetZoomButton(prop: AAResetZoomButton): AAChart {
         resetZoomButton = prop
         return this
     }
 
+    fun zoomType(zoomType: String?): AAChart {
+        this.zoomType = zoomType
+        return this
+    }
+
+    fun events(events: AAChartEvents?): AAChart {
+        this.events = events
+        return this
+    }
+
+    fun height(height: Number?): AAChart {
+        this.height = height
+        return this
+    }
+
 }
 
 

+ 12 - 9
sample/src/main/AndroidManifest.xml

@@ -1,16 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:tools="http://schemas.android.com/tools"
-    package="com.github.aachartmodel.aainfographics.demo">
+        xmlns:tools="http://schemas.android.com/tools"
+        package="com.github.aachartmodel.aainfographics.demo">
 
     <application
-        android:allowBackup="true"
-        android:icon="@mipmap/ic_launcher"
-        android:label="@string/app_name"
-        android:roundIcon="@mipmap/ic_launcher_round"
-        android:supportsRtl="true"
-        android:theme="@style/AppTheme"
-        tools:ignore="AllowBackup">
+            android:allowBackup="true"
+            android:icon="@mipmap/ic_launcher"
+            android:label="@string/app_name"
+            android:roundIcon="@mipmap/ic_launcher_round"
+            android:supportsRtl="true"
+            android:theme="@style/AppTheme"
+            tools:ignore="AllowBackup">
+        <activity
+                android:name=".JSFunctionForAAChartEventsActivity"
+                android:exported="false" />
         <activity android:name=".basiccontent.MainActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />

+ 12 - 0
sample/src/main/java/com/github/aachartmodel/aainfographics/demo/additionalcontent/JSFunctionForAAChartEventsActivity.kt

@@ -0,0 +1,12 @@
+package com.github.aachartmodel.aainfographics.demo.additionalcontent
+
+import androidx.appcompat.app.AppCompatActivity
+import android.os.Bundle
+import com.github.aachartmodel.aainfographics.demo.R
+
+class JSFunctionForAAChartEventsActivity : AppCompatActivity() {
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        setContentView(R.layout.activity_jsfunction_for_aachart_events)
+    }
+}

+ 83 - 0
sample/src/main/java/com/github/aachartmodel/aainfographics/demo/chartcomposer/JSFunctionForAAChartEventsComposer.kt

@@ -0,0 +1,83 @@
+package com.github.aachartmodel.aainfographics.demo.chartcomposer
+
+import com.github.aachartmodel.aainfographics.aachartcreator.*
+import com.github.aachartmodel.aainfographics.aaoptionsmodel.AAChartEvents
+import com.github.aachartmodel.aainfographics.aaoptionsmodel.AACrosshair
+import com.github.aachartmodel.aainfographics.aaoptionsmodel.AAStyle
+import com.github.aachartmodel.aainfographics.aatools.AAColor
+
+class JSFunctionForAAChartEventsComposer {
+    //https://github.com/AAChartModel/AAChartKit-Swift/issues/345
+    fun setCrosshairAndTooltipToTheDefaultPositionAfterLoadingChart(): AAOptions {
+        val aaChartModel: AAChartModel = AAChartModel()
+            .chartType(AAChartType.Areaspline) //图表类型
+            .colorsTheme(arrayOf("#04d69f", "#1e90ff", "#ef476f", "#ffd066"))
+            .stacking(AAChartStackingType.Normal)
+            .yAxisVisible(false)
+            .markerRadius(0)
+            .series(arrayOf(
+                AASeriesElement()
+                    .name("Tokyo Hot")
+                    .lineWidth(5.0)
+                    .fillOpacity(0.4f)
+                    .data(arrayOf(0.45, 0.43, 0.50, 0.55, 0.58, 0.62, 0.83, 0.39, 0.56, 0.67, 0.50, 0.34, 0.50, 0.67, 0.58, 0.29, 0.46, 0.23, 0.47, 0.46, 0.38, 0.56, 0.48, 0.36)),
+                AASeriesElement()
+                    .name("Berlin Hot")
+                    .lineWidth(5.0)
+                    .fillOpacity(0.4f)
+                    .data(arrayOf(0.38, 0.31, 0.32, 0.32, 0.64, 0.66, 0.86, 0.47, 0.52, 0.75, 0.52, 0.56, 0.54, 0.60, 0.46, 0.63, 0.54, 0.51, 0.58, 0.64, 0.60, 0.45, 0.36, 0.67)),
+                AASeriesElement()
+                    .name("New York Hot")
+                    .lineWidth(5.0)
+                    .fillOpacity(0.4f)
+                    .data(arrayOf(0.46, 0.32, 0.53, 0.58, 0.86, 0.68, 0.85, 0.73, 0.69, 0.71, 0.91, 0.74, 0.60, 0.50, 0.39, 0.67, 0.55, 0.49, 0.65, 0.45, 0.64, 0.47, 0.63, 0.64)),
+                AASeriesElement()
+                    .name("London Hot")
+                    .lineWidth(5.0)
+                    .fillOpacity(0.4f)
+                    .data(arrayOf(0.60, 0.51, 0.52, 0.53, 0.64, 0.84, 0.65, 0.68, 0.63, 0.47, 0.72, 0.60, 0.65, 0.74, 0.66, 0.65, 0.71, 0.59, 0.65, 0.77, 0.52, 0.53, 0.58, 0.53))
+            ))
+
+        val aaOptions: AAOptions = aaChartModel.aa_toAAOptions()
+
+        aaOptions.tooltip?.apply {
+            style(AAStyle.style(AAColor.White))
+           .backgroundColor("#050505")
+           .borderColor("#050505")
+        }
+
+        aaOptions.xAxis?.apply {
+            crosshair(AACrosshair()
+                .color(AAColor.DarkGray)
+                .dashStyle(AAChartLineDashStyleType.LongDashDotDot)
+                .width(2))
+        }
+
+        //默认选中的位置索引
+        val defaultSelectedIndex = 5
+
+        //https://api.highcharts.com/highcharts/chart.events.load
+        //https://www.highcharts.com/forum/viewtopic.php?t=36508
+        aaOptions.chart?.apply {
+            events(AAChartEvents()
+                    .load(String.format(
+                            """
+            function() {
+                let points = [];
+                let chart = this;
+                let series = chart.series;
+                let length = series.length;
+                           
+                for (let i = 0; i < length; i++) {
+                    let pointElement = series[i].data[%s];
+                    points.push(pointElement);
+                }
+                chart.xAxis[0].drawCrosshair(null, points[0]);
+                chart.tooltip.refresh(points);
+                       }""", defaultSelectedIndex
+                        )))
+        }
+        return aaOptions
+    }
+}
+

+ 9 - 0
sample/src/main/res/layout/activity_jsfunction_for_aachart_events.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:tools="http://schemas.android.com/tools"
+        xmlns:app="http://schemas.android.com/apk/res-auto"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        tools:context=".additionalcontent.JSFunctionForAAChartEventsActivity">
+
+</androidx.constraintlayout.widget.ConstraintLayout>