Skip to content

Commit f6677ee

Browse files
committed
Add double Y axes chart and triple Y axes chart samples
1 parent 7c992a6 commit f6677ee

File tree

8 files changed

+238
-21
lines changed

8 files changed

+238
-21
lines changed

AAInfographics/AAChartCreator/AAChartModel.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,18 @@ public enum AAChartType: String {
8989
case gauge
9090
}
9191

92-
public enum AAChartSubtitleAlignType: String {
92+
public enum AAChartLayoutType: String {
93+
case horizontal, vertical
94+
}
95+
96+
public enum AAChartAlignType: String {
9397
case left, center, right
9498
}
9599

100+
public enum AAChartVerticalAlignType: String {
101+
case top, middle, bottom
102+
}
103+
96104
public enum AAChartZoomType: String {
97105
case none, x, y, xy
98106
}

AAInfographics/AAChartCreator/AAChartView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ extension AAChartView {
343343

344344
/// Evaluate JavaScript string function body
345345
///
346-
/// - Parameter JSFunctionBodyString: JavaScript function body string
346+
/// - Parameter JSFunctionBodyString: valid JavaScript function body string
347347
public func aa_evaluateJavaScriptStringFunction(_ JSFunctionString: String) {
348348
if optionsJson != nil {
349349
let pureJSFunctionStr = AAJSStringPurer.pureJavaScriptFunctionString(JSFunctionString)

AAInfographics/AAChartCreator/AASeriesElement.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
public var threshold: Float? //The threshold, also called zero level or base level. For line type series this is only used in conjunction with negativeColor. default:0.
4545
public var negativeColor: String? //The color for the parts of the graph or points that are below the threshold
4646
public var dashStyle: String? //A name for the dash style to use for the graph. Applies only to series type having a graph, like line, spline, area and scatter in case it has a lineWidth.
47+
public var yAxis: Int?
4748
public var dataLabels: AADataLabels? //Individual data label for each point. The options are the same as the ones for `plotOptions.series.dataLabels`.
4849
public var marker: AAMarker? //Enable or disable the point marker. If null, the markers are hidden when the data is dense, and shown for more widespread data points.
4950
public var step: Any? //Whether to apply steps to the line. Possible values are left, center and right.
@@ -54,6 +55,7 @@
5455
public var shadow: Any?
5556
public var zones: [Any]?
5657
public var stack: String?
58+
public var tooltip: AATooltip?
5759

5860
@discardableResult
5961
public func type(_ prop: AAChartType) -> AASeriesElement {
@@ -127,6 +129,12 @@
127129
return self
128130
}
129131

132+
@discardableResult
133+
public func yAxis(_ prop: Int) -> AASeriesElement {
134+
yAxis = prop
135+
return self
136+
}
137+
130138
@discardableResult
131139
public func dataLabels(_ prop: AADataLabels) -> AASeriesElement {
132140
dataLabels = prop
@@ -186,6 +194,12 @@
186194
stack = prop
187195
return self
188196
}
197+
198+
@discardableResult
199+
public func tooltip(_ prop: AATooltip) -> AASeriesElement {
200+
tooltip = prop
201+
return self
202+
}
189203

190204
public override init() {
191205
}

AAInfographics/AAOptionsModel/AALegend.swift

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,6 @@
3232

3333
import UIKit
3434

35-
public enum AAChartLegendlLayoutType: String {
36-
case horizontal, vertical
37-
}
38-
39-
public enum AAChartLegendAlignType: String {
40-
case left, center, right
41-
}
42-
43-
public enum AAChartLegendVerticalAlignType: String {
44-
case top, middle, bottom
45-
}
46-
4735
public class AALegend: AAObject {
4836
public var layout: String? //图例数据项的布局。布局类型: "horizontal" 或 "vertical" 即水平布局和垂直布局 默认是:horizontal.
4937
public var align: String? //设定图例在图表区中的水平对齐方式,合法值有left,center 和 right。
@@ -62,19 +50,19 @@ public class AALegend: AAObject {
6250
public var y: Float?
6351

6452
@discardableResult
65-
public func layout(_ prop: AAChartLegendlLayoutType?) -> AALegend {
53+
public func layout(_ prop: AAChartLayoutType?) -> AALegend {
6654
layout = prop?.rawValue
6755
return self
6856
}
6957

7058
@discardableResult
71-
public func align(_ prop: AAChartLegendAlignType?) -> AALegend {
59+
public func align(_ prop: AAChartAlignType?) -> AALegend {
7260
align = prop?.rawValue
7361
return self
7462
}
7563

7664
@discardableResult
77-
public func verticalAlign(_ prop: AAChartLegendVerticalAlignType?) -> AALegend {
65+
public func verticalAlign(_ prop: AAChartVerticalAlignType?) -> AALegend {
7866
verticalAlign = prop?.rawValue
7967
return self
8068
}

AAInfographics/AAOptionsModel/AASubtitle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class AASubtitle: AAObject {
6060
}
6161

6262
@discardableResult
63-
public func verticalAlign(_ prop: AAChartLegendVerticalAlignType?) -> AASubtitle {
63+
public func verticalAlign(_ prop: AAChartVerticalAlignType?) -> AASubtitle {
6464
verticalAlign = prop?.rawValue
6565
return self
6666
}

AAInfographics/AAOptionsModel/AATitle.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ public class AATitle: AAObject {
5454
}
5555

5656
@discardableResult
57-
public func align(_ prop: AAChartLegendAlignType?) -> AATitle {
57+
public func align(_ prop: AAChartAlignType?) -> AATitle {
5858
align = prop?.rawValue
5959
return self
6060
}
6161

6262
@discardableResult
63-
public func verticalAlign(_ prop: AAChartLegendVerticalAlignType?) -> AATitle {
63+
public func verticalAlign(_ prop: AAChartVerticalAlignType?) -> AATitle {
6464
verticalAlign = prop?.rawValue
6565
return self
6666
}

AAInfographicsDemo/Demo/AdditionalContent/DrawChartWithAAOptionsVC.swift

Lines changed: 205 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class DrawChartWithAAOptionsVC: UIViewController {
6565
case 14: return configureXAxisLabelsFontColorAndFontSizeWithHTMLString()
6666
case 15: return configure_DataLabels_XAXis_YAxis_Legend_Style()
6767
case 16: return configureXAxisPlotBand()
68+
case 17: return configureDoubleYAxisChartOptions()
69+
case 18: return configureTripleYAxesMixedChart()
6870
default:
6971
return AAOptions()
7072
}
@@ -701,7 +703,7 @@ function () {
701703
.data([7.0, 6.9, 2.5, 14.5, 18.2, 21.5, 5.2, 26.5, 23.3, 45.3, 13.9, 9.6])
702704
,
703705
]
704-
);
706+
)
705707

706708
let aaOptions = AAOptionsConstructor.configureChartOptions(aaChartModel)
707709
aaOptions.xAxis?.labels?.useHTML(true)
@@ -873,6 +875,208 @@ function () {
873875

874876
return aaOptions
875877
}
878+
879+
private func configureDoubleYAxisChartOptions() -> AAOptions {
880+
let aaTitle = AATitle()
881+
.text("")
882+
883+
let aaXAxis = AAXAxis()
884+
.visible(true)
885+
.min(0)
886+
.categories([
887+
"Java", "Swift", "Python", "Ruby", "PHP", "Go","C",
888+
"C#", "C++", "Perl", "R", "MATLAB", "SQL"])
889+
890+
let aaYAxisTitleStyle = AAStyle()
891+
.color("#1e90ff")//Title font color
892+
.fontSize(14)//Title font size
893+
.fontWeight(.bold)//Title font weight
894+
.textOutline("0px 0px contrast")
895+
896+
let aaYAxisLabels = AALabels()
897+
.enabled(true)//设置 y 轴是否显示数字
898+
.format("{value:.,0f}mm")//让y轴的值完整显示 而不是100000显示为100k,同时单位后缀为°C
899+
.style(AAStyle()
900+
.color("#ff0000")//yAxis Label font color
901+
.fontSize(15)//yAxis Label font size
902+
.fontWeight(.bold)//yAxis Label font weight
903+
)
904+
905+
let yAxisOne = AAYAxis()
906+
.visible(true)
907+
.labels(aaYAxisLabels)
908+
.title(AATitle()
909+
.text("冬季降雨量")
910+
.style(aaYAxisTitleStyle))
911+
.opposite(true)
912+
913+
914+
let yAxisTwo = AAYAxis()
915+
.visible(true)
916+
.labels(aaYAxisLabels)
917+
.title(AATitle()
918+
.text("夏季降雨量")
919+
.style(aaYAxisTitleStyle))
920+
921+
let aaTooltip = AATooltip()
922+
.enabled(true)
923+
.shared(true)
924+
925+
let gradientColorDic1 = AAGradientColor.linearGradient(
926+
direction: .toTop,
927+
startColor: "#f54ea2",
928+
endColor: "#ff7676"//颜色字符串设置支持十六进制类型和 rgba 类型
929+
)
930+
931+
let gradientColorDic2 = AAGradientColor.linearGradient(
932+
direction: .toTop,
933+
startColor: "#17ead9",
934+
endColor: "#6078ea"//颜色字符串设置支持十六进制类型和 rgba 类型
935+
)
936+
937+
let aaMarker = AAMarker()
938+
.radius(7)//曲线连接点半径,默认是4
939+
.symbol(AAChartSymbolType.circle.rawValue)//曲线点类型:"circle", "square", "diamond", "triangle","triangle-down",默认是"circle"
940+
.fillColor("#ffffff")//点的填充色(用来设置折线连接点的填充色)
941+
.lineWidth(3)//外沿线的宽度(用来设置折线连接点的轮廓描边的宽度)
942+
.lineColor("")//外沿线的颜色(用来设置折线连接点的轮廓描边颜色,当值为空字符串时,默认取数据点或数据列的颜色)
943+
944+
let element1 = AASeriesElement()
945+
.name("2017")
946+
.type(.areaspline)
947+
// .borderRadius(4)
948+
.color(gradientColorDic1)
949+
.marker(aaMarker)
950+
.yAxis(1)
951+
.data([7.0, 6.9, 2.5, 14.5, 18.2, 21.5, 5.2, 26.5, 23.3, 45.3, 13.9, 9.6])
952+
953+
let element2 = AASeriesElement()
954+
.name("2018")
955+
.type(.column)
956+
.color(gradientColorDic2)
957+
.yAxis(0)
958+
.data([7.0, 6.9, 2.5, 14.5, 18.2, 21.5, 5.2, 26.5, 23.3, 45.3, 13.9, 9.6])
959+
960+
let aaOptions = AAOptions()
961+
.title(aaTitle)
962+
.xAxis(aaXAxis)
963+
.yAxisArray([yAxisOne,yAxisTwo])
964+
.tooltip(aaTooltip)
965+
.series([element1,element2])
966+
967+
return aaOptions
968+
}
969+
970+
private func configureTripleYAxesMixedChart() -> AAOptions {
971+
let colorsThemeArr = ["red","mediumspringgreen","deepskyblue",]
972+
973+
let aaTitle = AATitle()
974+
.text("东京月平均天气数据")
975+
976+
let aaSubtitle = AASubtitle()
977+
.text("数据来源: WorldClimate.com")
978+
979+
let aaXAxis = AAXAxis()
980+
.visible(true)
981+
.min(0)
982+
.categories(["一月", "二月", "三月", "四月", "五月", "六月",
983+
"七月", "八月", "九月", "十月", "十一月", "十二月"])
984+
985+
let yAxis1 = AAYAxis()
986+
.visible(true)
987+
.gridLineWidth(0)
988+
.labels(AALabels()
989+
.enabled(true)//设置 y 轴是否显示数字
990+
.format("{value}°C")
991+
.style(AAStyle()
992+
.color(colorsThemeArr[0])//yAxis Label font color
993+
))
994+
.title(AATitle()
995+
.text("温度")
996+
.style(AAStyle()
997+
.color(colorsThemeArr[0])))
998+
.opposite(true)
999+
1000+
1001+
let yAxis2 = AAYAxis()
1002+
.visible(true)
1003+
.gridLineWidth(0)
1004+
.labels(AALabels()
1005+
.enabled(true)//设置 y 轴是否显示数字
1006+
.format("{value}°mm")
1007+
.style(AAStyle()
1008+
.color(colorsThemeArr[1])//yAxis Label font color
1009+
))
1010+
.title(AATitle()
1011+
.text("降雨量")
1012+
.style(AAStyle()
1013+
.color(colorsThemeArr[1])))
1014+
1015+
let yAxis3 = AAYAxis()
1016+
.visible(true)
1017+
.gridLineWidth(0)
1018+
.labels(AALabels()
1019+
.enabled(true)//设置 y 轴是否显示数字
1020+
.format("{value}°mb")
1021+
.style(AAStyle()
1022+
.color(colorsThemeArr[2])//yAxis Label font color
1023+
))
1024+
.title(AATitle()
1025+
.text("海平面气压")
1026+
.style(AAStyle()
1027+
.color(colorsThemeArr[2])))
1028+
1029+
let aaTooltip = AATooltip()
1030+
.enabled(true)
1031+
.shared(true)
1032+
1033+
let aaLegend = AALegend()
1034+
.enabled(true)
1035+
.layout(.vertical)
1036+
.align(.center)
1037+
.x(80)
1038+
.verticalAlign(.top)
1039+
.y(55)
1040+
1041+
let element1 = AASeriesElement()
1042+
.name("降雨量")
1043+
.type(.column)
1044+
.yAxis(1)
1045+
.data([49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4])
1046+
.tooltip(AATooltip()
1047+
.valueSuffix(" mm"))
1048+
1049+
let element2 = AASeriesElement()
1050+
.name("海平面气压")
1051+
.type(.spline)
1052+
.yAxis(2)
1053+
.data([1016, 1016, 1015.9, 1015.5, 1012.3, 1009.5, 1009.6, 1010.2, 1013.1, 1016.9, 1018.2, 1016.7])
1054+
.dashStyle(.shortDot)
1055+
.tooltip(AATooltip()
1056+
.valueSuffix(" mb"))
1057+
1058+
let element3 = AASeriesElement()
1059+
.name("温度")
1060+
.type(.spline)
1061+
.yAxis(0)
1062+
.data([7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 13.9, 9.6])
1063+
.tooltip(AATooltip()
1064+
.valueSuffix(""))
1065+
1066+
let aaOptions = AAOptions()
1067+
.title(aaTitle)
1068+
.subtitle(aaSubtitle)
1069+
.colors(colorsThemeArr)
1070+
.xAxis(aaXAxis)
1071+
.yAxisArray([yAxis1,yAxis2,yAxis3])
1072+
.tooltip(aaTooltip)
1073+
.legend(aaLegend)
1074+
.series([element1,element2,element3])
1075+
1076+
return aaOptions
1077+
}
1078+
1079+
8761080
}
8771081

8781082

AAInfographicsDemo/Demo/MainVC.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ class MainVC: UIViewController {
175175
"configureXAxisLabelsFontColorAndFontSizeWithHTMLString",
176176
"configure_DataLabels_XAXis_YAxis_Legend_Style",
177177
"configureXAxisPlotBand",
178+
"configureDoubleYAxisChartOptions",
179+
"configureTripleYAxesMixedChart",
178180
],
181+
179182
[
180183
"简单字符串拼接",
181184
"自定义不同单位后缀",

0 commit comments

Comments
 (0)