Series in ECharts.js - series

How can I make the label display the value of not only one series, but the entire stack in Echarts.js? How can I make the border line go between each column, not just between columns of different x-axis values? I read the documentation, but did not find a solution to these issues there.
Chart
I wrote such settings in the configuration, but this, of course, is not what you need.
series: [
{
name: 'Matcha',
type: 'bar',
stack: 'drinks',
data: data.filter(item => item.name === 'Matcha').map(item => item.value),
},
{
name: 'Green tea',
type: 'bar',
stack: 'drinks',
data: data.filter(item => item.name === 'Green tea').map(item => item.value),
label: {
show: true,
position: 'top',
fontSize: 14,
fontWeight: 700,
},
},
{
name: 'Apple',
type: 'bar',
stack: 'fruits',
data: data.filter(item => item.name === 'Apple').map(item => item.value),
},
{
name: 'Orange',
type: 'bar',
stack: 'fruits',
data: data.filter(item => item.name === 'Orange').map(item => item.value),
label: {
show: true,
position: 'top',
fontSize: 14,
fontWeight: 700,
},
}
],

Related

React Native state is not getting updated

I want to update state on button click
this.state = {
legend: {
enabled: true,
textSize: 14,
form: 'CIRCLE',
horizontalAlignment: "RIGHT",
verticalAlignment: "CENTER",
orientation: "VERTICAL",
wordWrapEnabled: true
},
data: {
dataSets: [{
values: [{value: 45, label: 'Sandwiches'},
{value: 21, label: 'Salads'},
{value: 15, label: 'Soup'},
{value: 9, label: 'Beverages'},
{value: 15, label: 'Desserts'}],
label: 'Pie dataset',
}],
},
highlights: [{x:2}],
description: {
text: 'This is Pie chart description',
textSize: 14,
textColor: processColor('darkgray'),
}
};
I want to update values array of state by using following code but
it didn't work
const myvalues=this.state.data.dataSets[0].values.map(l => Object.assign({}, l));
myvalues[1].label = 'NEw sandwich';
this.setState({values: myvalues}, () => {
console.log(this.state.data.dataSets[0].values[1].label + " it worksss");
});
I am stuck in this
Check this
const myvalues = [] /*your new array*/
this.setState((state) =>
{
data: {
...state.data,
values: myvalues
}
});

React native: How to make horizontal scroll but data is divided to 4 rows

