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 do I set the value of the x-axis after update ? #1496

Closed
monkeyRing opened this issue Sep 20, 2016 · 19 comments
Closed

How do I set the value of the x-axis after update ? #1496

monkeyRing opened this issue Sep 20, 2016 · 19 comments

Comments

@monkeyRing
Copy link

the screenshot

2016-09-20 6 11 28

@monkeyRing
Copy link
Author

xcode 8 Chart2.2.5-Swift3.0

@liuxuan30
Copy link
Member

liuxuan30 commented Sep 21, 2016

well you should use Chart 3.0. Chart 2.2.5 will EOL soon. Also, just refresh your chart data x values. The code seems fine. Just don't forget to check your entries

@monkeyRing
Copy link
Author

@liuxuan30 ok ,thx . Charts 3.0 release yet?

@liuxuan30
Copy link
Member

no it's in master

@monkeyRing
Copy link
Author

ok . thx

@monkeyRing
Copy link
Author

@liuxuan30

i still can't found this after i changed master

2016-09-21 9 47 06

2016-09-21 9 46 47

@liuxuan30
Copy link
Member

Chart 3.0 has changed a lot. Use latest API

@monkeyRing
Copy link
Author

ok :) 👍 @liuxuan30

@Rushabh5
Copy link

Hello @monkeyRing ,

Are you set xValue in any graph.?

@monkeyRing
Copy link
Author

monkeyRing commented Sep 26, 2016

Not yet , I just want to set the x-axis of a chart of the X-coordinate data.
As I always shot as the usage before the update to 3.0.
But after the update to 3.0, you can not find the property of the xValus.
In 3.0v, i had already knew about how to set the x-axis, and the use of IAxisValueFormatter.
:) @rs10693

@Rushabh5
Copy link

Rushabh5 commented Sep 26, 2016

@monkeyRing So can you please explain me i have create 1 array for store all xvalue and then after fetching using for loop but in bar chart and line chart pass double value so i can't converted in to string. like,

for (int i = 0; i < yAxisArray.count; i++)//individual bar value
{
    double yVal = [[yAxisArray objectAtIndex:i] doubleValue];
    double xVal = [[xVals objectAtIndex:i] doubleValue];

    NSLog(@"%f", xVal);

    [yVals1 addObject:[[BarChartDataEntry alloc] initWithX:xVal y:yVal]];
}

and i want to display string value in x like 26-09,25-09

@monkeyRing
Copy link
Author

monkeyRing commented Sep 26, 2016

you should set xvals like this

Class ChartViewController : UIViewController, IAxisValueFormatter //step1
  {
     var xVals = [String]()  // step2,   Declare a global variable array for time
      override func viewDidLoad() {
         super.viewDidLoad()
         setupChartStyle()    // step 3
       }

       func setupChartStyle() {
          combinedChartView.chartDescription?.text = ""
          combinedChartView.noDataText = "加载中..."
          combinedChartView...
          combinedChartView.xAxis.valueFormatter = self   // Important statement, don't forgot this st.
        }

       func setChartData() {   // set ChartData DataSource  step 4
            for i in 0..<data.count {
                xVals.append("Time string formatted")    // In this step, you can format time strings.
            }
       }
}

Formatter Xvals Implementation && IAxisValueFormatter Method

step5

// return xVals value  
    func stringForValue(_ value: Double, axis: AxisBase?) -> String {
        return xVals[Int(value) % xVals.count]
    }
// OR
    func stringForValue(_ value: Double, axis: AxisBase?) -> String {
        return xVals[Int(value)]
    }

After taking time to string array to achieve x-axis formatting method and return

@rs10693

@Rushabh5
Copy link

can you describe in objective-c. @monkeyRing bcoz i found IAxisValueFormatter this class in swift. so how to use in obj-c i don't knw.

@monkeyRing
Copy link
Author

@rs10693 see the ChartsDemo . the ChartsDemo is described in objective-c

@monkeyRing
Copy link
Author

@rs10693
1

snip20160926_6
snip20160926_7

you can see the ChartsDemo . there are the simpleCode

@Rushabh5
Copy link

Rushabh5 commented Sep 27, 2016

Hello @monkeyRing

Thanks for help but now 1 problem m facing so please help me.

i given a Screen shot and see, in that all barchart are combine. i am using bar and line chart both are display same.
chart

@liuxuan30
Copy link
Member

@rs10693 Please refer to ChartsDemo first. Seems you don't setup chart data properly.

@Rushabh5
Copy link

Hello @liuxuan30 @monkeyRing

Thank you very much to both of you. now it's perfect.

@oscams
Copy link

oscams commented Dec 2, 2016

perfect solution!

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