Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to show x-axis labels only when value is a DataEntry in Line Chart? #1536

Closed
Lorenzo-R opened this issue Sep 22, 2016 · 3 comments
Closed

Comments

@Lorenzo-R
Copy link

I use the x value of data entries to represent time in a LineChart and a xAxis.valueFormatter to format the TimeInterval value into a date string. However I'd like the labels on the xAxis to show only the dates relative to a data entry (as it was before with xIndex), and hide all the ones that are currently shown in the space between two entry. I tried using xAxis.granularity, but it also prevents some "significant" dates (relative to an entry) to be shown.
I hope there's a way to solve this problem.

I am currently using the master of 19/09/2016, waiting for 3.0 release to come out!

Thanks a lot for the awesome library!

@Huang-Libo
Copy link

@Lorenzo-R Maybe you should modify the source code in AxisRendererBase.swift file, the interval's value is rounded in there:

// Find out how much spacing (in y value space) between axis values
let rawInterval = range / Double(labelCount)
interval = ChartUtils.roundToNextSignificant(number: Double(rawInterval))
let intervalMagnitude = ChartUtils.roundToNextSignificant(number: pow(10.0, Double(Int(log10(interval)))))
let intervalSigDigit = Int(interval / intervalMagnitude)
if intervalSigDigit > 5
{
    // Use one order of magnitude higher, to avoid intervals like 0.9 or 90
    interval = floor(10.0 * Double(intervalMagnitude))
}

@nickjwallin
Copy link

See my comment on a similar issue here: #1732 (comment)

The difference for you would be that in - (NSString *)stringForValue:(double)value axis:(ChartAxisBase *)axis, you would convert the value from double to NSInteger, for example, and then check if that NSInteger corresponds to a DataEntry you care about. (You'll have to keep track of your data entries I suppose).

For example:

- (NSString *)stringForValue:(double)value axis:(ChartAxisBase *)axis
{
    if (axis == _yAxis)
    {
        // create a string
    }
    else
    {
        NSInteger index = [NSNumber numberWithDouble:value].integerValue;
        // if (index is something you care about) (
        //   return a date string for it
        // }
    }
}

You'll have to play with the granularity to prevent overlap of values, maybe. This may be difficult to get working, but hopefully this helps you get started!

@liuxuan30
Copy link
Member

thanks @nickjwallin seems I can close it. Feel free to reopen if not resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants