Related
I try to make the pie chart show 'customized label',change label when the mouse triggered. But except blue data everything else will overlap with 'emphasis label'.
'avoidLabelOverlap' not working.
Is there way?
enter image description here
enter image description here
this is a example
var option = {
tooltip: {
trigger: 'item'
},
legend: {
top: '5%',
left: 'center'
},
series: [
{
name: 'Access From',
type: 'pie',
radius: ['40%', '70%'],
avoidLabelOverlap: false,
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2
},
label: {
show: true,
position: 'center',
formatter: function (params) {
var html = 'TEST';
return html;
}
},
emphasis: {
label: {
show: true,
fontSize: '40',
fontWeight: 'bold'
}
},
labelLine: {
show: false
},
data: [
{ value: 1048, name: 'Search Engine' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 484, name: 'Union Ads' },
{ value: 300, name: 'Video Ads' }
]
}
]
};
Finally,I find a method.
Use mouse event to change label in center.
<!DOCTYPE html>
<html lang="Zh-TW">
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.2.2/echarts.min.js"></script>
<meta charset="utf-8">
</head>
<body>
<div id="main" style="width:600px;height:600px;">
</div>
<script>
var myChart = echarts.init(document.getElementById('main'));
var option = {
title: {
text: 'Total',
textStyle: {
fontSize: 35,
},
x: 'center',
y: 'center'
},
tooltip: {
trigger: 'item'
},
legend: {
top: '5%',
left: 'center'
},
series: [
{
name: 'Testname',
type: 'pie',
radius: ['40%', '60%'],
center: ['50%', '50%'],
avoidLabelOverlap: true,
textAlign: 'center',
label: {
normal: {
show: true,
formatter: function (params) {
return params.name+'\n'+params.percent+'%'
},
textStyle: {
fontSize: 20
},
},
},
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2
},
data: [
{ value: 1048, name: 'Search Engine' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 484, name: 'Union Ads' },
{ value: 300, name: 'Video Ads' }
]
},
{
name: 'Testname',
type: 'pie',
radius: ['40%', '60%'],
center: ['50%', '50%'],
avoidLabelOverlap: true,
textAlign:'center',
label: {
normal: {
show: true,
position: 'center',
formatter: '{b}\n{c}',
align: 'center',
verticalAlign: 'middle',
textStyle: {
fontSize: 0
},
},
emphasis:{
show: true,
textStyle: {
fontSize: 35,
fontWeight: 'bold'
},
formatter: '{b}\n{c}'
},
},
itemStyle: {
borderRadius: 10,
borderColor: '#fff',
borderWidth: 2
},
data: [
{ value: 1048, name: 'Search Engine' },
{ value: 735, name: 'Direct' },
{ value: 580, name: 'Email' },
{ value: 484, name: 'Union Ads' },
{ value: 300, name: 'Video Ads' }
]
},
]
};
myChart.setOption(option);
myChart.on('mouseover', { seriesName: 'Testname' }, () => {
myChart.setOption({
title: {
show: false
}
})
})
myChart.on('mouseout', { seriesName: 'Testname' }, () => {
myChart.setOption({
title: {
show: true
}
})
})
</script>
</body>
</html>
Thanks for the accepted answer,
My case was series label was showing like you mentioned in question, and my need was to solve the same problem while hovering the mouse through legend.
Here is my addition.
// series name: Access From
labelOptionAlter = {
series: [
{ label: {
show: false,
position: 'center'
},
}
]
};
labelOptionDefault={
series: [
{ label: {
show: true,
position: 'center'
},
}
]
};
//similar to mouseover.
myChart.on('highlight', { seriesName: 'Access From' }, () => {
myChart.setOption(labelOptionAlter)
})
//similar to mouseout
myChart.on('downplay', { seriesName: 'Access From' }, () => {
myChart.setOption(labelOptionDefault)
})
Future scholars can read more here
I think there's no way to solve this problem.
I am currently updating ConsoleTvs / Charts 6 to 7. The chart is rendering with expected data.
The chart is not rendering according to any of the set options object keys for legend point style circle, padding top 50, display 'y' & 'x' axis labelString, not display gridlines, positioning datalabels at end with start offset in bold and green :
const chart = new Chartisan({
el: '#test_chart',
url: "#chart('test_chart_route')",
hooks: new ChartisanHooks()
.colors()
.datasets(
[
{ type: 'line', fill: false, borderColor: '#329865', backgroundColor: '#329865' },
{ type: 'line', fill: false, borderColor: '#1e5b3c', backgroundColor: '#1e5b3c' },
{ type: 'line', fill: false, borderColor: '#0f2d1e', backgroundColor: '#0f2d1e' },
{ type: 'line', fill: false, borderColor: '#329865', backgroundColor: '#329865' },
{ type: 'line', fill: false, borderColor: '#1e5b3c', backgroundColor: '#1e5b3c' },
{ type: 'line', fill: false, borderColor: '#0f2d1e', backgroundColor: '#0f2d1e' },
{ type: 'line', fill: false, borderColor: '#800000', backgroundColor: '#800000' },
{ type: 'line', fill: false, borderColor: '#F70000', backgroundColor: '#F70000' },
{ type: 'line', fill: false, borderColor: '#FF6F6F', backgroundColor: '#FF6F6F' },
{ type: 'line', fill: false, borderColor: '#800000', backgroundColor: '#800000' },
{ type: 'line', fill: false, borderColor: '#F70000', backgroundColor: '#F70000' },
{ type: 'line', fill: false, borderColor: '#FF6F6F', backgroundColor: '#FF6F6F' },
]
),
options: {
layout: {
padding: {
left: 0,
right: 0,
top: 50,
bottom: 0
},
},
aspectRatio: 1,
maintainAspectRatio: false,
responsive: true,
legend: {
display: true,
position: 'top',
labels: {
usePointStyle: true,
fontSize: 12,
},
},
elements: {
point: {
pointStyle: 'circle',
}
},
scales: {
xAxes: [{
maxBarThickness: 120,
scaleLabel: {
display: true,
labelString: "xAxes_label"
},
gridLines: {
display: false
},
ticks: {
fontSize: 10,
maxRotation: 80,
minRotation: 80,
padding: 2
},
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: "yAxes_label"
},
gridLines: {
display: false,
drawBorder: false
},
ticks: {
display: true,
fontSize: 10,
suggestedMin: 0
},
}],
},
plugins: {
datalabels: {
color: '#ff0a6c',
labels: {
title: {
font: {
weight: 'bold',
size: 11,
}
},
value: {
color: 'green'
}
},
formatter: function(value, context) {
return (value != '' && value !== undefined) ? Math.round(value * 100) / 100 : value;
},
anchor: 'end',
align: 'start',
display: 'auto',
clamp: false
}
}
}
});
I have also tried using the ChartisanHooks().options({...options...}) method with no change in set options.
Can anyone please show me in the right direction?
Instead of using the options hook, you defined options as a property. You should use .options({ ... }) but not options: { ... }.
The options hook however doesn't work for me, maybe I use an outdated Chartisan library. According to Custom Hooks, you can also merge the options to the chart as follows:
.custom(function({ data, merge }) {
return merge(data, {
options: {
...
}
}),
})
Please take a look at your amended and runnable code below and see how it works with the merge function.
const chart = new Chartisan({
el: '#test_chart',
data: {
"chart": {
"labels": ["First", "Second", "Third"]
},
"datasets": [{
"name": "Sample 1",
"values": [10, 3, 7]
},
{
"name": "Sample 2",
"values": [1, 6, 2]
}
]
},
hooks: new ChartisanHooks()
.colors()
.datasets(
[{
type: 'line',
fill: false,
borderColor: '#329865',
backgroundColor: '#329865'
},
{
type: 'line',
fill: false,
borderColor: '#1e5b3c',
backgroundColor: '#1e5b3c'
}
]
)
.custom(function({ data, merge }) {
return merge(data, {
options: {
layout: {
padding: {
left: 0,
right: 0,
top: 50,
bottom: 0
},
},
aspectRatio: 1,
maintainAspectRatio: false,
responsive: true,
legend: {
display: true,
position: 'top',
labels: {
usePointStyle: true,
fontSize: 12,
},
},
elements: {
point: {
pointStyle: 'circle',
}
},
scales: {
xAxes: [{
maxBarThickness: 120,
scaleLabel: {
display: true,
labelString: "xAxes_label"
},
gridLines: {
display: false
},
ticks: {
fontSize: 10,
maxRotation: 80,
minRotation: 80,
padding: 2
},
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: "yAxes_label"
},
gridLines: {
display: false,
drawBorder: false
},
ticks: {
display: true,
fontSize: 10,
suggestedMin: 0
},
}],
},
plugins: {
datalabels: {
color: '#ff0a6c',
labels: {
title: {
font: {
weight: 'bold',
size: 11,
}
},
value: {
color: 'green'
}
},
formatter: function(value, context) {
return (value != '' && value !== undefined) ? Math.round(value * 100) / 100 : value;
},
anchor: 'end',
align: 'start',
display: 'auto',
clamp: false
}
}
}
});
}),
});
<script src="https://unpkg.com/chart.js#2.9.4/dist/Chart.min.js"></script>
<script src="https://unpkg.com/#chartisan/chartjs#^2.1.0/dist/chartisan_chartjs.umd.js"></script>
<div id="test_chart" style="height: 300px;"></div>
The ECharts provide stack option to stack multiple area/line charts together.
https://echarts.apache.org/en/option.html#series-line.stack
I have three charts that look like this:
To achieve it you can paste the following code here: https://echarts.apache.org/examples/en/editor.html?c=area-stack
option = {
title: {
text: 'Double stack',
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985',
},
},
},
legend: {
data: ['stack 1', 'stack 2', 'basis'],
},
toolbox: {
feature: {
saveAsImage: {},
},
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true,
},
xAxis: [
{
type: 'category',
boundaryGap: false,
data: ['0', '1', '2', '3', '4', '5', '6'],
},
],
yAxis: [
{
type: 'value',
},
],
series: [
{
name: 'stack 1',
type: 'line',
areaStyle: {
color: 'red',
},
data: [140, 150, 160, 180, 160, 240, 160],
},
{
name: 'stack 2',
type: 'line',
areaStyle: {
color: 'green',
},
data: [120, 140, 130, 150, 120, 160, 125],
},
{
name: 'basis',
type: 'line',
areaStyle: {
color: 'blue',
},
data: [100, 110, 120, 130, 90, 130, 120],
},
],
};
However I would like to stack both the green and the red charts on the blue one to get something like this:
I can add the values of the blue one to both other charts and get the result and get the following options:
option = {
title: {
text: 'Double stack',
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985',
},
},
},
legend: {
data: ['stack 1', 'stack 2', 'basis'],
},
toolbox: {
feature: {
saveAsImage: {},
},
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true,
},
xAxis: [
{
type: 'category',
boundaryGap: false,
data: ['0', '1', '2', '3', '4', '5', '6'],
},
],
yAxis: [
{
type: 'value',
},
],
series: [
{
name: 'stack 1',
type: 'line',
areaStyle: {
color: 'red',
},
data: [140 + 100, 150 + 110, 160 + 120, 180 + 130, 160 + 90, 240 + 130, 160 + 120],
},
{
name: 'stack 2',
type: 'line',
areaStyle: {
color: 'green',
},
data: [120 + 100, 140 + 110, 130 + 120, 150 + 130, 120 + 90, 160 + 130, 125 + 120],
},
{
name: 'basis',
type: 'line',
areaStyle: {
color: 'blue',
},
data: [100, 110, 120, 130, 90, 130, 120],
},
],
};
but this way I will loose the interactive functionalities of ECharts.
Is there a possible way to do this? To stack the red and the green chart on the blue one but not on each other?
You need to do the same all series' names like this.
series: [
{
name: 'stack',
type: 'line',
areaStyle: {
color: 'red',
},
data: [140, 150, 160, 180, 160, 240, 160],
},
{
name: 'stack',
type: 'line',
areaStyle: {
color: 'green',
},
data: [120, 140, 130, 150, 120, 160, 125],
},
{
name: 'stack',
type: 'line',
areaStyle: {
color: 'blue',
},
data: [100, 110, 120, 130, 90, 130, 120],
},
],
and also, you can modify the tooltip with this
I hope, it will be helpful for you.
I found a simple solution for this by duplicating the basis graph with the very same data and colors, so the user doesn't see two graphs, then stack the red graph on one example of blue, and the green one on the other copy of the blue one like this:
option = {
legend: {
data: ['blue', 'red', 'green'],
},
xAxis: [
{
boundaryGap: false,
data: ['0', '1', '2', '3', '4', '5', '6'],
},
],
yAxis: [
{
type: 'value',
},
],
series: [
{
name: 'blue',
stack: 'stack 1',
type: 'line',
areaStyle: {
color: 'blue',
},
data: [100, 110, 120, 130, 90, 130, 120],
},
{
name: 'blue',
stack: 'stack 2',
type: 'line',
areaStyle: {
color: 'blue',
},
data: [100, 110, 120, 130, 90, 130, 120],
},
{
name: 'red',
stack: 'stack 1',
type: 'line',
areaStyle: {
color: 'red',
},
data: [140, 150, 160, 180, 160, 240, 160],
},
{
name: 'green',
stack: 'stack 2',
type: 'line',
areaStyle: {
color: 'green',
},
data: [120, 140, 130, 150, 120, 160, 125],
},
],
};
This will insure that both copies of the blue graph (standing as basis for both red and green one) will be disabled/enabled together since they have the same name, and each one of the the red and green graphs is stacked on a different blue copy.
When I add a toggle column to a grid with a search it does not appear to function. I have modified the Grid with Search Demo to include a toggle. But when I try to search on it the drop down just gives me an "Is" option and I cannot enter anything for the search clause.
searches: [
{ field: 'recid', caption: 'ID ', type: 'int' },
{ field: 'lname', caption: 'Last Name', type: 'text' },
{ field: 'fname', caption: 'First Name', type: 'text' },
{ field: 'email', caption: 'Email', type: 'list', options: { items: ['peter#gmail.com', 'jim#gmail.com', 'jdoe#gmail.com']} },
{ field: 'auth', caption: 'Auth', type: 'toggle' }
],
columns: [
{ field: 'recid', caption: 'ID', size: '50px', sortable: true, attr: 'align=center' },
{ field: 'lname', caption: 'Last Name', size: '30%', sortable: true },
{ field: 'fname', caption: 'First Name', size: '31%', sortable: true },
{ field: 'email', caption: 'Email', size: '40%' },
{ field: 'auth', caption: 'Auth', render: 'toggle', size: '20px' }
]
jsFiddle: https://jsfiddle.net/c9r6pk7m/4/
While toggle is a valid render value, it's not a valid searches type.
See: http://w2ui.com/web/docs/1.5/w2grid.searches
You could use list instead, though I must admit, I had to "cheat" with the false value, by mapping it to {id:"0", text: "No"}.
$(function () {
$('#grid').w2grid({
name: 'grid',
show: {
toolbar: true,
footer: true
},
multiSearch: true,
searches: [
{ field: 'recid', caption: 'ID ', type: 'int' },
{ field: 'lname', caption: 'Last Name', type: 'text' },
{ field: 'fname', caption: 'First Name', type: 'text' },
{ field: 'email', caption: 'Email', type: 'list', options: { items: ['peter#gmail.com', 'jim#gmail.com', 'jdoe#gmail.com']} },
{ field: 'auth', caption: 'Auth', type: 'list', options: { items: [{id:true, text: "Yes"}, {id:"0", text: "No"}]} }
],
columns: [
{ field: 'recid', caption: 'ID', size: '50px', sortable: true, attr: 'align=center' },
{ field: 'lname', caption: 'Last Name', size: '30%', sortable: true },
{ field: 'fname', caption: 'First Name', size: '31%', sortable: true },
{ field: 'email', caption: 'Email', size: '40%' },
{ field: 'auth', caption: 'Auth', render: 'toggle', size: '20px' }
],
records: [
{ recid: 1, fname: 'Jane', lname: 'Doe', email: 'jdoe#gmail.com', auth: true },
{ recid: 2, fname: 'Stuart', lname: 'Motzart', email: 'jdoe#gmail.com', auth: true },
{ recid: 3, fname: 'Jin', lname: 'Franson', email: 'peter#gmail.com', auth: true },
{ recid: 4, fname: 'Susan', lname: 'Ottie', email: 'jim#gmail.com', auth: true },
{ recid: 5, fname: 'Kelly', lname: 'Silver', email: 'peter#gmail.com', auth: true },
{ recid: 6, fname: 'Francis', lname: 'Gatos', email: 'jdoe#gmail.com', auth: true },
{ recid: 7, fname: 'Mark', lname: 'Welldo', email: 'jim#gmail.com', auth: false },
{ recid: 8, fname: 'Thomas', lname: 'Bahh', email: 'jdoe#gmail.com', auth: false },
{ recid: 9, fname: 'Sergei', lname: 'Rachmaninov', email: 'jdoe#gmail.com', auth: false },
{ recid: 20, fname: 'Jill', lname: 'Doe', email: 'jdoe#gmail.com', auth: false },
{ recid: 21, fname: 'Frank', lname: 'Motzart', email: 'jdoe#gmail.com', auth: false },
{ recid: 22, fname: 'Peter', lname: 'Franson', email: 'jdoe#gmail.com', auth: false },
{ recid: 23, fname: 'Andrew', lname: 'Ottie', email: 'jdoe#gmail.com', auth: false },
{ recid: 24, fname: 'Manny', lname: 'Silver', email: 'jdoe#gmail.com', auth: false },
{ recid: 25, fname: 'Ben', lname: 'Gatos', email: 'peter#gmail.com', auth: true },
{ recid: 26, fname: 'Doer', lname: 'Welldo', email: 'jdoe#gmail.com', auth: true },
{ recid: 27, fname: 'Shashi', lname: 'Bahh', email: 'jim#gmail.com', auth: true },
{ recid: 28, fname: 'Av', lname: 'Rachmaninov', email: 'jim#gmail.com', auth: true }
]
});
});
https://jsfiddle.net/c9r6pk7m/9/
I have a gridpanel with two column, first column show username, second column is a actioncolumn with edit button, when click edit button, change the user password by show a window with form and input new password.
How to pass the "username" to the form and show.
I'm trying to use Store.
Is there any other way?
my code
gridpanelview.js
actioncolumn:
/*...config*/
{
xtype: 'actioncolumn',
items: [
{
handler:function(view, rowIndex, colIndex, item, e, record, row) {
var pwdwin = Ext.create('myapp.view.SetPwdWin');
var store = Ext.create(myapp.store.mystore)
mysore.setData(record)
pwdwin.show();
},
icon: 'edit.png',
tooltip: 'change passpword'
}]
}
mywindow.js:
/*...config*/
dockedItems: [
{
xtype: 'form',
dock: 'top',
reference: 'form',
height: 200,
id: 'pwd_form',
bodyPadding: 10,
header: false,
title: 'My Form',
layout: {
type: 'vbox',
align: 'center'
},
items: [
{
xtype: 'textfield',
flex: 1,
id: 'user_name',
maxHeight: 20,
padding: 10,
fieldLabel: 'Name',
editable: false
},
{
xtype: 'textfield',
id: 'new_pwd',
padding: 10,
fieldLabel: 'Password',
inputId: 'new_pwd_value',
inputType: 'password',
allowBlank: false,
maxLength: 20,
minLength: 6
},
{
xtype: 'textfield',
id: 'confirm_pwd',
fieldLabel: 'confirm',
inputId: 'confirm_pwd_value',
inputType: 'password',
allowBlank: false,
maxLength: 20,
minLength: 6
},
{
xtype: 'button',
text: 'OK',
listeners: {
click: 'set_new_pwd'
}
}
]
}
],
set_form_username: function() {
//get Store data
form = this.getReferences().form.getForm();
//how to set username to the label
}
set_new_pwd: function(button, e, eOpts) {
//send username and new username to server
}
Try using getDockingRefItems('pwd_form') or getDockedItems()
For example:
Ext.application({
name: 'Fiddle',
launch: function() {
Ext.create('Ext.Button', {
text: 'Click me',
renderTo: Ext.getBody(),
handler: function() {
// way 1
w.getDockedItems()[0].items.items[0].setValue('your user name');
// way2
w.getDockingRefItems('pwd_form')[1].setValue('your user name');
w.show();
}
});
var w = Ext.create('Ext.window.Window', {
title: 'Hello',
height: 200,
width: 400,
dockedItems: [{
xtype: 'form',
dock: 'top',
reference: 'form',
height: 200,
id: 'pwd_form',
bodyPadding: 10,
header: false,
title: 'My Form',
layout: {
type: 'vbox',
align: 'center'
},
items: [{
xtype: 'textfield',
flex: 1,
id: 'user_name',
maxHeight: 20,
padding: 10,
fieldLabel: 'Name',
editable: false
}, {
xtype: 'textfield',
id: 'new_pwd',
padding: 10,
fieldLabel: 'Password',
inputId: 'new_pwd_value',
inputType: 'password',
allowBlank: false,
maxLength: 20,
minLength: 6
}, {
xtype: 'textfield',
id: 'confirm_pwd',
fieldLabel: 'confirm',
inputId: 'confirm_pwd_value',
inputType: 'password',
allowBlank: false,
maxLength: 20,
minLength: 6
}, {
xtype: 'button',
text: 'OK',
listeners: {
click: 'set_new_pwd'
}
}]
}]
});
}
});