Question

I have a chart of name versus age, where name is on the x axis and value on Y axis. The problem is the names are getting overlapped on the x axis which do not look good.

I could not find any formatting for showing truncated name values on x axis and complete as we zoom in.

Is there any way to show names with ellipses or other formatting where the names will not overlap?

Was it helpful?

Solution

The alterTickMark: method on SChartDelegate allows you to modify a tickMark (and its corresponding tickLabel) before they are added to the axis.

You could potentially check the axisRange in this step, and decide if the range.span is small enough that you could display labels truncated or in full.

E.g.

-(void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis
{
    if (!axis.isXAxis)
        return;

    if ([axis.axisRange.span doubleValue] > 5)
    {
        NSString *shortText = [tickMark.tickLabel.text substringToIndex:3];
        tickMark.tickLabel.text = [NSString stringWithFormat:@"%@...", shortText];

        //Resize, but maintain centering
        CGPoint center = tickMark.tickLabel.center;
        [tickMark.tickLabel sizeToFit];
        tickMark.tickLabel.center = center;
    }
}

As full disclosure, I work for ShinobiControls.

OTHER TIPS

If you need to adjust tick label width in column series and zooming is enabled (which makes more space for label after zoom gesture), just implement SChart delegate method:

- (void)sChart:(ShinobiChart *)chart alterTickMark:(SChartTickMark *)tickMark beforeAddingToAxis:(SChartAxis *)axis
{
    if (axis.isXAxis) {
        // Adjusting tickmark labels
        UILabel *label = [tickMark tickLabel];

        CGFloat maxLabelWidth = axis.axisFrame.size.width / [axis.axisRange.span floatValue];
        CGRect labelFrame = label.frame;
        labelFrame.size.width = maxLabelWidth;

        [label setFrame:labelFrame];
    }
}

Look at the longestLabelStringOn delegate method. Example:

func sChart(_ chart: ShinobiChart, longestLabelStringOn axis: SChartAxis) -> String? {
        if axis == chart.xAxis{
            return "Longest Possible String"
        }
        else{
            return ""
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top