0

任何人都可以告诉我如何在核心图中绘制填充不同颜色的面积图吗?我不想用 x 或 y 坐标填充颜色?我只想根据数组中给出的点填充颜色?PLZ伙计们,我需要你的帮助。我刚在这里打了3-4天?我的代码在这里。

CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)self.graph.defaultPlotSpace;

plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(  200)];
plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt(7)];

plotSpace.allowsUserInteraction=YES;
plotSpace.globalXRange   = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0) length:CPTDecimalFromInt([dates count]+3)];
plotSpace.delegate              = self;
plotSpace.yRange                = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(0)
                                                               length:CPTDecimalFromInt(200)];
plotSpace.xRange                = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromInt(-1)length:CPTDecimalFromInt(7)];                                                                             
CPTXYAxisSet *axisSet = (CPTXYAxisSet *)self.graph.axisSet;
NSSet *majorTickLocations = [NSSet setWithObjects:
                             [NSDecimalNumber numberWithUnsignedInteger:1],
                             [NSDecimalNumber numberWithUnsignedInteger:2],
                             [NSDecimalNumber numberWithUnsignedInteger:3],
                             [NSDecimalNumber numberWithUnsignedInteger:4],
                             [NSDecimalNumber numberWithUnsignedInteger:5],
                             [NSDecimalNumber numberWithUnsignedInteger:6],
                             [NSDecimalNumber numberWithUnsignedInteger:7],
                             nil];
CPTXYAxis *x                    = axisSet.xAxis;
x.orthogonalCoordinateDecimal   = CPTDecimalFromInt(-1);
x.majorIntervalLength           = CPTDecimalFromInt(1);//majorIntervalLength defines the number of units between “big” ticks on the axis. In this case it’s set to show one every 10 units.
x.minorTicksPerInterval         = 0;
x.labelingPolicy                = CPTAxisLabelingPolicyNone;

x.axisConstraints               = [CPTConstraints constraintWithLowerOffset:01.0];

x.majorTickLocations = majorTickLocations;

axisSet.xAxis.labelRotation = M_PI/4;

axisSet.xAxis.labelingPolicy = CPTAxisLabelingPolicyNone;
int labelLocations = 1;
NSMutableArray *customXLabels = [NSMutableArray array];
for (NSString *day in dates)
{
    CPTAxisLabel *newLabel = [[CPTAxisLabel alloc] initWithText:day textStyle:x.labelTextStyle];
    newLabel.tickLocation   = [[NSNumber numberWithInt:labelLocations] decimalValue];
    newLabel.offset         =x.labelOffset;// + x.majorTickLength;
    newLabel.rotation       = M_PI / 4;
    [customXLabels addObject:newLabel];
    labelLocations++;
    [newLabel release];
}
x.title = @"Data For X-Axis";
x.titleTextStyle = textStyle;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
    x.titleOffset = 35.0f;
}
else
x.titleOffset = 100.0f;

