Эх сурвалжийг харах

Add a new sample of double charts linked working

An An 5 жил өмнө
parent
commit
079cc34871

+ 1 - 1
app/build.gradle

@@ -24,7 +24,7 @@ android {
 
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
-    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
+    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
     implementation 'com.android.support:appcompat-v7:28.0.0'
     implementation 'com.android.support.constraint:constraint-layout:1.1.3'
     implementation 'com.google.code.gson:gson:2.8.5'

+ 4 - 9
app/src/main/AndroidManifest.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
-          package="com.aachartmodel.aainfographics">
+        package="com.aachartmodel.aainfographics">
 
     <application
             android:allowBackup="true"
@@ -11,9 +11,9 @@
             android:theme="@style/AppTheme">
         <activity android:name=".MainActivity">
             <intent-filter>
-                <action android:name="android.intent.action.MAIN"/>
+                <action android:name="android.intent.action.MAIN" />
 
-                <category android:name="android.intent.category.LAUNCHER"/>
+                <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
         <activity android:name=".ChartsDemo.BasicContent.SpecialChartActivity" />
@@ -25,12 +25,7 @@
         <activity android:name=".ChartsDemo.AdditionalContent.EvaluateJSStringFunctionActivity" />
         <activity android:name=".ChartsDemo.AdditionalContent.HideOrShowChartSeriesActivity" />
         <activity android:name=".ChartsDemo.AdditionalContent.OnlyRefreshChartDataActivity" />
-
-
-
-
-
-
+        <activity android:name=".ChartsDemo.AdditionalContent.DoubleChartsLinkedWorkActivity"/>
     </application>
 
 </manifest>

+ 3 - 2
app/src/main/java/com/aachartmodel/aainfographics/AAInfographicsLib/AAChartConfiger/AAChartView.kt

@@ -50,7 +50,7 @@ class AAMoveOverEventMessageModel {
     var y: Double? = null
     var category: String? = null
     var offset: LinkedTreeMap<*, *>? = null
-    var index: Double? = null
+    var index: Int? = null
 }
 
 
@@ -339,7 +339,8 @@ class AAChartView : WebView {
         eventMessageModel.y = messageBody["y"] as Double?
         eventMessageModel.category = messageBody["category"].toString()
         eventMessageModel.offset = messageBody["offset"] as LinkedTreeMap<*, *>?
-        eventMessageModel.index = messageBody["index"] as Double?
+        val index = messageBody["index"] as Double?
+        eventMessageModel.index = index?.toInt()
         return eventMessageModel
     }
 

+ 174 - 0
app/src/main/java/com/aachartmodel/aainfographics/ChartsDemo/AdditionalContent/DoubleChartsLinkedWorkActivity.kt

@@ -0,0 +1,174 @@
+package com.aachartmodel.aainfographics.ChartsDemo.AdditionalContent
+
+import android.os.Bundle
+import android.os.Handler
+import android.os.Looper
+import android.support.v7.app.AppCompatActivity
+import com.aachartmodel.aainfographics.AAInfographicsLib.AAChartConfiger.*
+import com.aachartmodel.aainfographics.AAInfographicsLib.AAOptionsModel.AAOptions
+import com.aachartmodel.aainfographics.R
+
+
+class DoubleChartsLinkedWorkActivity : AppCompatActivity(),
+    AAChartView.AAChartViewCallBack {
+    private var selectedGradientColor: Any = AAColor.redColor()
+    private var aaChartView1: AAChartView? = null
+    private var aaChartView2: AAChartView? = null
+    private var gradientColorsArr: Array<Any>? = null
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+        setContentView(R.layout.activity_double_charts_linked_work)
+        aaChartView1 = findViewById(R.id.AAChartView1)
+        aaChartView1?.callBack = this
+        aaChartView2 = findViewById(R.id.AAChartView2)
+        aaChartView1?.aa_drawChartWithChartOptions(configureChartOptions1())
+        aaChartView2?.aa_drawChartWithChartOptions(configureChartOptions2())
+    }
+
+    private fun configureChartOptions1(): AAOptions {
+        val gradientColorNamesArr = arrayOf(
+            "oceanBlue",
+            "sanguine",
+            "lusciousLime",
+            "purpleLake",
+            "freshPapaya",
+            "ultramarine",
+            "pinkSugar",
+            "lemonDrizzle",
+            "victoriaPurple",
+            "springGreens",
+            "mysticMauve",
+            "reflexSilver",
+            "neonGlowColor",
+            "berrySmoothieColor",
+            "newLeaf",
+            "cottonCandy",
+            "pixieDust",
+            "fizzyPeach",
+            "sweetDream",
+            "firebrick",
+            "wroughtIron",
+            "deepSea",
+            "coastalBreeze",
+            "eveningDelight",
+            "neonGlowColor",
+            "berrySmoothieColor"
+        )
+        val gradientColorArr =
+            arrayOf<Map<*, *>>(
+                AAGradientColor.oceanBlueColor(),
+                AAGradientColor.sanguineColor(),
+                AAGradientColor.lusciousLimeColor(),
+                AAGradientColor.purpleLakeColor(),
+                AAGradientColor.freshPapayaColor(),
+                AAGradientColor.ultramarineColor(),
+                AAGradientColor.pinkSugarColor(),
+                AAGradientColor.lemonDrizzleColor(),
+                AAGradientColor.victoriaPurpleColor(),
+                AAGradientColor.springGreensColor(),
+                AAGradientColor.mysticMauveColor(),
+                AAGradientColor.reflexSilverColor(),
+                AAGradientColor.neonGlowColor(),
+                AAGradientColor.berrySmoothieColor(),
+                AAGradientColor.newLeafColor(),
+                AAGradientColor.cottonCandyColor(),
+                AAGradientColor.pixieDustColor(),
+                AAGradientColor.fizzyPeachColor(),
+                AAGradientColor.sweetDreamColor(),
+                AAGradientColor.firebrickColor(),
+                AAGradientColor.wroughtIronColor(),
+                AAGradientColor.deepSeaColor(),
+                AAGradientColor.coastalBreezeColor(),
+                AAGradientColor.eveningDelightColor(),
+                AAGradientColor.neonGlowColor(),
+                AAGradientColor.berrySmoothieColor()
+            )
+        gradientColorsArr = gradientColorArr as Array<Any>
+        val aaChartModel: AAChartModel = AAChartModel()
+            .chartType(AAChartType.Column)
+            .title("")
+            .yAxisTitle("")
+            .categories(gradientColorNamesArr)
+            .colorsTheme(gradientColorArr as Array<Any> )
+            .xAxisReversed(true)
+            .yAxisReversed(true)
+            .inverted(true)
+            .legendEnabled(false)
+            .touchEventEnabled(true)
+            .series(arrayOf(
+                    AASeriesElement()
+                        .name("Tokyo")
+                        .data(arrayOf(
+                                211, 183, 157, 133, 111, 91, 73, 57, 43, 31, 21, 13,
+                                211, 183, 157, 133, 111, 91, 73, 57, 43, 31, 21, 13
+                            )
+                        )
+                        .colorByPoint(true)
+                )
+            )
+        val aaOptions: AAOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
+        aaOptions.plotOptions?.column?.groupPadding = 0f
+        return aaOptions
+    }
+
+    private fun configureChartOptions2(): AAOptions {
+        val aaChartModel: AAChartModel = AAChartModel()
+            .chartType(AAChartType.Column)
+            .title("")
+            .yAxisTitle("")
+            .legendEnabled(false)
+            .yAxisGridLineWidth(0f)
+            .series(arrayOf(
+                    AASeriesElement()
+                        .name("Tokyo")
+                        .data(arrayOf(
+                            149.9, 171.5, 106.4, 129.2, 144.0, 176.0, 135.6, 188.5, 276.4, 214.1, 95.6, 54.4,
+                            149.9, 171.5, 106.4, 129.2, 144.0, 176.0, 135.6, 188.5, 276.4, 214.1, 95.6, 54.4
+                            )
+                        )
+                )
+            )
+        val aaOptions: AAOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
+        aaOptions.plotOptions?.column?.groupPadding = 0f
+        return aaOptions
+    }
+
+    private fun configureSeriesDataArray(): Array<AADataElement> {
+        val maxRange = 40
+        val numberArr1: Array<AADataElement?> = arrayOfNulls(maxRange)
+        var y1: Double
+        val max = 38
+        val min = 1
+        val random = (Math.random() * (max - min) + min).toInt()
+        for (i in 0 until maxRange) {
+            y1 = Math.sin(random * (i * Math.PI / 180)) + i * 2 * 0.01
+            val aaDataElement: AADataElement = AADataElement()
+                .color(selectedGradientColor)
+                .y(y1.toFloat())
+            numberArr1[i] = aaDataElement
+        }
+        return numberArr1 as Array<AADataElement>
+    }
+
+    override fun chartViewDidFinishLoad(aaChartView: AAChartView) {
+
+    }
+
+    override fun chartViewMoveOverEventMessage(
+        aaChartView: AAChartView,
+        messageModel: AAMoveOverEventMessageModel
+    ) {
+        selectedGradientColor = gradientColorsArr?.get(messageModel.index!!)!!
+
+        val mainHandler = Handler(Looper.getMainLooper())
+        mainHandler.post {
+            //已在主线程中,可以更新UI
+            val aaSeriesElementsArr: Array<AASeriesElement> = arrayOf<AASeriesElement>(
+                AASeriesElement()
+                    .data(configureSeriesDataArray() as Array<Any>)
+            )
+            aaChartView2?.aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray(
+                aaSeriesElementsArr
+            )
+        }    }
+}

