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

setVisibleXRange doesn't work #2460

Closed
abcdefz opened this issue May 21, 2017 · 10 comments
Closed

setVisibleXRange doesn't work #2460

abcdefz opened this issue May 21, 2017 · 10 comments
Labels

Comments

@abcdefz
Copy link

abcdefz commented May 21, 2017

In my code, I wrote

        @IBOutlet weak var lineChart: LineChartView!
        ...
        ...
        let lineChartDataSet = LineChartDataSet(values: dataEntries, label: "Units Sold")
        let lineChartData = LineChartData(dataSet: lineChartDataSet)
        lineChart.data = lineChartData
        lineChart.setVisibleXRangeMaximum(20.0)

but I got
2

After I remove "lineChart.setVisibleXRangeMaximum(20.0)" and I got
1

So if I want to set visible x range and the func setVisibleXRange doesn't effect data, how can I do, could anyone help me?


And I try to do some same change in Charts-Demos. In file LineChartTimeViewController.m, line 155 I add "[_chartView setVisibleXRangeMaximum:20.0];" but it also doesn't work. Are there some errors in my code?

@liuxuan30
Copy link
Member

liuxuan30 commented May 24, 2017

It's working on my side
image
[_chartView setVisibleXRangeMaximum:5];

but time line chart do seems weird, should be related to the time conversion. Are you able to tackle this issue?

@abcdefz
Copy link
Author

abcdefz commented May 26, 2017

wow, I actually started to write ios a few days ago. the issue is probably dificult to me.

@liuxuan30 liuxuan30 added the bug label Jun 5, 2017
@JCMcLovin
Copy link
Contributor

JCMcLovin commented Apr 9, 2018

Has anything been done on this issue? I have a very similar problem. When I segue to the ChartViewContoller and the default selection has data, the chart renders normally:

1rm_normal

but if I segue to this view controller when the default selection doesn't have any data and then select an item that has data, it looks like this:

segue to this:
1rm_nodatamessage

then select an item that has data:
1rm_squished

Of course viewDidLoad is called when I segue to the view controller and as long as the default selection has data when I segue to it, I can select another item that has data or doesn't and the chart will continue to render properly. So the difference appears to be in viewDidLoad but I've tried everything I can think of but nothing fixes the problem. Here's my viewDidLoad:

 override func viewDidLoad() {
    super.viewDidLoad()
    
    view.backgroundColor = UIColor(hexString: "232B35")
    
    self.title = "1RM"
    
    chartView.delegate = self
    chartView.chartDescription?.enabled = false
    
    let leftAxis = chartView.leftAxis
    leftAxis.axisMinimum = 190
    leftAxis.labelTextColor = NSUIColor.white
    
    let xAxis = chartView.xAxis
    xAxis.labelPosition = .bottom
    xAxis.axisMinimum = 0
    xAxis.granularity = 1
    xAxis.axisLineWidth = 5
    xAxis.valueFormatter = self
    xAxis.labelTextColor = NSUIColor.white
    
    
    chartView.configureDefaults()
    chartView.rightAxis.enabled = false // this fixed the extra xAxis grid lines
    
    chartView.backgroundColor = NSUIColor(red: 35/255.0, green: 43/255.0, blue: 53/255.0, alpha: 1.0)
    
    fetchData()
    
    chartView.setVisibleXRangeMaximum(7)
    
    chartView.animate(yAxisDuration: 1.0)
}

I've tried putting chartView.setVisibleXRangeMaximum(7) in the method that sets the chart data but it doesn't make a difference.

Is there anything else I can try or is this a legitimate bug that hasn't been fixed yet?

Thanks

@JCMcLovin
Copy link
Contributor

I posted a question on Stack Overflow about this issue.

@liuxuan30
Copy link
Member

setVisibleXRangeMaximum is working, I labeld bug because other issue.
Please try ChartsDemo first as I tried.

@pateljinal1844
Copy link

I just found out, ordering matters for this to work. You need to call setVisibleXRangeMaximum after chartView.data = data or notifyDataSetChanged

@Deyan-Petkov
Copy link

Deyan-Petkov commented Mar 28, 2021

use zoom(float scaleX, float scaleY, float x, float y) method

myChart.zoom(3, 0, myChart.getX(), myChart.getY());
This will hide some of the content and let you swipe.

@Nikolai17
Copy link

I just found out, ordering matters for this to work. You need to call setVisibleXRangeMaximum after chartView.data = data or notifyDataSetChanged

thanks )

@humoroutlaw
Copy link

It's working on my side image [_chartView setVisibleXRangeMaximum:5];

but time line chart do seems weird, should be related to the time conversion. Are you able to tackle this issue?

time line chart no working

@liuxuan30
Copy link
Member

have to close this since too old

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

No branches or pull requests

7 participants