x.axisLabels                    = [NSSet setWithArray:customXLabels];
x.axisLineStyle=lineStyle;
x.majorTickLineStyle=lineStyle;
x.minorTickLineStyle=lineStyle;
x.labelTextStyle = textStyle;

    CPTXYAxis *y                    = axisSet.yAxis;
    y.title = @"Data For Y-Axis";
    y.titleTextStyle = textStyle;
    y.titleOffset = 20.0f;
    y.axisLineStyle = lineStyle;
    y.majorTickLineStyle = lineStyle;
    y.minorTickLineStyle = lineStyle;
    y.labelTextStyle = textStyle;
    y.labelOffset = 1.0f;
    y.majorIntervalLength = CPTDecimalFromFloat(10.0f);
    y.minorTicksPerInterval = 1;
    y.minorTickLength = 2.0f;
    y.majorTickLength = 5.0f;

    CPTMutableLineStyle *majorGridLineStyle = [CPTMutableLineStyle lineStyle];
    majorGridLineStyle.lineWidth = 1.5f;
    majorGridLineStyle.lineColor = [CPTColor lightGrayColor]; //[[CPTColor lightGrayColor] colorWithAlphaComponent:0.6f];
    y.majorGridLineStyle = majorGridLineStyle;

    x.orthogonalCoordinateDecimal = CPTDecimalFromString(@"0");

    CPTScatterPlot *plot = [[[CPTScatterPlot alloc] init] autorelease];
    CPTColor *aaplColor = [CPTColor greenColor];
    plot.dataSource = self;
    plot.identifier = @"SYS";
    plot.dataLineStyle = lineStyle;
    plot.plotSymbol = plotSymbol;
    [self.graph addPlot:plot toPlotSpace:plotSpace];


    CPTScatterPlot *googPlot = [[CPTScatterPlot alloc] init];
    googPlot.dataSource = self;
    googPlot.identifier = @"DIA";
    CPTColor *googColor = [CPTColor redColor];
    [self.graph addPlot:googPlot toPlotSpace:plotSpace];

    CPTMutableLineStyle *aaplLineStyle = [plot.dataLineStyle mutableCopy];
    aaplLineStyle.lineWidth = 1.5;
    aaplLineStyle.lineColor = aaplColor;
    plot.dataLineStyle = aaplLineStyle;

    CPTMutableLineStyle *aaplSymbolLineStyle = [CPTMutableLineStyle lineStyle];
    aaplSymbolLineStyle.lineColor = aaplColor;
    CPTPlotSymbol *aaplSymbol = [CPTPlotSymbol rectanglePlotSymbol];
    aaplSymbol.fill = [CPTFill fillWithColor:aaplColor];
    aaplSymbol.lineStyle = aaplSymbolLineStyle;
    aaplSymbol.size = CGSizeMake(6.0f, 6.0f);
    plot.plotSymbol = aaplSymbol;

    CPTMutableLineStyle *aaplLineStyle1 = [googPlot.dataLineStyle mutableCopy];
    aaplLineStyle1.lineWidth = 1.5;
    aaplLineStyle1.lineColor = googColor;
    googPlot.dataLineStyle = aaplLineStyle1;
    CPTMutableLineStyle *aaplSymbolLineStyle1 = [CPTMutableLineStyle lineStyle];
    aaplSymbolLineStyle1.lineColor = googColor;
    CPTPlotSymbol *aaplSymbol1 = [CPTPlotSymbol diamondPlotSymbol];
    aaplSymbol1.fill = [CPTFill fillWithColor:googColor];
    aaplSymbol1.lineStyle = aaplSymbolLineStyle1;
    aaplSymbol1.size = CGSizeMake(6.0f, 6.0f);
    googPlot.plotSymbol = aaplSymbol1;



    CPTLegend *theLegend      = [CPTLegend legendWithGraph:self.graph];
    theLegend.numberOfRows    = 1;
    theLegend.fill            = [CPTFill fillWithColor:[CPTColor colorWithGenericGray:.8]];

    theLegend.cornerRadius    = 2.0;
    theLegend.swatchSize      = CGSizeMake(8.0, 5.0);

    theLegend.rowMargin       = 5.0;
    theLegend.paddingLeft     = 5.0;
    theLegend.paddingTop      = 5.0;
    theLegend.paddingRight    = 5.0;
    theLegend.paddingBottom   = 5.0;
    self.graph.legend              = theLegend;
    self.graph.legendAnchor        = CPTRectAnchorTopLeft;
    self.graph.legendDisplacement  = CGPointMake(120.0, -2.0);
    graph.plotAreaFrame.borderLineStyle = nil;

我正在使用核心情节框架..

4

1 回答 1

1

如果您想更改图表线上的点颜色,那么只需更改这行代码中的颜色

aaplSymbol1.fill = [CPTFill fillWithColor:googColor];

如果你想改变每个点的颜色不同,那么在这条线上改变不同的颜色

aaplSymbol1.fill = [CPTFill fillWithColor:googColor]; 

对于每个不同的点。

于 2013-11-19T05:03:55.843 回答