+ 20 - 3
app/src/main/java/com/aachartmodel/aainfographics/ChartsDemo/BasicContent/MainActivity.kt

@@ -133,7 +133,13 @@ class MainActivity : AppCompatActivity() {
         "自定义Y轴文字2",
         "自定义分组堆积柱状图tooltip内容",
         "双 X 轴镜像图表",
-        "customArearangeChartTooltip"
+        "customArearangeChartTooltip",
+        /*执行由 JavaScript 字符串映射转换成的 js function 函数*/
+        "evalJSFunction1",
+        "evalJSFunction2",
+        "evalJSFunction3",
+        /*Double Charts Linked Work---双表联动*/
+        "doubleChartsLinkedWork----------------------------"
 
         )
 
@@ -231,7 +237,9 @@ class MainActivity : AppCompatActivity() {
         /*执行由 JavaScript 字符串映射转换成的 js function 函数*/
         "evalJSFunction1",
         "evalJSFunction2",
-        "evalJSFunction3"
+        "evalJSFunction3",
+        /*Double Charts Linked Work---双表联动*/
+        "doubleChartsLinkedWork"
     )
 
     override fun onCreate(savedInstanceState: Bundle?) {
@@ -262,8 +270,10 @@ class MainActivity : AppCompatActivity() {
                     goToOnlyRefreshChartDataActivity(position)
                 } else if (position <= 83) { /*formatter js function*/
                     goToCustomTooltipWithJSFunctionActivity(position)
-                } else { /*eval JS Function*/
+                } else if (position <= 85) { /*eval JS Function*/
                     goToEvaluateJSStringFunctionActivity(position)
+                } else { /*Double Charts Linked Work*/
+                    goToDoubleChartsLinkedWorkActivity(position)
                 }
             }
     }
