Comments (11)
There are discussions about supporting this directly-
But still it can be done virtually, as mapping values to dates in your data
provider. It's not optimal, but can do the trick.
As you can map days or months to x-values, and can convert a date to a
decimal value, it's really easy to implement. And you can supply your own
formatters for just about anything :)
from charts.
In case anybody faces the same issue: I solved it by using the timestamp of the (chronologically) first value in the chart as zero and using the seconds between the first value and each of the following values as xIndex like that:
yVals.append(ChartDataEntry(value: [some float], xIndex: [time interval between a value and the first value] * count / [time interval between first and last value]))
I am currently working on the x-Axis description (corresponding dates). These are still ordered by count and not by timestamp. More on that as soon.
from charts.
Update on the x-Axis description (bit hacky, though): I simply add an "independent" date value for each float value to display in the chart.
let timeInterval = Int(dateOfFirstMeasurement.timeIntervalSince1970) + Int([loop iterator] * timeIntervalTotal / [count of float values to display])
xVals.append(dateFormatter.stringFromDate(NSDate(timeIntervalSince1970: NSTimeInterval(timeInterval))))
from charts.
I am also currently trying to find a good solution for the NSDate mapping. My solution at the moment is to add all xValues at the beginning for the TimeInterval to Show and later map the data xValue to the shown TimeInterval.
-
(void)addDataSetForSymptom:(Symptom *)symptom
{
NSArray *entries = [self.dataEntryStore entriesSince:self.startDate until:self.endDate withSymptom:symptom];
NSMutableArray *values = [NSMutableArray array];for (DataEntry _entry in entries)
{
ChartDataEntry *de = [[ChartDataEntry alloc] initWithValue:[entry.level floatValue]_100 xIndex:[self xValueForEntry:entry]];
[values addObject:de];
}LineChartDataSet *set = [[LineChartDataSet alloc] initWithYVals:values];
set.lineWidth = 2.5f;
set.circleRadius = 5.0;
[set setColor:ChartColorTemplates.vordiplom[0]];
[set setCircleColor:ChartColorTemplates.vordiplom[0]];
[set setCircleHoleColor: Rgb2UIColor(51, 51, 51)];
set.drawValuesEnabled = NO;[self.chartData addDataSet:set];
self.lineChart.data = self.chartData;
} -
(void)fillXValues
{
NSTimeInterval ti = [self.endDate timeIntervalSinceDate:self.startDate]/60;for (int i = 0; i < ti ; i ++)
{
[self.chartData addXValue:[@(i) stringValue]];
}
} -
(NSInteger)xValueForEntry:(DataEntry *)entry
{
return [self.endDate timeIntervalSinceDate:entry.date]/60;
}
My problem is, if I want to display the data of a whole year, I have to add too many xValues. Is your solution doing the same trick caloon?
from charts.
365 values are not a lot :-)
On Mon, Apr 27, 2015 at 5:21 PM, FranzBusch [email protected]
wrote:
I am also currently trying to find a good solution for the NSDate mapping.
My solution at the moment is to add all xValues at the beginning for the
TimeInterval to Show and later map the data xValue to the shown
TimeInterval.
(void)addDataSetForSymptom:(Symptom *)symptom
{
NSArray *entries = [self.dataEntryStore entriesSince:self.startDate
until:self.endDate withSymptom:symptom];
NSMutableArray *values = [NSMutableArray array];for (DataEntry
_entry in entries) { ChartDataEntry *de = [[ChartDataEntry alloc]
initWithValue:[entry.level floatValue]_100 xIndex:[self
xValueForEntry:entry]];
[values addObject:de];
}LineChartDataSet *set = [[LineChartDataSet alloc]
initWithYVals:values];
set.lineWidth = 2.5f;
set.circleRadius = 5.0;
[set setColor:ChartColorTemplates.vordiplom[0]];
[set setCircleColor:ChartColorTemplates.vordiplom[0]];
[set setCircleHoleColor: Rgb2UIColor(51, 51, 51)];
set.drawValuesEnabled = NO;[self.chartData addDataSet:set];
self.lineChart.data = self.chartData;
}
-(void)fillXValues
{
NSTimeInterval ti = [self.endDate
timeIntervalSinceDate:self.startDate]/60;for (int i = 0; i < ti ; i ++)
{
[self.chartData addXValue:[@(i) stringValue]];
}
}
-(NSInteger)xValueForEntry:(DataEntry *)entry
{
return [self.endDate timeIntervalSinceDate:entry.date]/60;
}My problem is, if I want to display the data of a whole year, I have to
add too many xValues. Is your solution doing the same trick caloon?—
Reply to this email directly or view it on GitHub
#38 (comment)
.
from charts.
365 is no problem;)
But if I want to cover every minute of one month, I have to handle about 43.000 values.
from charts.
Man you shouldn't do that. You need to run an averaging filter on your data
בתאריך יום שני, 27 באפריל 2015, FranzBusch [email protected] כתב:
365 is no problem;)
But if I want to cover every minute of one month, I have to handle about
43.000 values.—
Reply to this email directly or view it on GitHub
#38 (comment)
.
from charts.
You are probably right about that. I was just trying to experiment with the time it needs to display..
Another question I think the xAxisLabelModulus is not working properly.
ChartXAxis *xAxis = self.lineChart.xAxis;
xAxis.labelFont = [UIFont systemFontOfSize:12.f];
xAxis.labelPosition = XAxisLabelPositionBottom;
xAxis.labelTextColor = UIColor.whiteColor;
xAxis.axisLabelModulus = 24;
After this setUp code the chart still doesn't apply the modulus. Is it not possible to set a fixed modulus?
from charts.
Follow up on your first comment @FranzBusch: my app does not contain too much data (e.g. no stock prices) and I only tried it with about 70-80 xValues. Averaging the data should be the right way to go. There won't be "enough space" to display 43000 values on your iOS device anyway.
I also planned to use an averaging filter. If values are "too close to each other" in x-direction, the cubic line will make it look like the chart is not ordered correctly, with graphs going backwards. @danielgindi: Is there an averaging mechanism built into ios-charts?
from charts.
Actually there is a filtering mechanism with one filter implemented- a very
specific averaging algorithm suited for charts.
But it is disabled right now because of structural changes in the
MPAndroidChart library. It will be re-enabled soon again, I hope!
בתאריך יום שני, 27 באפריל 2015, Josef [email protected] כתב:
Follow up on your first comment @FranzBusch
https://github.com/FranzBusch: my app does not contain to much data
(e.g. no stock prices) and I only tried it with about 70-80 xValues.Averaging the data should be the right way to go. There presumably won't
be "enough space" on your iOS device to display 43000 values anyway.I also planned to use an averaging filter. If values are "to close to each
other" in x-direction, the cubic line will make it look like the chart is
not ordered correctly. @danielgindi https://github.com/danielgindi: Is
there an averaging mechanism already built into ios-charts?—
Reply to this email directly or view it on GitHub
#38 (comment)
.
from charts.
Follow up - my first code sample was not guide as it caused the line chart to vanish (cp. issue #63). Instead of the xIndices, yVals should be an approximation.
The right way to go (sorry but its difficult to describe) would be to approximate each xIndex with a yVal:
- detect which two yVals are the closest to an xIndex (e.g. via for loop)
- calculate a relative yVal for the xIndex: (yVal(smaller than xIndex) * xDistance(between yVal greater than xIndex and xIndex) + yVal(greater than xIndex) * xDistance(between yVal smaller than xIndex and xIndex)) / xDistance(between yVal smaller than xIndex and yVal greater than xIndex)
from charts.
Related Issues (20)
- BarChart: highlight x-axis value when tapped HOT 1
- Incorrect scale of candlestick chart
- Y-axis max label is less than the highest Y-Value
- Library not loaded on physical device HOT 1
- crash animationUpdate() HOT 2
- Concurrency warning when conforming `ChartViewDelegate` with MainActor attribute.
- Pie chart update data set
- BalloonMarker Corner and barChart corner
- How to alpha background when select a marker ?
- How to alpha background when select a marker ? Now I use BalloonMarker
- Install pod 'DGCharts' & pod 'ChartsRealm' is the name of the libraries
- Install pod 'DGCharts' & pod 'ChartsRealm' is the name of the libraries, then i'm trying to build the application i'm getting below error:
- Install pod 'DGCharts' & pod 'ChartsRealm' is the name of the libraries, then i'm trying to build the application i'm getting errors: HOT 3
- Bar Chart Displaying Wrong Y Values JUST rightAxis,but leftAxis is OK!!! HOT 3
- Bar chart, x-axis or zero axis is overlapping the bars.
- % symbol not showing in Piechart
- View Destroy,RadarChartView not releasing, memory leak. Is there a solution?
- How to Fill Area Between Two Lines with Different Colors Based on Line Intersection
- [Crash] Renderers (isDrawingValuesAllowed func) crash - wrong data type cast causes host app to crash HOT 1
- The TestFlight upload was successful.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from charts.