iOS & macOS charts - Examples
Please note! These examples are new to SciChart iOS v4 release! SciChart’s OpenGL ES and Metal iOS and Metal macOS Chart library ships with hundred of Objective-C and Swift iOS & macOS Chart Examples which you can browse, play with and view the source-code. All of this is possible with the new and improved SciChart iOS Examples Suite and demo application for Mac, which ships as part of the SciChart SDK.
The Change Column Color Chart View example demonstrates how to dynamically change the color of columns in a chart based on user interaction or specific conditions. With a custom `SeriesInfoProvider`, you can define the logic for how each series in the chart should behave, including how its columns are colored based on specific data conditions, user actions, or external parameters. The paletteProvider allows you to customize the color palette used for the columns in the chart.
The Swift and Objective-C source code for the iOS and macOS Change Column Color example is included below (Scroll down!).
Did you know that we have the source code for all our example available for free on Github?
Clone the SciChart.iOS.Examples from Github.
Also the SciChart iOS and Scichart macOS Trials contain the full source for the examples (link below).
ChangeColumnColorChartView.swift
View source code//******************************************************************************
// SCICHART® Copyright SciChart Ltd. 2011-2023. All rights reserved.
//
// Web: http://www.scichart.com
// Support: support@scichart.com
// Sales: sales@scichart.com
//
// ChangeColumnColorChartView.swift is part of the SCICHART® Examples. Permission is hereby granted
// to modify, create derivative works, distribute and publish any part of this source
// code whether for commercial, private or personal use.
//
// The SCICHART® examples are distributed in the hope that they will be useful, but
// without any warranty. It is provided "AS IS" without warranty of any kind, either
// expressed or implied.
//******************************************************************************
//MARK: - Color Palette Provider
class ColumnsPaletteProvider : SCIPaletteProviderBase<SCIFastColumnRenderableSeries>, ISCIFillPaletteProvider {
let colors = SCIUnsignedIntegerValues()
let desiredColors:[UInt32] = [0xFF21a0d8, 0xFFc43360]
var touchedIndex: Int = -1
init() {
super.init(renderableSeriesType: SCIFastColumnRenderableSeries.self)
}
override func update() {
let count = renderableSeries!.currentRenderPassData.pointsCount
colors.count = count
for i in 0 ..< count {
if i == touchedIndex {
colors.set(desiredColors[1], at: i)
}
else {
colors.set(desiredColors[0], at: i)
}
}
}
var fillColors: SCIUnsignedIntegerValues { return colors }
}
//MARK: - Chart Initialisation
class ChangeColumnColorChartView: SCDSingleChartViewController<SCIChartSurface> {
override var associatedType: AnyClass { return SCIChartSurface.self }
private let hitTestInfo = SCIHitTestInfo()
override func initExample() {
let xAxis = SCINumericAxis()
xAxis.growBy = SCIDoubleRange(min: 0.1, max: 0.1)
let yAxis = SCINumericAxis()
yAxis.axisAlignment = .left
yAxis.growBy = SCIDoubleRange(min: 0, max: 0.1)
let dataSeries = SCIXyDataSeries(xType: .double, yType: .double)
let yValues = [50, 35, 61, 58, 50, 50, 40, 53, 55, 23, 45, 12, 59, 60];
for i in 0 ..< yValues.count {
dataSeries.append(x: i, y: yValues[i])
}
let rSeries = SCIFastColumnRenderableSeries()
rSeries.dataSeries = dataSeries
rSeries.dataPointWidth = 0.7
rSeries.paletteProvider = ColumnsPaletteProvider()
let customSeriesInfoProvider = CustomSeriesInfoProvider()
customSeriesInfoProvider.delegate = self
rSeries.seriesInfoProvider = customSeriesInfoProvider
SCIUpdateSuspender.usingWith(surface) {
self.surface.xAxes.add(xAxis)
self.surface.yAxes.add(yAxis)
self.surface.renderableSeries.add(rSeries)
self.surface.chartModifiers.add(items: SCITooltipModifier())
}
}
}
extension ChangeColumnColorChartView: CustomSeriesInfoProviderDelegate {
func getTouchDataSeriesIndex(dataSeriesIndex: Int) {
let seriesCollection = surface.renderableSeries
let rSeries = seriesCollection.firstObject
if let paletteProvider = rSeries.paletteProvider as? ColumnsPaletteProvider {
paletteProvider.touchedIndex = dataSeriesIndex
}
surface.invalidateElement()
}
}
Back to iOS & macOS charts Examples


