Balkengrafik

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Balkengrafik

    Ich benötige für eine iPhone App eine Balkengrafik die auch noch zwei Liniengrafiken enthalten soll.

    Ich habe mir mal core plot kurz angeschaut, das sieht schon mal nicht schlecht aus.
    Bevor ich mich da jetzt ausführlicher mit beschäftige, die Fragen:

    Kann ich damit Balken- und Liniengrafiken mischen?

    Ist core plot überhaupt empfehlenswert?

    Was nutzt ihr so um Charts zu zeigen?
    Ich habe auch keine Loesung, aber ich bewundere das Problem!
    _____________________________________________________


    Hape42
  • Balkengrafik

    Hi Hape,

    Ich habe CorePlot schon benutzt und man kann damit eingetaucht ALLES machen. Aber es ist auch relativ komplex und bläht die app ungemein auf.
    Ich habe auch schon eine Balken und eine Liniengrafik komplett selber gemacht in einer iOS App mit ganz Einfachen Cocoa Funktionen zum zeichnen on Linien und Rechtecken. Fand ich auch nicht schwerer als sich in CorePlot einzuarbeiten.
    Also wenn es wirklich nur so einfache Diagramme sind würde ich es eben von Hand machen.

    Grus

    Claus
    2 Stunden Try & Error erspart 10 Minuten Handbuchlesen.

    Pre-Kaffee-Posts sind mit Vorsicht zu geniessen :)
  • hape42 schrieb:


    Ist core plot überhaupt empfehlenswert?

    Was nutzt ihr so um Charts zu zeigen?


    Ich finde Core Plot super. Die Dokumentation ist … äh … der Code, was definitiv ein großes Manko ist. Das Prinzip ist aber leicht zu durchschauen und funktioniert wie z.B. eine UITableViewDataSource. Du konfigurierst Deinen Graphen und implementierst die passenden Datasource-Methoden, fertig.
  • mit core Plot war es dann doch relativ einfach ein Ergebnis zu erzielen:

    [Blockierte Grafik: http://www.hape42.de/graph.png]

    Ich hab nur zwei kleinere Probleme:

    1. rechts und links wird immer nur ein "halber" Balken angezeigt.

    2. ging ich davon aus, dass der Balken einfach schmaler wird, wenn immer mehr Daten angezeigt werden. Wird er aber nicht, es fehlen rechts zwei Balken. Die Daten sind da und werden auch über

    Quellcode

    1. -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
    richtig zugewiesen. Nur scheinen die irgendwo "rechts" außerhalb des sichtbaren Bereichs zu stehen.

    Hat jemand eine Idee?

    Quellcode

    1. - (void) initGraph
    2. {
    3. UIView *viewToRemove = [self.view viewWithTag:1];
    4. if(hostingView != nil)
    5. [viewToRemove removeFromSuperview];
    6. barLineChart = [[CPTXYGraph alloc] initWithFrame:CGRectMake(0, 0, 320, 380)];
    7. barLineChart.plotAreaFrame.borderLineStyle = nil;
    8. barLineChart.plotAreaFrame.cornerRadius = 0.0f;
    9. barLineChart.paddingLeft = 0.0f;
    10. barLineChart.paddingRight = 0.0f;
    11. barLineChart.paddingTop = 0.0f;
    12. barLineChart.paddingBottom = 0.0f;
    13. barLineChart.plotAreaFrame.paddingLeft = 40.0;
    14. barLineChart.plotAreaFrame.paddingTop = 40.0;
    15. barLineChart.plotAreaFrame.paddingRight = 10.0;
    16. barLineChart.plotAreaFrame.paddingBottom = 40.0;
    17. CPTMutableTextStyle *textStyle = [CPTTextStyle textStyle];
    18. textStyle.color = [CPTColor grayColor];
    19. textStyle.fontSize = 16.0f;
    20. textStyle.textAlignment = CPTTextAlignmentCenter;
    21. barLineChart.titleTextStyle = textStyle;
    22. barLineChart.titleDisplacement = CGPointMake(0.0f, -10.0f);
    23. barLineChart.titlePlotAreaFrameAnchor = CPTRectAnchorTop;
    24. CPTXYAxisSet *axisSet = (CPTXYAxisSet *)barLineChart.axisSet;
    25. CPTXYAxis *x = axisSet.xAxis;
    26. x.axisLineStyle = nil;
    27. x.majorTickLineStyle = nil;
    28. x.minorTickLineStyle = nil;
    29. x.majorIntervalLength = CPTDecimalFromString(@"10.0");
    30. x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
    31. x.titleLocation = CPTDecimalFromFloat(7.5f);
    32. x.titleOffset = 25.0f;
    33. x.labelingPolicy = CPTAxisLabelingPolicyNone;
    34. CPTXYAxis *y = axisSet.yAxis;
    35. y.axisLineStyle = nil;
    36. y.majorTickLineStyle = nil;
    37. y.minorTickLineStyle = nil;
    38. y.majorIntervalLength = CPTDecimalFromString(@"1");
    39. y.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");
    40. y.title = @"Schlaege";
    41. y.titleOffset = 40.0f;
    42. y.titleLocation = CPTDecimalFromFloat(150.0f);
    43. hostingView = [[CPTGraphHostingView alloc] initWithFrame:CGRectMake(0, 120, 320, 300)];
    44. hostingView.hostedGraph = barLineChart;
    45. hostingView.tag = 1;
    46. [self.view addSubview:hostingView];
    47. CPTGraph *graph = hostingView.hostedGraph;
    48. CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *) graph.defaultPlotSpace;
    49. plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromDouble(16.0f)];
    50. plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromDouble(0.0f) length:CPTDecimalFromInt([self maxScore])];
    51. CPTBarPlot *scorePlot = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
    52. scorePlot.baseValue = CPTDecimalFromString(@"0");
    53. scorePlot.identifier = @"Schlaege";
    54. scorePlot.cornerRadius = 2.0f;
    55. scorePlot.dataSource = self;
    56. [barLineChart addPlot:scorePlot];
    57. CPTScatterPlot *parPlot = [[CPTScatterPlot alloc] init];
    58. parPlot.dataSource = self;
    59. parPlot.identifier = @"Par";
    60. CPTColor *parColor = [CPTColor redColor];
    61. [graph addPlot:parPlot toPlotSpace:plotSpace];
    62. CPTMutableLineStyle *parLineStyle = [parPlot.dataLineStyle mutableCopy];
    63. parLineStyle.lineWidth = 3.0;
    64. parLineStyle.lineColor = parColor;
    65. parPlot.dataLineStyle = parLineStyle;
    66. CPTScatterPlot *schnittPlot = [[CPTScatterPlot alloc] init];
    67. schnittPlot.dataSource = self;
    68. schnittPlot.identifier = @"Schnitt";
    69. CPTColor *schnittColor = [CPTColor greenColor];
    70. [graph addPlot:schnittPlot toPlotSpace:plotSpace];
    71. CPTMutableLineStyle *schnittLineStyle = [schnittPlot.dataLineStyle mutableCopy];
    72. schnittLineStyle.lineWidth = 3.0;
    73. schnittLineStyle.lineColor = schnittColor;
    74. schnittPlot.dataLineStyle = schnittLineStyle;
    75. graph.legend = [CPTLegend legendWithGraph:graph];
    76. graph.legend.fill = [CPTFill fillWithColor:[CPTColor lightGrayColor]];
    77. graph.legend.cornerRadius = 5.0;
    78. graph.legend.numberOfColumns = 3;
    79. graph.legendAnchor = CPTRectAnchorBottomLeft;
    80. graph.legendDisplacement = CGPointMake(50.0, -25.0);
    81. }
    Alles anzeigen
    Ich habe auch keine Loesung, aber ich bewundere das Problem!
    _____________________________________________________


    Hape42