Warum wird nicht meine x-Achse zeigen, mit Kern-Plot auf dem iPhone?
-
20-09-2019 - |
Frage
EDIT: Ich denke, meine Frage besser als formuliert ist: Wie kann ich eine Y-Achse, die nicht bei Null startet? Es scheint, wie die X-Achse immer auf der y = 0 gesetzt wird, aber ich würde die x-Achse wie irgend positive Zahl auf der y-Achse sein.
Hier ist ein Graph mit regelmäßigen Daten ... Ich möchte nur die x-Achse bei dem minimalen y-Wert für das Grundstück gelegt wurde (etwa 77), statt bei 0.
Hier ist die Funktion, die ich verwende, um die Grafik zu erstellen.
Es ist eine ganze Reihe von Code, und ich bin nicht ganz sicher, welches Stück aus sein könnte, nicht die x-Achse angezeigt werden soll.
Könnte die x-Achse etwas nicht zeigen, haben mit meinen Daten zu tun?
- (void) showGraph:(SavedDetailScreen*)dataSource {
// create the graph and add it to the view
CPXYGraph *graph = [[CPXYGraph alloc] initWithFrame: CGRectZero];
graph.plotArea.masksToBorder = NO;
CPLayerHostingView *graphView = [[CPLayerHostingView alloc] initWithFrame:CGRectMake(0,0, 280, 240)];
[self addSubview:graphView];
graphView.hostedLayer = graph;
graph.paddingLeft = 50.0;
graph.paddingTop = 20.0;
graph.paddingRight = 10.0;
graph.paddingBottom = 40.0;
// set up the ranges for the graph axis
float minElevation = dataSource.track.tbStats.minAlt;
float maxElevation = dataSource.track.tbStats.maxAlt-dataSource.track.tbStats.minAlt;
float minDistance = 0.0f;
float maxDistance = dataSource.track.tbStats.totalDistance;
CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minDistance)
length:CPDecimalFromFloat(maxDistance)];
plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(minElevation)
length:CPDecimalFromFloat(maxElevation)];
// style the graph with white text and lines
CPTextStyle *whiteText = [CPTextStyle textStyle];
whiteText.color = [CPColor whiteColor];
CPLineStyle *whiteStyle = [CPLineStyle lineStyle];
whiteStyle.lineColor = [CPColor whiteColor];
whiteStyle.lineWidth = 2.0f;
// set up the axis
CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet;
CPXYAxis *x = axisSet.xAxis;
CPXYAxis *y = axisSet.yAxis;
x.majorIntervalLength = CPDecimalFromFloat(maxDistance/10.0f);
x.minorTicksPerInterval = 0;
x.majorTickLineStyle = whiteStyle;
x.minorTickLineStyle = whiteStyle;
x.axisLineStyle = whiteStyle;
x.minorTickLength = 5.0f;
x.majorTickLength = 10.0f;
x.labelOffset = 3.0f;
x.labelTextStyle = whiteText;
y.majorIntervalLength = CPDecimalFromFloat(maxElevation/5.0f);
y.minorTicksPerInterval = 0;
y.majorTickLineStyle = whiteStyle;
y.minorTickLineStyle = whiteStyle;
y.axisLineStyle = whiteStyle;
y.minorTickLength = 5.0f;
y.majorTickLength = 10.0f;
y.labelOffset = 3.0f;
y.labelTextStyle = whiteText;
CPScatterPlot *plot = [[[CPScatterPlot alloc] initWithFrame:graph.bounds] autorelease];
plot.dataLineStyle.lineWidth = 2.0f;
plot.dataLineStyle.lineColor = [CPColor blueColor];
plot.dataSource = dataSource;
[graph addPlot:plot];
CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol];
greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]];
greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
plot.plotSymbol = greenCirclePlotSymbol;
}
Lösung
Sie legen die Position einer Achse auf der orthogonalen Achse der constantCoordinateValue Eigenschaft der Achse verwendet wird. Genau festgelegt, dass das Eigentum auf der x auf einen positiven Wert von y-Achse und die Achse sollte nach oben bewegen.
Andere Tipps
Ich habe das gleiche Problem gestern / heute hatte und die Lösung scheint die orthogonalCoordinateDecimal Eigenschaft auf der Achse zu verwenden. Zum Beispiel:
graph.axisSet.xAxis.orthogonalCoordinateDecimal = CPDecimalFromFloat(minHeight);
https://github.com/djw/core-plot/tree/ 9282845bddbb8c40ff314bbfa158beff797c91f7 / Beispiele
Diese besagen, dass die isFloatingAxis Eigenschaft wird von mindestens Version 0.9 entfernt worden ist.
Ich fand auch diese in der Diskussionsgruppe als auch http: //code.google.com/p/core-plot/issues/detail?id=125
Nach einiger Jagd, es sieht aus wie die neue Art und Weise eine Achse sieht wie folgt zu schweben:
x.axisConstraints = [CPTConstraints constraintWithUpperOffset:132];
Dieser Rahmen muss wirklich einen besseren Weg, sich selbst zu konfigurieren. Ich sehe kein Problem herausspringt. Vielleicht versuchen Sie einfach die Methode auf den Punkt zu vereinfachen, wo das Debuggen überschaubar wird. Überprüfen Sie die Daten, die Sie in, um sicherzustellen, sind vorbei ist es, was Sie es erwarten. Noch besser wäre es, erstellen Sie einige Dummy-Daten, dass Sie produzieren kennen das Grundstück Sie erwarten.