Search code examples
iosobjective-cshinobi

ShinobiCharts styling / order of data issues


I wanted to ask some chart styling and data questions. My chart currently looks like this: enter image description here

I would like to add a border around the chart with rounded edges, I have tried using the following code to no avail:

_chart.layer.cornerRadius = 10.0;

_chart.layer.borderWidth = 0.7;

_chart.layer.borderColor = [UIColorwhiteColor].CGColor;

I would also like to add labels to the bars to indicate their values, but have no idea how to do so.

My final question is regarding the data in the chart. Despite having a data structure in the correct order, the data appears scrambled in terms of order (it should read M T W TH F S SU). My data structure is:

_sales[0] = @{@"M" : @1.6, @"T" : @5.6, @"W" : @10.6, @"TH" : @12.6, @"F" : @15.6, @"S" : @3.6, @"Su" : @4.6};

and is used in the following way:

- (id<SChartData>)sChart:(ShinobiChart *)chart dataPointAtIndex:(NSInteger)dataIndex forSeriesAtIndex:(NSInteger)seriesIndex {

    SChartDataPoint *datapoint = [[SChartDataPointalloc] init];

    NSString* key = _sales[seriesIndex].allKeys[dataIndex];

    datapoint.xValue = key;

    datapoint.yValue = _sales[seriesIndex][key];

    return datapoint;

}

Any advice or input would be appreciate, thanks in advance!


Solution

  • Disclaimer: I work for ShinobiControls

    Chart Border

    Instead of using layer.borderWidth you can use borderThickness and instead of using layer.borderColor you can use borderColor.

    The following worked for me when I tested it:

    _chart.borderColor = [UIColor redColor];
    _chart.borderThickness = @(5);
    _chart.layer.cornerRadius = 10.0;
    

    Data Point Labels

    You can turn data point labels on and control their style via the series you are returning from your data source:

    series.style.dataPointLabelStyle.showLabels = YES;
    

    Data Order

    You mention that your data structure is "in the correct order", but unfortunately that isn't quite true. You are using an NSDictionary which does not guarantee order. When you call allKeys on your NSDictionary the array that is returned is not necessarily in order. As per the NSDictionary API documentation for allKeys:

    The order of the elements in the array is not defined.

    In order to fix this you'll need to switch to a data structure that does guarantee order.

    I hope all that info is useful!

    Note: There are a number of different questions in the original post, so this response contains several answers. I'm not really sure what the etiquette is for editing/splitting questions on SO is, so I've left it alone. If anyone comes across this question and has suggestions along those lines then feel free to make edits or add comments etc.