简体   繁体   English

带动画的ios简单条形图

[英]ios simple bar graph with animation

I need to show 2 bar graphs in my app, I dont want to use core-plot as is overkill to show just 2 bars with variant height, [UIimageView with box.png] 我需要在我的应用程序中显示2个条形图,我不想使用核心情节,因为过度杀伤只显示2个变量高度的条形图,[UIimageView with box.png]

i have done some tests just using UIView animations, wich seem to be enough to make the bar grow or shrink, [the problem is that the height is dependant on the starting point, so my bar doesnt have a point 0 for Y, wich changes with the height for the bar] 我只是使用UIView动画完成了一些测试,这似乎足以使条形成长或缩小,[问题是高度取决于起点,所以我的条形对Y没有0点,哪里有变化与酒吧的高度]

so how could i set a point 0 for my Y axis?, so I just have to think of heigh, and not the starting point as well? 那我怎么能为我的Y轴设置一个0点?所以我只需要考虑高度,而不是起点?

or shall i go with some bar generator framework that is not so over kill as core-plot ,, 或者我应该使用一些不像核心情节那样过度杀死的条形发生器框架,

what is the simplest, lightest weight? 什么是最简单,最轻的重量?

power-plot 电积

ecgraph , Other? ecgraph ,其他?

PS. PS。 the other point is that i need to have a custom background for the chart, and custom bars thats why im using box.png for the bars] 另一点是,我需要有一个自定义的图表背景,自定义栏,这就是为什么我使用box.png为条]

the code... 编码...

viewDidLoad { ***
CGRect chartbackGroundImageRect = CGRectMake(150, 20, 632, 653);
UIImageView *chartbackGroundImage = [[UIImageView alloc] initWithFrame:chartbackGroundImageRect];
[chartbackGroundImage setImage:[UIImage imageNamed:@"chartArtBgnd.png"]];
chartbackGroundImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:chartbackGroundImage];
[chartbackGroundImage release];
CGRect leftBarImageRect = CGRectMake(550, 550, 81, 40);
leftBarImage = [[UIImageView alloc] initWithFrame:leftBarImageRect];
[leftBarImage setImage:[UIImage imageNamed:@"leftBar.png"]];
leftBarImage.opaque = YES; // explicitly opaque for performance
[self.view addSubview:leftBarImage];
[leftBarImage release];
***}

testBarAnimation {*** 
 // Setup the animation
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2]; //animation for arrow
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationBeginsFromCurrentState:YES];

CGRect newFrame = CGRectMake(550, 300, 81, 290);

leftBarImage.frame = newFrame;


[UIView commitAnimations];
***}

thanks a lot! 非常感谢!

I dont know, it's applicable to your project. 我不知道,它适用于您的项目。 But I used different approach, as iOS doesn't have good libraries for Chart. 但是我使用了不同的方法,因为iOS没有适合Chart的好库。

I used UIWebview with HTML5 /CSS based free chart engines available on Web. 我使用UIWebview与Web上提供的基于HTML5 / CSS的免费图表引擎。 For me its working fine, Bit slow than native charts would be but enough for my project 对我来说它的工作正常,比本机图表慢一点对我的项目来说足够了

Define a utility function: 定义效用函数:

CGRect modifyRectByHeight(CGRect originalRect, CGFloat newHeight)
{
    CGRect result = originalRect;

    result.origin.y += height;
    result.size.height += height;

    return result;
}

Then use as follows: 然后使用如下:

leftBarImage.frame = modifyRectByHeight( leftBarImage.frame, 150);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM