【问题标题】:Core Plot CPTScatterPlot 'Line Graph' not showing核心绘图 CPTScatterPlot '折线图' 未显示
【发布时间】:2012-06-11 10:55:09
【问题描述】:

所以我的问题很简单。我正在尝试将我的图表从条形图切换到折线图,但我的折线图没有显示/绘图。我对我的 CPTBarPlot '条形图' 使用了类似的代码,并且这个绘图/显示正确。

我正确绘制的条形图代码是:

CPTBarPlot *barPlot             = nil;    
barPlot                         = [CPTBarPlot tubularBarPlotWithColor:[CPTColor colorWithComponentRed:0.9294f green:0.3960f blue:0.5921f alpha:1.0f] horizontalBars:NO];
barPlot.fill                    = [CPTFill fillWithColor:[CPTColor colorWithComponentRed:0.9294f green:0.3960f blue:0.5921f alpha:1.0f]];
barPlot.opacity                 = 0.8f;
barPlot.dataSource              = self;
barPlot.delegate                = self;
barPlot.baseValue               = CPTDecimalFromString(@"0");
barPlot.barOffset               = CPTDecimalFromFloat(0.50f);

switch (graphType) {
    case kWeightThreeMonth:
    {
        barPlot.identifier  = [GraphsViewController threeMonthBarPlotIdentifier];
    }
        break;

    case kWeightSixMonth:
    {
        barPlot.identifier  = [GraphsViewController sixMonthBarPlotIdentifier];
    }
        break;

    case kWeightNineMonth:
    {
        barPlot.identifier  = [GraphsViewController nineMonthBarPlotIdentifier];
    }
        break;  
    default:
        break;
} 
barPlot.barCornerRadius         = 2.0f;
barPlot.lineStyle               = nil;
[lineGraph addPlot:barPlot toPlotSpace:plotSpace];

我没有显示的线图代码是:

// Create a blue plot area
CPTScatterPlot *boundLinePlot   = [[[CPTScatterPlot alloc] init] autorelease];
CPTMutableLineStyle *lineStyle  = [CPTMutableLineStyle lineStyle];
lineStyle.miterLimit            = 1.0f;
lineStyle.lineWidth             = 3.0f;
lineStyle.lineColor             = [CPTColor redColor];
boundLinePlot.dataLineStyle     = lineStyle;
switch (graphType) {
    case kWeightThreeMonth:
    {
        boundLinePlot.identifier  = [GraphsViewController threeMonthBarPlotIdentifier];
    }
        break;

    case kWeightSixMonth:
    {
        boundLinePlot.identifier  = [GraphsViewController sixMonthBarPlotIdentifier];
    }
        break;

    case kWeightNineMonth:
    {
        boundLinePlot.identifier  = [GraphsViewController nineMonthBarPlotIdentifier];
    }
        break;  
    default:
        break;
} 

boundLinePlot.dataSource    = self;
boundLinePlot.delegate      = self;
[lineGraph addPlot:boundLinePlot toPlotSpace:plotSpace];

// Do a blue gradient
CPTColor *areaColor1        = [CPTColor colorWithComponentRed:0.3 green:0.3 blue:1.0 alpha:0.8];
CPTGradient *areaGradient1  = [CPTGradient gradientWithBeginningColor:areaColor1 endingColor:[CPTColor clearColor]];
areaGradient1.angle         = -90.0f;
CPTFill *areaGradientFill   = [CPTFill fillWithGradient:areaGradient1];
boundLinePlot.areaFill      = areaGradientFill;
boundLinePlot.areaBaseValue = [[NSDecimalNumber zero] decimalValue];

// Add plot symbols
CPTMutableLineStyle *symbolLineStyle = [CPTMutableLineStyle lineStyle];
symbolLineStyle.lineColor   = [CPTColor blackColor];
CPTPlotSymbol *plotSymbol   = [CPTPlotSymbol ellipsePlotSymbol];
plotSymbol.fill             = [CPTFill fillWithColor:[CPTColor blueColor]];
plotSymbol.lineStyle        = symbolLineStyle;
plotSymbol.size             = CGSizeMake(10.0, 10.0);
boundLinePlot.plotSymbol    = plotSymbol;

我在这里遗漏了什么吗?考虑到条形图正常工作,我认为数据源等都将以相同的方式工作。我只是想从条形图切换到折线图。

任何帮助将不胜感激。

亲切的问候, 丹

【问题讨论】:

    标签: iphone objective-c ios core-plot


    【解决方案1】:

    您可能需要重新加载绘图数据。尝试这样做:

    [lineGraph reloadData]
    

    【讨论】:

    • 嗨斯凯拉姆。不幸的是,我已经在我的代码底部执行此操作(未在我的原始帖子中显示。)它很奇怪,我希望条形图和折线图以类似的方式工作。不知道为什么条形图正确绘制和显示,而折线图没有。两者的区别,基本上就是我原帖中的代码。谢谢
    【解决方案2】:

    这其实是我自己的错。

    在数据源方法中;

    -(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
    -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
    

    我在做一个 if 语句;

    if ( [plot isKindOfClass:[CPTBarPlot class]] ){
    

    当然,我使用的是 CPTScatterPlot,所以我的代码没有被调用。呵呵。

    【讨论】:

      猜你喜欢
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-28
      • 2015-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多