I need to scroll my items horizontally but my data is divided to 4 rows every row contain 4 items. and I can scroll horizontally so the next 16 item come to the screen.
when using numColumns={4} it works if
horizontal={false}
but with
horizontal={true}
I can't specify numColumns attr.
Should I use SectionList instead of FlatList ?
and how it could be implemented ?
let items = [
{ id: 1, title: '1', price: '20' },
{ id: 2, title: '2', price: '16' },
{ id: 3, title: '3', price: '92' },
{ id: 4, title: '4', price: '93' },
{ id: 5, title: '5', price: '20' },
{ id: 6, title: '6', price: '16' },
{ id: 7, title: '7', price: '92' },
{ id: 8, title: '8', price: '93' },
{ id: 9, title: 'Grilled Steak', price: '20' },
{ id: 10, title: 'Pappas', price: '16' },
{ id: 11, title: 'Ciccione', price: '92' },
{ id: 12, title: 'Gyros Melt', price: '93' },
{ id: 13, title: 'Grilled Steak', price: '20' },
{ id: 14, title: 'Pappas', price: '16' },
{ id: 15, title: 'Ciccione', price: '92' },
{ id: 16, title: 'Gyros Melt', price: '93' },
];
<FlatList
keyExtractor={item => item.id}
data={items}
horizontal
numColumns={4}
renderItem={({ item }) => <Text>{item.title}</Text>}
/>
I have the same issue with same scenario. making group data is quite a bad practice in case you have long array. so I play with styles of flatlist and I was successful. following is my code if you can take advantage out of it:
<ScrollView showsHorizontalScrollIndicator={false} horizontal={true} style={styles.flatListContainer}>
<FlatList
showsHorizontalScrollIndicator={false}
data={item.items}
numColumns={4}
renderItem={_showData}
columnWrapperStyle={styles.flatListColumnWraper}
keyExtractor={(item) => item.key}
style={styles.flatListDataContainer}
scrollEnabled={false}
contentContainerStyle={
styles.flatListContentContainerStyle
}
/>
</ScrollView>
flatListContainer: {
marginTop: height(2),
height:height(60),
paddingVertical:height(2)
},
flatListDataContainer: {
alignSelf: 'center',
},
flatListContentContainerStyle: {
alignSelf: 'center',
flexDirection: 'row',
justifyContent: 'space-evenly',
},
flatListColumnWraper:{
flexDirection: 'column',
},
Unfortunately FlatList doesn't support a number of columns when it is horizontal.
https://facebook.github.io/react-native/docs/flatlist#numcolumns
Multiple columns can only be rendered with horizontal={false} and will
zig-zag like a flexWrap layout. Items should all be the same height -
masonry layouts are not supported.
However, you could group your data so that for every cell in a horizontal FlatList 4 items are rendered.
let items = [
[ { id: 1, title: '1', price: '20' },
{ id: 2, title: '2', price: '16' },
{ id: 3, title: '3', price: '92' },
{ id: 4, title: '4', price: '93' } ],
[ { id: 5, title: '5', price: '20' },
{ id: 6, title: '6', price: '16' },
{ id: 7, title: '7', price: '92' },
{ id: 8, title: '8', price: '93' } ],
[ { id: 9, title: 'Grilled Steak', price: '20' },
{ id: 10, title: 'Pappas', price: '16' },
{ id: 11, title: 'Ciccione', price: '92' },
{ id: 12, title: 'Gyros Melt', price: '93' } ],
[ { id: 13, title: 'Grilled Steak', price: '20' },
{ id: 14, title: 'Pappas', price: '16' },
{ id: 15, title: 'Ciccione', price: '92' },
{ id: 16, title: 'Gyros Melt', price: '93' } ]
];
Then update your renderItem so that it handles the increased input, something like this.
renderItem = ({item}) => {
return item.map(i => <Text>{i.title}</Text>)
}

Setting Colors for Rally Chart with 2.0rc1

I have an app that worked great for 2.0p5. I was able to set the various columns in the chart specific colors. In the chart config, I added
colors: [
'#89A54E',
'#4572A7',
'#AA4643'
],
When I upgraded to 2.0rc1, the colors no longer seem to get set. My chart config is:
Ext.create('Rally.ui.chart.Chart', {
animate: true,
chartData: {
series: [{
type: 'column',
name: 'Data1',
data: data1
},
{
type: 'column',
name: 'Data2',
data: data2
},
{
type: 'column',
name: 'Data3',
data: data3
}],
categories: xAxisData
},
chartConfig: {
chart: {
type: 'column'
},
title: {
text: 'Show Data'
},
yAxis: {
min: 0,
title: {
text: 'yAxis Info'
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: 'gray'
}
}
},
legend: {
align: 'right',
x: -100,
verticalAlign: 'top',
y: 20,
floating: true,
backgroundColor: 'white',
borderColor: '#CCC',
borderWidth: 1,
shadow: false
},
tooltip: {
formatter: function() {
return '<b>'+ this.x +'</b><br/>'+
this.series.name +': '+ this.y +'<br/>'+
'Total: '+ this.point.stackTotal;
}
},
colors: [
'#89A54E',
'#4572A7',
'#AA4643'
],
plotOptions: {
column: {
stacking: 'normal',
dataLabels: {
enabled: true,
color: 'white'
}
}
}
}
});
Any ideas why I lost my color setting capabilities in 2.0rc1?
An example from one of my apps:
var series = [{
name : 'Col 1',
data : [],
showInLegend : false
},{
name : 'Col 2',
data : [],
showInLegend : false
},{
name : 'Col 3',
data : [],
showInLegend : false
}];
Ext.Array.each(records, function(record) {
//HighCharts Data
record.set('name', ...);
record.set('y', ...);
record.set('color', ...);
//Add record to series
series[index].data.push(record.data);
// Add to chartData
});
Hope this helps/works for you!

RallyChart with the type being pie

I am trying to connect a RallyChart using the type specifier set to pie with a Rally.data.custom.Store. When the RallyChart has the type set to column or is blank, the data shows correctly. When the type is set to pie, I get a pie with all 0%s returned.
Here's what my store looks like:
var myStore = Ext.create('Rally.data.custom.Store', {
data: mySeries,
fields: [
{ name: 'WorkItems', type: 'string' },
{ name: 'Count', type: 'int' }
]
});
Here's what my chart configuration function looks like:
_buildChart: function(myStore) {
this.myChart = Ext.create('Rally.ui.chart.Chart', {
height: 400,
store: myStore,
series: [{
type: 'pie',
name: 'Count',
dataIndex: 'Count'
}],
xField: 'WorkItems',
chartConfig: {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Work Breakdown in Selected Sprint'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
}
}
}
}
});
this.add(this.myChart);
}
My data incoming looks like:
['Defects', 4],
['Feature A', 4]
['Feature B', 4]
Any ideas why column charts can show it, but pie cannot?
I bet this is a bug in the 2.0p5 version of the chart. We just released version 2.0rc1 of the SDK which includes a better version of the chart. The following code example shows how to create a pie with your data and Rally.ui.chart.Chart in 2.0rc1:
//from inside your app
this.add({
xtype: 'rallychart',
height: 400,
chartData: {
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Defects', 4], ['Feature A', 4], ['Feature B', 4]
]
}]
},
chartConfig: {
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
xAxis: {},//must specify empty x-axis due to bug
title: {
text: 'Work Breakdown in Selected Sprint'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
}
}
}
}
});
Note it is no longer necessary to create an intermediate store to pass to the chart- you can simply pass in your series as part of the chartData config.

How to change color of bar in column chart in extjs4.1

can anybody tell how to change color of bar in column chart .I have tried with style but its not working
style : {
fill : ['red', 'green'],
width : 30
},
Thanks
Use color renderer function for series onReady method like this on custom example;
Ext.onReady(function () {
var chart = Ext.create('Ext.chart.Chart', {
xtype: 'chart',
animate: true,
style: 'background:#fff',
shadow: false,
store: store1,
axes: [{
type: 'Numeric',
position: 'bottom',
fields: ['data1'],
label: {
renderer: Ext.util.Format.numberRenderer('0,0')
},
title: 'Number of Hits',
minimum: 0
}, {
type: 'Category',
position: 'left',
fields: ['name'],
title: 'Month of the Year'
}],
series: [{
type: 'bar',
axis: 'bottom',
label: {
display: 'insideEnd',
field: 'data1',
renderer: Ext.util.Format.numberRenderer('0'),
orientation: 'horizontal',
color: '#333',
'text-anchor': 'middle',
contrast: true
},
xField: 'name',
yField: ['data1'],
//color renderer
renderer: function(sprite, record, attr, index, store) {
var fieldValue = Math.random() * 20 + 10;
var value = (record.get('data1') >> 0) % 5;
var color = ['rgb(213, 70, 121)',
'rgb(44, 153, 201)',
'rgb(146, 6, 157)',
'rgb(49, 149, 0)',
'rgb(249, 153, 0)'][value];
return Ext.apply(attr, {
fill: color
});
}
}]
});
var win = Ext.create('Ext.Window', {
width: 800,
height: 600,
minHeight: 400,
minWidth: 550,
hidden: false,
maximizable: true,
title: 'Bar Renderer',
renderTo: Ext.getBody(),
layout: 'fit',
tbar: [{
text: 'Save Chart',
handler: function() {
Ext.MessageBox.confirm('Confirm Download', 'Would you like to download the chart as an image?', function(choice){
if(choice == 'yes'){
chart.save({
type: 'image/png'
});
}
});
}
}, {
text: 'Reload Data',
handler: function() {
store1.loadData(generateData());
}
}],
items: chart
});
});
Good Luck!