My radar's tooltips is show "labels" but I want radar's tooltips show "data"
I refer to the method of chart.js official website but still can't display it correctly
My Radar chart
Chart.js official website Radar chart
My code version
"dependencies": {
"chart.js": "^2.9.3",
"chartkick": "^3.2.0",
"core-js": "^3.3.2",
"hchs-vue-charts": "^1.2.8",
"vue": "^2.6.10",
"vue-chartjs": "^3.5.0",
"vue-chartkick": "^0.6.0",
"vue-router": "^3.1.3",
"vuetify": "^2.1.0"
}
My code
<script>
import { Radar } from "vue-chartjs";
export default {
extends: Radar,
data() {
return {
datacollection: {
labels: [
"Eating","Drinking","Sleeping","Designing","Coding","Cycling","Running"
],
datasets: [
{
label: "My First Dataset",
backgroundColor: "rgba(179,181,198,0.2)",
borderColor: "rgba(179,181,198,1)",
pointBackgroundColor: "rgba(179,181,198,1)",
pointBorderColor: "#fff",
pointHoverBackgroundColor: "#fff",
pointHoverBorderColor: "rgba(179,181,198,1)",
data: [65, 59, 90, 81, 56, 55, 40]
},
{
label: "My Second Dataset",
backgroundColor: "rgba(255,99,132,0.2)",
borderColor: "rgba(255,99,132,1)",
pointBackgroundColor: "rgba(255,99,132,1)",
pointBorderColor: "#fff",
pointHoverBackgroundColor: "#fff",
pointHoverBorderColor: "rgba(255,99,132,1)",
data: [28, 48, 40, 19, 96, 27, 100]
}]},
options: {
scale: {
angleLines: {
display: false
},
ticks: {
suggestedMin: 50,
suggestedMax: 100
}}}};},
mounted() {
this.renderChart(this.datacollection, this.options);
}};
</script>
You can add the tooltips option with a callback function that returns the title as follows:
"options": {
...
"tooltips": {
"callbacks": {
"title": (tooltipItem, data) => data.labels[tooltipItem[0].index]
}
}
}
Please have a look at the following JavaScript code snippet. Adding the tooltips option to your existing Vue.js code should work the same.
new Chart(document.getElementById("myChart"), {
"type": "radar",
"data": {
"labels": ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
"datasets": [{
"label": "My First Dataset",
"data": [65, 59, 90, 81, 56, 55, 40],
"fill": true,
"backgroundColor": "rgba(255, 99, 132, 0.2)",
"borderColor": "rgb(255, 99, 132)",
"pointBackgroundColor": "rgb(255, 99, 132)",
"pointBorderColor": "#fff",
"pointHoverBackgroundColor": "#fff",
"pointHoverBorderColor": "rgb(255, 99, 132)"
}, {
"label": "My Second Dataset",
"data": [28, 48, 40, 19, 96, 27, 100],
"fill": true,
"backgroundColor": "rgba(54, 162, 235, 0.2)",
"borderColor": "rgb(54, 162, 235)",
"pointBackgroundColor": "rgb(54, 162, 235)",
"pointBorderColor": "#fff",
"pointHoverBackgroundColor": "#fff",
"pointHoverBorderColor": "rgb(54, 162, 235)"
}]
},
"options": {
"elements": {
"line": {
"tension": 0,
"borderWidth": 3
}
},
"tooltips": {
"callbacks": {
"title": (tooltipItem, data) => data.labels[tooltipItem[0].index]
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="myChart"></canvas>
Related
I receive through api one json with this structure. And I want to display the objects as follows. But I do not know in map array by react native how to get in objects and sub-objects.
import React from 'react'
import { View, Text } from 'react-native'
const Categoris = () => {
const terms = ` [
{
"term_id": 15,
"name": "Uncategorized",
"children": [
]
},
{
"term_id": 21,
"name": "Clothing",
"children": [
{
"term_id": 24,
"name": "Accessories",
"children": [
{
"term_id": 24,
"name": "Accessories",
"children": [
]
},
{
"term_id": 23,
"name": "Hoodies",
"children": [
]
},
{
"term_id": 22,
"name": "Tshirts",
"children": [
]
}
]
},
{
"term_id": 23,
"name": "Hoodies",
"children": [
]
},
{
"term_id": 22,
"name": "Tshirts",
"children": [
]
}
]
},
{
"term_id": 26,
"name": "Decor",
"children": [
]
},
{
"term_id": 25,
"name": "Music",
"children": [
]
}
]`
function recursive(arrayJson, level=0)
{
let childrenComp = null
if(arrayJson.children)
childrenComp = recursive(arrayJson.children, level++)
return <>
<Text>{level > 0 && "-".repeat(level)}{arrayJson.name}</Text>
{childrenComp}
</>
}
const components = recursive(terms)
return (
<View>{components}</View>
)
}
export default Categoris
And I want to show it this way:
Uncategorized
Clothing
-Accessories
--Bike
--Engine
---Bench
--Airplane
Hoodies
Tshirts
But not show anything!!!
Result:
Uncategorized
Clothing
-Accessories
--Accessories
--Hoodies
--Tshirts
-Hoodies
-Tshirts
Decor
Music
import { StatusBar } from "expo-status-bar";
import React, { ReactNode } from "react";
import { StyleSheet, Text, View } from "react-native";
export default function App() {
const recursive = (data: Item[], level = 0): ReactNode => {
return data.map((item) =>
item.children?.length ? (
<>
{renderItem(level, item.name)}
{recursive(item.children, level + 1)}
</>
) : (
renderItem(level, item.name)
)
);
};
const renderItem = (level: number, name: string) => (
<Text style={styles.item}>
{level > 0 && "-".repeat(level)}
{name}
</Text>
);
return (
<View style={styles.container}>
{recursive(terms)}
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
item: {
alignSelf: "flex-start",
},
container: {
flex: 1,
backgroundColor: "#fff",
padding: 50,
},
});
interface Item {
term_id: number;
name: string;
children?: Item[];
}
const terms: Item[] = [
{
term_id: 15,
name: "Uncategorized",
children: [],
},
{
term_id: 21,
name: "Clothing",
children: [
{
term_id: 24,
name: "Accessories",
children: [
{
term_id: 24,
name: "Accessories",
children: [],
},
{
term_id: 23,
name: "Hoodies",
children: [],
},
{
term_id: 22,
name: "Tshirts",
children: [],
},
],
},
{
term_id: 23,
name: "Hoodies",
children: [],
},
{
term_id: 22,
name: "Tshirts",
children: [],
},
],
},
{
term_id: 26,
name: "Decor",
children: [],
},
{
term_id: 25,
name: "Music",
children: [],
},
];
Enjoy!
I have created a sample code for you. you just need to add your React native UI Tags, function remains same
import React from 'react';
export default function Cate() {
let data = JSON.parse(terms);
console.log(data, 'data is the ');
const getCate = (data = []) => {
return data.map((item) => (
<div>
<h3>{item.name}</h3>
<div style={{ marginLeft: 20 }}> {item.children &&
getCate(item.children)}</div>
</div>
));
};
return (
<div>
<h1>Testing</h1>
{getCate(data)}
</div>
);
}
const terms = ` [
{
"term_id": 15,
"name": "Uncategorized",
"children": [
]
},
{
"term_id": 21,
"name": "Clothing",
"children": [
{
"term_id": 24,
"name": "Accessories",
"children": [
{
"term_id": 24,
"name": "Accessories",
"children": [
]
},
{
"term_id": 23,
"name": "Hoodies",
"children": [
]
},
{
"term_id": 22,
"name": "Tshirts",
"children": [
]
}
]
},
{
"term_id": 23,
"name": "Hoodies",
"children": [
]
},
{
"term_id": 22,
"name": "Tshirts",
"children": [
]
}
]
},
{
"term_id": 26,
"name": "Decor",
"children": [
]
},
{
"term_id": 25,
"name": "Music",
"children": [
]
}
]`;
I try to position 2 vertical lines which are my thresholds for list of results for some tests.
My problem is that when I try to take value which is not part of the results, The lines are not shown.
With the following code I see the lines.
<script>
import BarChart from "#/components/TestsStatictics/BarChart.vue";
export default {
components: {
BarChart,
},
data() {
return {
chartData: {
labels: [24.35, 24, 24.2, 24.28],
datasets: [
{
label: "Bar Chart",
backgroundColor: [
"rgba(255, 99, 132, 0.2)",
"rgba(54, 162, 235, 0.2)",
"rgba(255, 206, 86, 0.2)",
"rgba(75, 192, 192, 0.2)",
"rgba(75, 192, 192, 0.2)",
],
borderColor: [
"rgba(255,99,132,1)",
"rgba(54, 162, 235, 1)",
"rgba(255, 206, 86, 1)",
"rgba(75, 192, 192, 1)",
"rgba(75, 192, 192, 0.2)",
],
pointBorderColor: "#2554FF",
data: [24.35, 24, 24.2, 24.28],
},
],
},
options: {
annotation: {
annotations: [
{
type: "line",
mode: "vertical",
scaleID: "x-axis-0",
value: 24.35,
borderColor: "green",
borderWidth: 1,
label: {
enabled: true,
position: "center",
content: "22.70",
},
},
{
type: "line",
mode: "vertical",
scaleID: "x-axis-0",
value: 24.28,
borderColor: "green",
borderWidth: 1,
label: {
enabled: true,
position: "center",
content: "25.70",
},
},
],
},
scales: {
yAxes: [
{
ticks: {
beginAtZero: true,
},
gridLines: {
display: true,
},
},
],
xAxes: [
{
gridLines: {
display: false,
},
barThickness: 30,
},
],
},
legend: {
display: true,
},
responsive: true,
maintainAspectRatio: false,
},
};
},
};
</script>
but if I change the part of the annotation to this (the value of the annotation is not within the data and labels values), It doesn`t work:
annotations: [
{
type: "line",
mode: "vertical",
scaleID: "x-axis-0",
value: 22,
borderColor: "green",
borderWidth: 1,
label: {
enabled: true,
position: "center",
content: "22",
},
},
{
type: "line",
mode: "vertical",
scaleID: "x-axis-0",
value: 26,
borderColor: "green",
borderWidth: 1,
label: {
enabled: true,
position: "center",
content: "26",
},
},
],
Try setting max an min values for the axes:
suggestedMax, suggestedMin
scales: {
xAxes: [
{
gridLines: {
display: false,
},
ticks: {
suggestedMax: 35,
suggestedMin: 20
},
barThickness: 30,
},
],
I have a Highcharts bar graph. Each point has a group of results, however the first and last element are being cropped. How can I extend the x-axis so every bar is shown?
In the image below each group has the same results so you can see the N and P are dropped from the first group and S and Mg from the last grouping.
The data is coming from a database, so i don't know how many groups there will be, or what range (so simply adding a day to each end is not sufficient, the overlap could be larger or smaller)
const conf = {
chart: {
type: "column",
animation: false,
marginRight: 10,
dateFormat: "dd/mm/YYYY"
},
title: {
text: "Spread Events"
},
xAxis: {
type: "datetime",
tickPixelInterval: 50
},
yAxis: {
title: {
text: "Spread"
},
plotLines: [
{
value: 0,
width: 1,
color: "#808080"
}
]
},
legend: {
enabled: true
},
exporting: {
enabled: false
},
plotOptions: {
column: {
pointPadding: 0.2,
borderWidth: 0
}
},
series: this.state.graphData
};
and this is the graphData from the example
[
{
"name": "N",
"data": [[1559669642443, 300], [1559343600000, 300], [1559257200000, 300]]
},
{
"name": "P",
"data": [[1559669642443, 160], [1559343600000, 160], [1559257200000, 160]]
},
{
"name": "K",
"data": [[1559669642443, 470], [1559343600000, 470], [1559257200000, 470]]
},
{
"name": "S",
"data": [[1559669642443, 120], [1559343600000, 120], [1559257200000, 120]]
},
{
"name": "Mg",
"data": [[1559669642443, 90], [1559343600000, 90], [1559257200000, 90]]
}
]
You have Highcharts error #15 in a console, which means that your data is not sorted. Highcharts requires sorted data in ascending X order:
series: [{
...,
data: [
[1559257200000, 300],
[1559343600000, 300],
[1559669642443, 300]
]
}, ...
]
Live demo: http://jsfiddle.net/BlackLabel/y2rzd65m/
I'm trying to adapt particles.js to a Vue.js component from the example below:
https://codepen.io/MichaelVanDenBerg/pen/WpXGRm
However, when using the code below, I get the following error message in the console:
[Vue warn]: Error in mounted hook: "TypeError: this.particles is not a
function"
How can I fix it in the code below?
Template:
</template>
<div>
<div id="particles-js"></div>
</div>
</template>
Script:
<script>
import particles from 'particles.js'
export default {
mounted() {
this.initParticles()
},
methods: {
initParticles () {
particles("particles-js", {
"particles": {
"number": {
"value": 80,
"density": {
"enable": true,
"value_area": 700
}
},
"color": {
"value": "#ffffff"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#000000"
},
"polygon": {
"nb_sides": 5
},
},
"opacity": {
"value": 0.5,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 3,
"random": true,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 150,
"color": "#ffffff",
"opacity": 0.4,
"width": 1
},
"move": {
"enable": true,
"speed": 6,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"bounce": false,
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": true,
"mode": "grab"
},
"onclick": {
"enable": true,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 140,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
})
}
}
}
</script>
CSS:
<style scoped>
#particles-js {
position: absolute;
width: 100%;
height: 100%;
background: #00356B;
}
</style>
The particles.js package does not export anything, but rather it sets window.particlesJS.
To use this package, simply import it in your script, and then invoke particlesJS():
import 'particles.js'
export default {
// ...
methods: {
initParticles() {
window.particlesJS('particles-js', {/* ... */})
}
}
}
demo
How to perform clustering in React Native Mapbox with custom icons.
i have checked the earthquake clustering example given on GitHub page of mapbox react native. but i need something different like, i need to do clustering with custom icons. i have 2 types of data/points on map one is user and other is events both have different icons so i need to render those custom icons in clustering.
also on tap of that icon i need to show a pulse animation behind that icon. any possible way to do this?
here is my code for implementing mapbox :-
<MapboxGL.MapView
ref={(ref) => this.map = ref}
showUserLocation={store.homeStore.locationAlowed}
zoomLevel={11}
pitch={45}
centerCoordinate={[store.userStore.longitude, store.userStore.latitude]}
userTrackingMode={MapboxGL.UserTrackingModes.follow}
styleURL={MapboxGL.StyleURL.Street}
style={{
position: store.homeStore.mapPosition,
top: 0,
left: 0,
right: 0,
bottom: 0,
}}
logoEnabled={false}
compassEnabled={false}
attributionEnabled={false}
onDidFinishRenderingMapFully={() => this.map.takeSnap(true).then((resp) => {
if (resp) {
store.homeStore.mapImageSource = resp;
}
})}
onPress={this.onMapPress.bind(this)}>
{store.homeStore.setLocationOnMap && store.homeStore.eventData.length > 0 ?
store.homeStore.eventData.map((prop, key) => {
return (
<MapboxGL.PointAnnotation
key={prop.id}
id={prop.id}
coordinate={[parseFloat(prop.evt_longitude), parseFloat(prop.evt_latitude)]} >
<TouchableOpacity onPress={this.selectEventOnMap.bind(this, prop)} style={{ height: vh * 0.109 }}>
<View style={styles.likesContainer}>
<Image source={require('../Images/ic_home_event_likes.png')}
style={[styles.heartImage, prop.event_likes > 999 ? { marginLeft: vw * 0.018 } :
prop.event_likes > 9 ? { marginLeft: vw * 0.036 } : { marginLeft: vw * 0.049 }]} />
<Text style={[styles.likesText, prop.event_likes < 10 ? { marginLeft: 2 } : '']}>
{prop.event_likes > 999 ? (Math.round(prop.event_likes / 1000) + " k") : prop.event_likes}</Text>
</View>
<Image source={require('../Images/ic_home_inactive_event_pin.png')}
style={{
height: vh * 0.098, width: vw * 0.15, marginTop: vh * 0.017,
tintColor: (prop.userid == store.userStore.id ? Colors.Blue : Colors.warmPink)
}} />
<Image source={this.getImageSource(prop.evt_category)}
style={{
height: vh * 0.041, width: vw * 0.077,
top: vh * 0.035, left: vw * 0.038, position: 'absolute'
}} />
{prop.selected && <Pulse style={{ zIndex: -1, position: 'absolute', top: -((vh * 0.109) / 3) }}
color={Colors.warmPink} numPulses={6} diameter={100} speed={18} duration={1000} />}
</TouchableOpacity>
</MapboxGL.PointAnnotation>
);
}) : null}
{store.homeStore.setLocationOnMap && store.homeStore.peopleData.length > 0 ?
store.homeStore.peopleData.map((prop, key) => {
return (
<MapboxGL.PointAnnotation
key={prop.userid}
id={prop.userid}
coordinate={[parseFloat(prop.longitude), parseFloat(prop.latitude)]} >
<TouchableOpacity onPress={() => { store.homeStore.showProfileCard = true; store.homeStore.userData = prop; }}>
<View style={{
height: vw * 0.130, width: vw * 0.130, borderRadius: (vw * 0.130) / 2,
backgroundColor: Colors.Blue, alignItems: 'center', justifyContent: 'center'
}}>
<AsyncImage source={{ uri: prop.image }}
style={{
height: vw * 0.122, width: vw * 0.122, borderRadius: (vw * 0.122) / 2
}} placeholderColor='#b3e5fc' />
</View>
</TouchableOpacity>
</MapboxGL.PointAnnotation>
);
}) : null}
{this.renderRoute()}
{/* <MapboxGL.ShapeSource
id='earthquakes'
cluster
clusterRadius={50}
clusterMaxZoom={14}
url='http://moso.appinventive.com/public/accesscsv/data.json'>
<MapboxGL.SymbolLayer
id='pointCount'
style={layerStyles.clusterCount} />
<MapboxGL.CircleLayer
id='singlePoint'
filter={['!has', 'point_count']}
style={layerStyles.singlePoint} />
</MapboxGL.ShapeSource> */}
{/* <MapboxGL.ShapeSource
id='talesMarkers'
shape={jsonData}
cluster
clusterRadius={50}
clusterMaxZoom={14}
>
<MapboxGL.SymbolLayer key='{id}' id='{id}' style={styles.icon} />
</MapboxGL.ShapeSource> */}
</MapboxGL.MapView>
and here is the json data :-
const jsonData = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"id": "27",
"evt_name": "nh24 event",
"evt_latitude": "28.624134137261",
"evt_longitude": "77.399671500871",
"evt_start": "1520855452",
"evt_category": "1",
"event_address": "Pusta Road, Bahrampur, Noida, Uttar Pradesh 203207, India",
"evt_createdon": "1520855452",
"userid": "23",
"image": "https://appinventiv-development.s3.amazonaws.com/moso%2FnCA3HzIs7OsAVLYVJ6Db",
"event_likes": "0",
"event_followers": "0",
"distance": "2.6069925023499723",
"view": false,
"event_growth": 0,
"owner_popularity": 0,
"viral": 0,
"icon": 'airport-15'
},
"geometry": {
"type": "Point",
"coordinates": [
77.399671500871,
28.624134137261,
6.55
]
},
"id": "27"
},
{
"type": "Feature",
"properties": {
"id": "26",
"evt_name": "event with exact address",
"evt_latitude": "28.611121352303",
"evt_longitude": "77.385811577333",
"evt_start": "1520839916",
"evt_category": "1",
"event_address": "Sector 65, Noida, Uttar Pradesh 201301, India",
"evt_createdon": "1520839916",
"userid": "23",
"image": "https://appinventiv-development.s3.amazonaws.com/moso%2FnCA3HzIs7OsAVLYVJ6Db",
"event_likes": "0",
"event_followers": "0",
"distance": "1.489932977056515",
"view": false,
"event_growth": 0,
"owner_popularity": 0,
"viral": 0,
"icon": 'airport-15'
},
"geometry": {
"type": "Point",
"coordinates": [
77.385811577333,
28.611121352303,
1.67
]
},
"id": "26"
},
{
"type": "Feature",
"properties": {
"userid": "13",
"name": "",
"username": "howdy",
"latitude": 28.577006492753625,
"longitude": 77.32924537095796,
"facebookprof": "",
"instaprof": "",
"image": "https://appinventiv-development.s3.amazonaws.com/moso%2FchMzFARwXj2z1y3MYASk",
"createdon": "1519757532",
"user_bio": "",
"user_likes": "1",
"user_followers": "1",
"distance": "0.021139920338468652",
"liked": false,
"follows": false,
"view": false,
"live_events": "0",
"user_growth": 1.3149888133309905e-9,
"user_popularity": 0.00046882325363338024,
"viral": 1.1720601065666707e-8,
"icon": 'airport-15'
},
"geometry": {
"type": "Point",
"coordinates": [
77.32924537095796,
28.577006492753625,
77.7
]
},
"id": "13"
},
{
"type": "Feature",
"properties": {
"userid": "20",
"name": null,
"username": "otheruser",
"latitude": 28.606038365831,
"longitude": 77.362243836846,
"facebookprof": "",
"instaprof": "",
"image": "https://scontent.xx.fbcdn.net/v/t1.0-1/c59.0.200.200/p200x200/10354686_10150004552801856_220367501106153455_n.jpg?oh=f621f9474a63f5b27b0514adda5db42b&oe=5B0F8625",
"createdon": "1519776475",
"user_bio": "",
"user_likes": "1",
"user_followers": "1",
"distance": "0.019360181909683884",
"liked": false,
"follows": false,
"view": false,
"live_events": "0",
"user_growth": 1.3149888133309905e-9,
"user_popularity": 0.0000017414245723714283,
"viral": 4.35553391414857e-11,
"icon": 'airport-15'
},
"geometry": {
"type": "Point",
"coordinates": [
77.362243836846,
28.606038365831,
1.6
]
},
"id": "20"
},
{
"type": "Feature",
"properties": {
"userid": "23",
"name": "vijay",
"username": "vijaysharma",
"latitude": 28.577006492753625,
"longitude": 77.32924537095796,
"facebookprof": "https://www.gmail.com",
"instaprof": "https://www.gmail.com",
"image": "https://appinventiv-development.s3.amazonaws.com/moso%2FnCA3HzIs7OsAVLYVJ6Db",
"createdon": "1520588433",
"user_bio": "Usheiwhwosbwowgwiwgwowwjai9a7292ue8rgdidbdidhndjdjdjdjsksoa9wub3829283yehs8dyv3i38sieh3i39w83hejwuhe",
"user_likes": "0",
"user_followers": "0",
"distance": "0.021139920338468652",
"liked": false,
"follows": false,
"view": false,
"live_events": "0",
"user_growth": 0,
"user_popularity": 0,
"viral": 0,
"icon": 'airport-15'
},
"geometry": {
"type": "Point",
"coordinates": [
77.32924537095796,
28.577006492753625,
44.5
]
},
"id": "23"
}
]
}
with pointAnnotations i am able to show points on map but this way clustering is not performed on mapbox. and if i try to make points on map from clustering using shapesource layer and json data then i am not getting how to use my custom icons. also i need to fire a click event on tap of that custom pin and show pulse loading animation behind that point.
please take a look at screenshots also what i need to do with clustering.
screenshots shown only point annotations with which clustering is not happening.
mapbox point annotations without clustering