Skip to content

Commit 4de6b71

Browse files
committed
Optimize content of gauge chart
1 parent 9da94df commit 4de6b71

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed

AAInfographics/AAChartCreator/AAOptionsConstructor.swift

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,25 +225,30 @@ public class AAOptionsConstructor {
225225
|| chartType == .areasplinerange
226226
|| chartType == .boxplot
227227
|| chartType == .waterfall
228-
|| chartType == .polygon ) {
229-
230-
let aaXAxisLabelsEnabled = aaChartModel.xAxisLabelsEnabled
231-
let aaXAxisLabels = AALabels()
232-
.enabled(aaXAxisLabelsEnabled) //设置 x 轴是否显示文字
233-
if aaXAxisLabelsEnabled == true {
234-
aaXAxisLabels.style(
235-
AAStyle()
236-
.color(aaChartModel.axesTextColor)
237-
)
238-
}
228+
|| chartType == .polygon
229+
|| chartType == .gauge) {
239230

240-
let aaXAxis = AAXAxis()
241-
.labels(aaXAxisLabels)
242-
.reversed(aaChartModel.xAxisReversed)
243-
.gridLineWidth(aaChartModel.xAxisGridLineWidth) //x轴网格线宽度
244-
.categories(aaChartModel.categories)
245-
.visible(aaChartModel.xAxisVisible) //x轴是否可见
246-
.tickInterval(aaChartModel.xAxisTickInterval) //x轴坐标点间隔数
231+
if chartType != .gauge {
232+
let aaXAxisLabelsEnabled = aaChartModel.xAxisLabelsEnabled
233+
let aaXAxisLabels = AALabels()
234+
.enabled(aaXAxisLabelsEnabled) //设置 x 轴是否显示文字
235+
if aaXAxisLabelsEnabled == true {
236+
aaXAxisLabels.style(
237+
AAStyle()
238+
.color(aaChartModel.axesTextColor)
239+
)
240+
}
241+
242+
let aaXAxis = AAXAxis()
243+
.labels(aaXAxisLabels)
244+
.reversed(aaChartModel.xAxisReversed)
245+
.gridLineWidth(aaChartModel.xAxisGridLineWidth) //x轴网格线宽度
246+
.categories(aaChartModel.categories)
247+
.visible(aaChartModel.xAxisVisible) //x轴是否可见
248+
.tickInterval(aaChartModel.xAxisTickInterval) //x轴坐标点间隔数
249+
250+
aaOptions.xAxis(aaXAxis)
251+
}
247252

248253
let aaYAxisLabelsEnabled = aaChartModel.yAxisLabelsEnabled
249254
let aaYAxisLabels = AALabels()
@@ -270,8 +275,7 @@ public class AAOptionsConstructor {
270275
.color(aaChartModel.axesTextColor)
271276
))
272277

273-
aaOptions.xAxis(aaXAxis)
274-
.yAxis(aaYAxis)
278+
aaOptions.yAxis(aaYAxis)
275279
}
276280
}
277281

AAInfographicsDemo/Demo/AdditionalContent/DrawChartWithAAOptionsVC.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ class DrawChartWithAAOptionsVC: UIViewController {
360360
.chartType(.gauge)
361361
.yAxisMin(0)
362362
.yAxisMax(100)
363+
.backgroundColor(["#555555"])
363364
.series([
364365
AASeriesElement()
365366
.data([80]
@@ -373,8 +374,11 @@ class DrawChartWithAAOptionsVC: UIViewController {
373374
.endAngle(150)
374375
)
375376

377+
aaOptions.tooltip?.crosshairs(false)
376378
let aaYAxis = aaOptions.yAxis as? AAYAxis
377-
aaYAxis?.plotBands([
379+
aaYAxis?
380+
.gridLineColor(AAColor.white)
381+
.plotBands([
378382
AAPlotBandsElement()
379383
.from(0)
380384
.to(60)
@@ -389,8 +393,9 @@ class DrawChartWithAAOptionsVC: UIViewController {
389393
private func setUpOptions2() -> AAOptions {
390394
let aaChartModel = AAChartModel()
391395
.chartType(.gauge)
396+
.backgroundColor(["#555555"])
392397
.yAxisMin(0)
393-
.yAxisMax(100)
398+
.yAxisMax(200)
394399
.yAxisTitle("km/h")
395400
.series([
396401
AASeriesElement()
@@ -405,21 +410,24 @@ class DrawChartWithAAOptionsVC: UIViewController {
405410
.startAngle(-150)
406411
.endAngle(150)
407412
)
408-
413+
414+
aaOptions.tooltip?.crosshairs(false)
409415
let aaYAxis = aaOptions.yAxis as? AAYAxis
410-
aaYAxis?.plotBands([
416+
aaYAxis?
417+
.gridLineColor(AAColor.white)
418+
.plotBands([
411419
AAPlotBandsElement()
412420
.from(0)
413421
.to(120)
414-
.color("#BC2B44"),
422+
.color("#1e90ff"),
415423
AAPlotBandsElement()
416424
.from(120)
417425
.to(160)
418-
.color("#EC6444"),
426+
.color("#ef476f"),
419427
AAPlotBandsElement()
420428
.from(160)
421429
.to(200)
422-
.color("#f19742"),
430+
.color("#ffd066"),
423431
])
424432

425433
return aaOptions

0 commit comments

Comments
 (0)