-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
LineChart X-Axis - How To Always Display First & Last Label #2006
Comments
try /// if set to true, the chart will avoid that the first and last label entry in the chart "clip" off the edge of the chart
open var avoidFirstLastClippingEnabled = false |
@cnowak7 Were you able to solve the issue mentioned in the 2nd image? Please share the solution |
|
If I look into the source code, the axis entries are calculated in |
#2007 seems same issue with this one? |
@liuxuan30 I use custom String array as X-Axis Values i.e. Dates |
This is how my chart looks when setting Here's some extra code that I'm using to set up my X-Axis:
|
I am using Charts 3.0.1 by the way :) |
Same here. Charts 3.0.1, XCode 8.0 and Swift 3.0 |
If a solution isn't possible for this situation, I guess a workaround that would probably make sense would be to, when the chart is displayed, highlight the last value (today) so that the "BalloonMarker" shows up displaying the text "Dec XX\n500". |
On my side obviously :) |
OK I checked it. In chart 3.0, x axis behaves like y axis, so you can check out your y axis labels, the biggest y axis label is smaller than data's max value, in In For example in ChartsDemo - Line Chart Dual YAxis, if my x values are from 0 to 20, The reason If you want to sure the label that is your data's x value, you have to tweak @danielgindi what you do think for such user cases? |
@liuxuan30 We don't want to tweak I first generate the formatted values (e.g. day names or formatted days) and then set them as:
What I need is a smarter This is a very basic and very common use case. |
I understand. There are still bugs about the x axis labels, e.g. label overlap. Maybe I should use 'override' rather than 'tweak' for computeAxisValues(). You can provide an implementation to make sure your first/last value is always displayed as workaround. However, this might cause the label out of bound or other issues. Another way is, you can try // force label count
if axis.isForceLabelsEnabled
{
interval = Double(range) / Double(labelCount - 1)
// Ensure stops contains at least n elements.
axis.entries.removeAll(keepingCapacity: true)
axis.entries.reserveCapacity(labelCount)
var v = yMin
for _ in 0 ..< labelCount
{
axis.entries.append(v)
v += interval
}
n = labelCount
} It does not involves the addtional process, just simple math. |
@liuxuan30 What if the x-axis values are in String format? In my case, the x-axis values are Dates in String format |
@vaibhav-varshaaweblabs x axis now is taking double ONLY in Chart 3.x, so you can use valueFormatter to display the label instead of the double. However, the valueFormatter might be complicated, when you need to consider zooming/scrolling |
Has anyone found a solution for this in Charts 3.0.2? I'm using date strings for my x-axis labels and seeing the last label disappear occasionally, but having trouble reproducing. This is with |
@vaibhav-varshaaweblabs @raudabaugh : How did u guys manage to plot strings on the X-Axis, as the setDataCount method is expecting int or double values for X and Y. |
bottomAxis.setLabelCount(entries.size(), true); and also set margin right to make visible last count. |
This will help for display last value of line chart - i tried and worked for me |
setLabelCount does not work if there are many x values. |
After doing |
In my Line Chart, I have it set up so that if there's only one data entry, I make the data point show up in the middle like this:
If there's more data entries, it'll look more like this:
The problem I'm having is that the last label on the X-Axis is not showing up. This is data from the past 30 days, so I'd like the last label, Dec 25, to show up. Is there a way to make my Line Chart always display the first and last label on the X-Axis? I don't care how it computes or skips the labels in between.
The text was updated successfully, but these errors were encountered: