I want to remove 1/5 and show all legends in google pie chart - legend

Here i have total 10 legends, but i want to show all 10 legends.

As WhiteHat mentions in his comment, you have to move the legend.position to the top and increase the maxLines.
But additionally, you have to add the top property to the chartArea, to get enough space at the top of the chart.
{
width: '100%',
height: '100%',
legend: {
position: 'top', // <--- top position
alignment: 'center',
maxLines: 5 // <--- increase of max lines
},
chartArea: {
height: "100%",
width: "100%",
top: "25%" // <-- top space (you can use fix values as well. (e.x. 50))
},
sliceVisibilityThreshold: 0,
pieHole: 0.4,
}

Related

Different height of maximum and minimum track using react-native-slider

At this moment the library https://www.npmjs.com/package/#miblanchard/react-native-slider does not have a solution to be able to change the height of the left and right track of the thumb.
How to implement it?
I found a workaround:
The container in which the Slider is should have overflow style: "hidden"
I use renderThumbComponent to display the thumb left line to the left
renderThumbComponent={() => (
<>
<View style={styles.thickerLine} />
<View style={styles.thumb} />
</>
)}
I set the style for thickerLine to be as long as possible, so that it goes beyond the container.
thickerLine: {
position: "absolute",
top: 8,
right: 0,
backgroundColor: "blue",
height: 4,
width: window.width,
},
Yes, I know it's wild, but it works!

FlatList is not scrolling or scrollable with multiple items

I am using FlatList for list of video tiles but somehow it is not scrollable can someone please give an input what is wrong in here ?
const TileList = styled(FlatList)({ overflow: 'hidden' }, variant({
prop: 'orientation',
variants: {
vertical: {
height: '100%',
width: '100%',
flexGrow: 0,
maxHeight: '40%',
},
horizontal: {
width: 250,
//height: '100%',
maxWidth: 250,
flex: 0,
}
}
}));
<TileList
testID="teams-other-list"
data={remainingTiles}
renderItem={renderItem}
contentContainerStyle={containerStyle}
horizontal={isHorizontal}
inverted
orientation={orientation}
initialScrollIndex={0}
/>
It's not scrollable because of overflow 'hidden' style option. It hides everything outside the component's frame. Remove it and the scroll will appear
If you want to use initialScrollIndex prop, getItemLayout prop is required. Or the flatlist is not scrolled.
Check this out:
https://reactnative.dev/docs/flatlist#getitemlayout
https://reactnative.dev/docs/flatlist#initialscrollindex

How can I make an inward rounded corned on only 1 corner? I have two rectangles on my screen and I want them to have a corner as shown in the picture

Trying to make rounded corner go inward to create a semi-circle illusion on the rectangular shape.
leftContainer: {
width:'50%',
height: Dimensions.get('window').height,
flex: 1,
},
rightContainer: {
width:'50%',
height: Dimensions.get('window').height,
flex: 1,
You can achieve this with 3rd View. Position it absolute and give it border radius of '50%'.

Creating CSS circles in react-native

I'm having some trouble creating CSS circles in react-native. The following works in iPhone 6 Plus but in all the other iPhones, they become diamonds.
circle: {
height: 30,
width: 30,
borderRadius: 30,
}
Now if I use PixelRatio on borderRadius it works in everything but iPhone 6 plus. iPhone 6 plus renders it as boxes with rounded corners.
circle: {
height: 30,
width: 30,
borderRadius: 30 / PixelRatio.get(),
}
Your border radius should be a half of width and your height. like below:
circle: {
width: 44,
height: 44,
borderRadius: 44/2
}
None of these fit my needs, if you need a responsive circle you can try using my solution:
Step 1: Import Dimensions (and other used elements) from react native (or add to existing imports list)
import { Dimensions, TouchableHighlight, Text } from 'react-native';
Step 2: Add your touchable element (you can calculate width or height of a device)
<TouchableHighlight
style = {{
borderRadius: Math.round(Dimensions.get('window').width + Dimensions.get('window').height) / 2,
width: Dimensions.get('window').width * 0.5,
height: Dimensions.get('window').width * 0.5,
backgroundColor:'#f00',
justifyContent: 'center',
alignItems: 'center'
}}
underlayColor = '#ccc'
onPress = { () => alert('Yaay!') }
>
<Text> Mom, look, I am a circle! </Text>
</TouchableHighlight>
Step 3: Enjoy your responsive circled element
borderRadius should be half the side of the square. So 15 in your case - no matter what pixel ratio the device has.
It works with 30 / PixelRatio.get() only for 2x retina devices, cause the result is 15.
Then for iPhone 6 Plus, you indeed get a rounded box because the result is 10 (pixel ratio is 3).
I'm surprised your saying it worked on iPhone 6 Plus with 30 for a 30x30 square.
If you want to make a circle that will work on any device the only thing that you should do is to give the same height and width the same value and then give the borderRadius a really high value I personally give it 1000 so it will big enough for most of the cases
circle :{
height : 30 ,
width :30,
borderRadius: 1000,
}
Since borderRadius style expects number as a value you can't use borderRadius: 50%. To make circle all you have to do is use your image width/height and devide it with 2. Read more here:
https://github.com/refinery29/react-native-cheat-sheet
Basically just need to apply same height, width and in borderRadius have to divided by 2
E.g. height : 50, width :50 borderRadius : 50/2
Just Circle
var circle = {
height: 30,
width: 30,
borderRadius: 15
}
Responsive Circle with Device Height
var circle = {
height: Dimensions.get('window').height * 0.1,
width: Dimensions.get('window').height * 0.1,
borderRadius: Math.round((Dimensions.get('window').height + Dimensions.get('window').width) / 2)
}
Responsive Circle with Device Width
var circle = {
height: Dimensions.get('window').width * 0.1,
width: Dimensions.get('window').width * 0.1,
borderRadius: Math.round((Dimensions.get('window').height + Dimensions.get('window').width) / 2)
}
Example Code
import React, { useEffect, useState, useRef } from 'react'
import { Dimensions, SafeAreaView, StyleSheet, Text, View } from 'react-native'
const { height, width } = Dimensions.get('window')
function roundOff(v) {
return Math.round(v)
}
function dimensions() {
var _borderRadius = roundOff((height + width) / 2),
_height = roundOff(height),
_width = roundOff(width)
return { _borderRadius, _height, _width }
}
export default function ResponsiveCircle() {
return (
<SafeAreaView style={styles.container}>
<View style={styles.circleView}>
<Text style={styles.text}>
Responsive{'\n'}Circle
</Text>
</View>
</SafeAreaView>
)
}
const commonStyles = { alignItems: 'center', justifyContent: 'center', }
const styles = StyleSheet.create({
container: { flex: 1, ...commonStyles },
circleView: { height: dimensions()._height * 0.2, width: dimensions()._height * 0.2, borderRadius: dimensions()._borderRadius, backgroundColor: 'tan', ...commonStyles },
text: { textAlign: 'center', lineHeight: 25, color: 'black', fontWeight: 'bold' }
})
I've been using the styled-components package to style my React Native components and the easiest solution I've found is to set the border radius to a size in px larger than half of the width that the circle will ever have. It'll then default to the equivalent of a 50% border-radius for any size smaller than that.
onLayout worked for me.
Calculate width and height to maintain 1:1 aspect ratio, then set borderRadius to width/2
const [circleSytle, setCircleStytle] = useState();
...
function calCircleStyle(layoutEvent) {
let {width, height} = layoutEvent.nativeEvent.layout;
let dim = width > height ? width : height;
setCircleStyle({width:dim, height:dim, borderRadius:dim/2});
}
Then apply it to your view like this:
<View onLayout={calCircleStyle} style={circleStyle}>
...
</View>
Btw, can anyone explain why borderRadius:1000 is bad?

Issue with label alignment in titanium alloy

I have created custom check boxes in my application. I have no issue with check box and it's label if the label text is small. If the label text is large (more than a one line) the alignment is not showing properly.
Look at the above screenshot: the first option label text is "Please select the 2 primary reasons rating the program testing the program" and second option label text is "Question2". If the text in first label is small that is which fits in one line then the UI looks good. But If text is more than one line I am facing the above issue.
My code is as follows,
View:
<Label class="standardType1">Please select the 2 primary reasons rating the program?</Label>
<View class="checkBoxContainerView">
<Widget id="box1" src="checkbox" value="true"/>
<Label class="question1">Please select the 2 primary reasons rating the program testing the program</Label>
</View>
<View class="checkBoxContainerView">
<Widget id="box2" src="checkbox" value="true"/>
<Label class="question1">Question2</Label>
</View>
Style:
"#box1":
{
height: Ti.UI.SIZE,
width: Ti.UI.SIZE,
left:10
}
"#box2":
{
height: Ti.UI.SIZE,
width: Ti.UI.SIZE,
left:10
}
".question1":
{
top: 3,
left: 13,
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
color: '#fff',
font:{
fontSize: 16,
fontWeight: 'normal'
}
}
".checkBoxContainerView":
{
left: 15,
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
layout: 'horizontal'
}
Can any one help me with that? Even if label text is more than one line the height of the view should automatically increase and option should be view. Please help me.
After thinking a lot about your problem I experimented a little bit. I did not use the checkBox but tried to receive a proper alignment if the label is a multi-line label.
Xml:
<View id="temp" layout="horizontal" top="0" left="0">
<Label id="headline"/>
<Label id="description"/>
</View>
And my .tss:
"#headline": {
top: "0",
left: "0",
width: "50%",
text: "Headline",
font: {
fontSize: 20
}
}
"#description": {
left: "0",
width: "50%",
text: "Your long text here",
font: {
fontSize: 16
}
}
As you can see I did not specify any height or width for my container (not defined in the .tss but in the xml) and only set a width parameter for my labels. You should consider to use 10-20% for your checkBoxes and the rest for your label. Do not specify any height parameters since the system will do this automatically.