不要使用核心图在条形图中显示轴线 [英] Don't Display the Axis line in bar chart using core plot

查看:71
本文介绍了不要使用核心图在条形图中显示轴线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想在条形图视图中显示轴线。我只想显示条形图,我该如何删除该轴线?

i dont want show Axis line in bar graph view. i want to show only the bar plot how can i remove that Axis line?

那是每当我运行应用程序时它显示的XY轴,但我可以在哪里删除以免显示该轴线。我无法添加图片,所以我在这里添加了代码

that is whenever i run the application its showing XY Axis but where i can remove for wont display that Axis line. i cant add image so i added code here

在这里查看我的代码:

  - (void)generateData
  {
  NSMutableDictionary *dataTemp = [[NSMutableDictionary alloc] init];

   //Array containing all the dates that will be displayed on the X axis
   dates = [NSArray arrayWithObjects:@"A", @"B", @"C", 
         @"D", @"E", nil];

//Dictionary containing the name of the two sets and their associated color
//used for the demo
sets = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], @"Plot 1", nil];

//Generate random data for each set of data that will be displayed for each day
//Numbers between 1 and 10
for (NSString *date in dates) {
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    for (NSString *set in sets) {


        NSNumber *num = [NSNumber numberWithInt:arc4random_uniform(8)+1];


        [dict setObject:num forKey:set];
    }
    [dataTemp setObject:dict forKey:date];
}

data = [dataTemp copy];

NSLog(@"%@", data);
 }
- (void)generateLayout
{
//Create graph from theme
graph                               = [[CPTXYGraph alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
self.hostedGraph                    = graph;
/*graph.paddingLeft                   = 25.0;
graph.paddingTop                    = 10.0;
graph.paddingRight                  = 10.0;
graph.paddingBottom                 = 50.0;
*/

//Add plot space
CPTXYPlotSpace *plotSpace       = (CPTXYPlotSpace *)graph.defaultPlotSpace;
plotSpace.delegate              = self;
plotSpace.yRange                = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(0) 
                                                               length:CPTDecimalFromFloat(10.0f)];
plotSpace.xRange                = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-1.0f) 
                                                               length:CPTDecimalFromFloat(8.0f)];


//Create a bar line style
CPTMutableLineStyle *barLineStyle   = [[CPTMutableLineStyle alloc] init];
barLineStyle.lineWidth              = 1.0;
barLineStyle.lineColor              = [CPTColor whiteColor];
CPTMutableTextStyle *whiteTextStyle = [CPTMutableTextStyle textStyle];
whiteTextStyle.color                = [CPTColor whiteColor];





 //Plot
 BOOL firstPlot = YES;


for (NSString *set in [[sets allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]) {


    CPTBarPlot *plot        = [CPTBarPlot tubularBarPlotWithColor:[CPTColor blueColor] horizontalBars:NO];
   plot.lineStyle          = barLineStyle;
    CGColorRef color        = ((UIColor *)[sets objectForKey:set]).CGColor;
    plot.fill               = [CPTFill fillWithColor:[CPTColor colorWithCGColor:color]];
    if (firstPlot) {
        plot.barBasesVary   = NO;
        firstPlot           = NO;
    } else {
        plot.barBasesVary   = YES;
    }
    plot.barWidth           = CPTDecimalFromFloat(0.5f);
    plot.barOffset=CPTDecimalFromFloat(0.5f);
    plot.barsAreHorizontal  = NO;
    plot.dataSource         = self;
    plot.identifier         = set;
    [graph addPlot:plot toPlotSpace:plotSpace];

    [plotSpace scaleToFitPlots:[graph allPlots]];
}




//Add legend
CPTLegend *theLegend      = [CPTLegend legendWithGraph:graph];
theLegend.numberOfRows    = sets.count;
theLegend.fill            = [CPTFill fillWithColor:[CPTColor colorWithGenericGray:0.15]];
theLegend.borderLineStyle = barLineStyle;
theLegend.cornerRadius    = 10.0;
theLegend.swatchSize      = CGSizeMake(15.0, 15.0);
whiteTextStyle.fontSize   = 13.0;
theLegend.textStyle       = whiteTextStyle;
theLegend.rowMargin       = 5.0;
theLegend.paddingLeft     = 10.0;
theLegend.paddingTop      = 10.0;
theLegend.paddingRight    = 10.0;
theLegend.paddingBottom   = 10.0;
graph.legend              = theLegend;
graph.legendAnchor        = CPTRectAnchorTopLeft;
graph.legendDisplacement  = CGPointMake(80.0, -10.0);

}

 - (void)createGraph
{
//Generate data
[self generateData];


//Generate layout
[self generateLayout];
}



   #pragma mark - CPTPlotDataSource methods

  - (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
return dates.count;
}

   - (double)doubleForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:  (NSUInteger)index
{


 double num = NAN;

//X Value
if (fieldEnum == 0) {
    num = index;
}

else {
    double offset =0;

    if (((CPTBarPlot *)plot).barBasesVary) {

        for (NSString *set in [[sets allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]) {

            if ([plot.identifier isEqual:set]) {

                break;
            }
            offset += [[[data objectForKey:[dates objectAtIndex:index]]  objectForKey:set] doubleValue];
        }
    }


    //Y Value
    if (fieldEnum == 1) {
        num = [[[data objectForKey:[dates objectAtIndex:index]]     objectForKey:plot.identifier] doubleValue] + offset;
    }


    //Offset for stacked bar
    else {
        num = offset;
    }
}

//NSLog(@"%@ - %d - %d - %f", plot.identifier, index, fieldEnum, num);

return num;
  }

  @end


推荐答案

使用 [CPTLineStyle lineStyle] 将显示一条细黑线。您还可以创建 CPTMutableLineStyle 并修改样式属性,包括颜色,宽度,线连接和虚线图案以自定义外观

Using [CPTLineStyle lineStyle] will give a thin black line. You can also create a CPTMutableLineStyle and modify the style properties including the color, width, line join, and dash pattern to customize the look

还可以尝试以下波纹线

minorTickLineStyle 属性设置为 nil

有关更多详细信息,请参见此链接

for more details see this link

HighLevelDesignOverview

for CPTLineStyle ,您可以从此链接获取信息。

for CPTLineStyle , you can get information from this link..

CPTLineStyle

这篇关于不要使用核心图在条形图中显示轴线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