@@ -332,6 +342,13 @@ class MainActivity : AppCompatActivity() {
         startActivity(intent)
     }
 
+    fun goToDoubleChartsLinkedWorkActivity(position: Int) {
+        val intent = Intent(this, DoubleChartsLinkedWorkActivity::class.java
+        )
+        intent.putExtra("chartType", chartTypeArr[position])
+        startActivity(intent)
+    }
+
 
 }
 

+ 41 - 0
app/src/main/res/layout/activity_double_charts_linked_work.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:app="http://schemas.android.com/apk/res-auto"
+        xmlns:tools="http://schemas.android.com/tools"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        tools:context=".ChartsDemo.AdditionalContent.DoubleChartsLinkedWorkActivity">
+
+    <LinearLayout
+            android:id="@+id/linearLayout"
+            android:layout_width="0dp"
+            android:layout_height="0dp"
+            android:layout_marginStart="1dp"
+            android:layout_marginLeft="1dp"
+            android:layout_marginTop="1dp"
+            android:layout_marginEnd="1dp"
+            android:layout_marginRight="1dp"
+            android:layout_marginBottom="1dp"
+            android:orientation="vertical"
+            app:layout_constraintBottom_toBottomOf="parent"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent">
+
+
+        <com.aachartmodel.aainfographics.AAInfographicsLib.AAChartConfiger.AAChartView
+                android:id="@+id/AAChartView1"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_weight="1"
+                />
+
+        <com.aachartmodel.aainfographics.AAInfographicsLib.AAChartConfiger.AAChartView
+                android:id="@+id/AAChartView2"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_weight="1"
+                />
+
+    </LinearLayout>
+</android.support.constraint.ConstraintLayout>

+ 12 - 3
app/src/main/res/layout/activity_evaluate_jsstring_function.xml

@@ -1,10 +1,19 @@
 <?xml version="1.0" encoding="utf-8"?>
-<android.support.constraint.ConstraintLayout
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        xmlns:tools="http://schemas.android.com/tools"
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto"
+        xmlns:tools="http://schemas.android.com/tools"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         tools:context=".ChartsDemo.AdditionalContent.EvaluateJSStringFunctionActivity">
 
+    <TextView
+            android:id="@+id/textView7"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="137dp"
+            android:layout_marginLeft="137dp"
+            android:layout_marginTop="200dp"
+            android:text="TextView"
+            app:layout_constraintStart_toStartOf="parent"
+            app:layout_constraintTop_toTopOf="parent" />
 </android.support.constraint.ConstraintLayout>