ChartsOrg / ChartsOrg/Charts

Chart X axis not ploting data as per dataset when need to show duplicate values

Open
#4,706 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
28k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Issue is : [Image to understand](https://i.stack.imgur.com/nwmTO.png) :: Described below

The issue is, it is ploting up and down at same X value. Instead of that, i want to display both X values in left right. Basically want X values based on Dataset's X values.

Tried various ways :

Way 1:

`lineView.xAxis.valueFormatter = IndexAxisValueFormatter(values: arrStrDates) // arrStrDates is X Axis label values`

Way 2:

Tried by creating custom formatter :

```
class CustomLabelsAxisValueFormatter : NSObject, IAxisValueFormatter {

var labels: [String] = []

func stringForValue(_ value: Double, axis: AxisBase?) -> String {

let count = self.labels.count

guard let axis = axis, count > 0 else {

return ""
}

let factor = axis.axisMaximum / Double(count)

let index = Int((value / factor).rounded())

if index >= 0 && index < count {

return self.labels[index]
}

return ""
}
}

let formatter = CustomLabelsAxisValueFormatter()

formatter.labels = xVals

chart.xAxis.valueFormatter = formatter
```
Way 3 :

```
lineView.xAxis.granularityEnabled = true
lineView.xAxis.granularity = 1.0
```
This is how adding into datasets:
```

let data = LineChartData()
data.dataSets.append(dataset1)
data.dataSets.append(dataset2)
chartView.data = data
```

Dataset value is as below.
[Aug 19, 110]
[Aug 14, 120]
[Aug 14, 135]
[Aug 10, 110]….

What I am expecting in X axis, it should plot only dates which is in array. 19,14,14,10 and so on..
issue is currently it is plotting 19,17,16,14,12,10,8(Which you can see in question image) which is automatically by chart itself.
I want to plot x axis as per dataset(Array) only.[Based on date only]

Contributor guide

Open the contributing guide

Research direction

Reproduce the chart using the shown LineChartData setup, duplicate Aug 14 x-values, and the xAxis formatter options. Start by tracing how the chart generates x-axis labels and positions dataset entries, then compare that behavior with the requested 19,14,14,10 labels. Done means duplicate dataset dates are represented as requested without automatically inserted date labels.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
data-visualization, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.