TKChart
uses Categoric axes to plot data that contains categoric values. The axis is valid only in the context of Cartesian series. It also introduces several important properties:
majorTickInterval
- defines an interval among major axis ticks.
minorTickInterval
- defines an interval among minor axis ticks.
baseline
- contains a value, which defines how the series data should be aligned. For example, The TKChartBarSeries
might render its bars up and down depending on whether its value is greater or less than the baseline value.
offset
- determines an axis value where the axis is crossed with another axis.
You can configure a category axis by settings its categories property. You should use the following code snippet as a sample:
NSMutableArray *array = [[NSMutableArray alloc] init];
NSArray *categories = @[ @"Apple", @"Google", @"Microsoft", @"Samsung" ];
for (int i = 0; i<categories.count; i++) {
[array addObject:[[TKChartDataPoint alloc] initWithX:categories[i] Y:@(arc4random() % 100)]];
}
TKChartColumnSeries *series = [[TKChartColumnSeries alloc] initWithItems:array];
series.selection = TKChartSeriesSelectionSeries;
TKChartCategoryAxis *xAxis = [[TKChartCategoryAxis alloc] initWithCategories:categories];
xAxis.position = TKChartAxisPositionBottom;
xAxis.plotMode = TKChartAxisPlotModeBetweenTicks;
xAxis.range = [TKRange rangeWithMinimumIndex:0 andMaximumIndex:3];
_chart.xAxis = xAxis;
var array = [TKChartBubbleDataPoint]()
let categories = ["Apple", "Google", "Microsoft", "Samsung"]
for item in 0..<categories.count {
array.append(TKChartBubbleDataPoint(x: categories[item], y: Int(arc4random()%100), area: 0))
}
let series = TKChartColumnSeries(items:array)
series.selection = TKChartSeriesSelection.series
let xAxis = TKChartCategoryAxis(categories:categories)
xAxis.position = TKChartAxisPosition.bottom
xAxis.setPlotMode(TKChartAxisPlotMode.betweenTicks)
xAxis.range = TKRange(minimumIndex: 0, andMaximumIndex: 3)
chart.xAxis = xAxis
List<TKChartDataPoint> list = new List<TKChartDataPoint> ();
string[] categories = new []{"Apple", "Google", "Microsoft", "Samsung"};
for (int i = 0; i < categories.Length; i++) {
list.Add(new TKChartDataPoint(new NSString(categories[i]), new NSNumber(r.Next() % 100)));
}
TKChartColumnSeries series = new TKChartColumnSeries (list.ToArray());
series.Selection = TKChartSeriesSelection.Series;
TKChartCategoryAxis xAxis = new TKChartCategoryAxis ();
xAxis.Position = TKChartAxisPosition.Bottom;
xAxis.PlotMode = TKChartAxisPlotMode.BetweenTicks;
series.XAxis = xAxis;
You can specify the axis range by setting the minimum and maximum indexes of categories.
The TKChartAxisPlotMode
is used by the axis to plot the data. Possible values are TKChartAxisPlotModeBetweenTicks
and TKChartAxisPlotModeOnTicks
. TKChartAxisPlotModeBetweenTicks
plots points in the middle of the range, defined by two ticks. OnTicks
plots the points over each tick.
You should use the following lines of code to alter this behavior:
xAxis.plotMode = TKChartAxisPlotModeBetweenTicks;
xAxis.setPlotMode(TKChartAxisPlotMode.betweenTicks)
xAxis.PlotMode = TKChartAxisPlotMode.BetweenTicks;
xAxis.plotMode = TKChartAxisPlotModeOnTicks;
xAxis.setPlotMode(TKChartAxisPlotMode.onTicks)
xAxis.PlotMode = TKChartAxisPlotMode.OnTicks;