Echarts - Rotated X-Axis labels overlap the graph itself - echarts

I am using Apache Echarts 5.2.2 and I am struggling with rotated x-axis labels. With large font sizes like 30, 40, they overlap the graph as you can see in the image below
Here the config
option = {
grid: {
left: '10%',
right: '10%',
bottom: '15%'
},
xAxis: {
type: 'category',
data: [
"Arta",
"Chahar Mahal va Bakhtiari",
"Drenthe",
"Gamprin",
"Kabale",
"Lvivska oblast",
"Tebessa",
"Wangdue Phodrang",
"Zagorje ob Savi",
"Zeeland"
],
axisLabel: {
fontSize: 40,
rotate: -45,
overflow: 'truncate',
width: 100,
}
},
yAxis: {
type: 'value',
name: 'km/s minus 299,000',
},
};
Anyone knows the solution or what I am doing wrong?

Related

Rotate chart title in Echarts?

In Apache Echarts, is there a way to rotate the title text of a chart so that it is vertically oriented on one side rather than horizontal on the top? The title at the top sometimes takes important chart real-estate that my series in some cases can overlap. I would like to instruct Echarts when there's a space crunch to move the title off to the left side in a vertical position (like reading titles on the spines of books in a library). There appears to be several "rotate" options for labels, but nothing for titles.
I am not sure you can rotate the main title if you use the default canvas renderer. In this case, you may want to play with the name of your yAxis like this:
const myChart = echarts.init(document.getElementById('main'));
let option = {
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value',
name: 'This is my title',
nameLocation: 'center',
nameRotate: 90,
nameGap: 45,
nameTextStyle: {
color: 'black',
fontSize: 18,
fontWeight: 'bold'
}
},
series: [
{
data: [150, 230, 224, 218, 135, 147, 260],
type: 'line'
}
]
};
myChart.setOption(option);
#main {
width: 100%;
height: 350px;
}
<script src="https://cdn.jsdelivr.net/npm/echarts#5.4.1/dist/echarts.min.js"></script>
<div id="main"></div>
Alternatively, you could use the SVG renderer and add a bit of CSS to transform the main title (which is a <text> element):
const myChart = echarts.init(document.getElementById('main'), null, { renderer: 'svg' });
let option = {
title: {
text: 'This is my title'
},
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
data: [150, 230, 224, 218, 135, 147, 260],
type: 'line'
}
]
};
myChart.setOption(option);
#main {
width: 100%;
height: 350px;
}
svg g text:last-child {
transform: rotate(-90deg) translateX(-250px);
}
<script src="https://cdn.jsdelivr.net/npm/echarts#5.4.1/dist/echarts.min.js"></script>
<div id="main"></div>

(ApexCharts) How can I make the pie chart the same size?

My Problem : Chart size is fixed including legends.
I want to fixed pie chart size except legends.
How can I make the pie chart the same size?
This is my code.
Help me plz
var options = {
series: [25, 15, 44],
chart: {
type: 'pie',
**width: '300px'**
},
labels: ["Monday", "Tuesday", "Wednesday"],
theme: {
monochrome: {
enabled: true,
color: '#f38200',
shadeIntensity: 0.9
}
},
plotOptions: {
pie: {
size : "200px"
}
},
stroke: {
show: false
},
dataLabels: {
enabled: false
},
legend: {
position: 'bottom',
horizontalAlign: 'left',
markers: {
width: 9, height: 9
},
itemMargin: {
horizontal: 20, vertical: 0
},
formatter: function(seriesName, opts) {
~~~~~~~
return legend;
}
}
};
IMG - This is my problem
Try setting the legend width or height to a static value, e.g.
legend: {
width: 200
}
Try using -
legend: {
floating: true
}
and setting the legend's position using offsets.

ECharts Baidu how to display labels in negative value as positive value?

I am using ECharts Baidu to generate charts. I am using a tornado chart to display the force of left and right arm. The force of the left arm is displayed at the left side and right arm at the right side. Is there a way display the negative value of the label and the axis as positive? I can always hide the axis value so as long as the solution can make the graph to display negative as positive label, I will mark it as solution.
https://echarts.baidu.com/echarts2/doc/example/bar5.html#-en
var option= {
title: {
},
grid: {
top: '10%',
bottom: '25%',
left: '20%',
right: '10%',
},
tooltip: { triggerOn: 'click' },
xAxis: [
{
type: 'value',
name: 'Newton',
nameLocation: 'center',
nameTextStyle: {
padding: 10
},
}
],
yAxis: [
{
axisTick: { show: false },
data: ['FEB']
}
],
barWidth: 40,
series: [
{
type: 'bar',
stack: 'feb',
label: {
normal: {
show: true,
position: 'top',
}
},
data: [{ value: Number(data2[0].left) * -1 }], //the value is from the ajax call
itemStyle: { color: 'gray' }
},
{
type: 'bar',
stack: 'feb',
label: {
normal: {
show: true,
position: 'top'
}
},
data: [Number(data2[0].right)],
itemStyle: { color: '#F26718' },
},
],
textStyle: {
fontWeight: 'bold',
color: 'black'
}
}
chart.setOption(option);
})
try with this:
label: {
normal: {
show: true,
position: 'top',
formatter: function (params) {
return Math.abs(params.value[1]);
}
}
}
this example assumes that the data you passed to the chart is an array like [x, y]. if your input data is different, put a breakpoint inside the formatter function e see how "params" is structured.

Highchart multi Yaxis in one line

I want to create chart like that in highcharts:
IOT Central Chart
this is what i get until now:
Highcharts.setOptions({
colors: ['#3399CF', '#F9BA06', '#65AF35', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4']
});
// Get the data. The contents of the data file can be viewed at
$.getJSON(
'https://cdn.rawgit.com/highcharts/highcharts/057b672172ccc6c08fe7dbb27fc17ebca3f5b770/samples/data/activity.json',
function (activity) {
$.each(activity.datasets, function (i, dataset) {
// Add X values
dataset.data = Highcharts.map(dataset.data.splice(1, 10), function (val, j) {
return [activity.xData[j], val];
});
$('<div class="chart">')
.appendTo('#container')
.highcharts({
chart: {
type: "spline",
marginLeft: 40, // Keep all charts left aligned
marginTop: 7,
marginBottom: 7
},
title: {
text: null,
},
credits: {
enabled: false
},
legend: {
enabled: false
},
xAxis: {
visible: false,
labels: {
format: '{value} km'
}
},
yAxis: {
visible: true,
title: {
text: null
},
tickAmount: 2,
minPadding: 0,
lineWidth:1,
gridLineColor: "transparent"
},
series: [{
data: dataset.data,
name: dataset.name,
color: Highcharts.getOptions().colors[i],
fillOpacity: 0.3,
tooltip: {
valueSuffix: ' ' + dataset.unit
}
}]
});
});
}
);
.chart {
min-width: 320px;
max-width: 800px;
height: 150px;
margin: 0 auto;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container"></div>
but the problem is that i cant export or zoom do normal legend to this chart.
The problem here is that you create three separate charts instead of one.
Highstock allows you to position and resize axes (height & top properties):
yAxis: [{
height: '50%'
}, {
top: '50%',
height: '50%'
}],
API references:
https://api.highcharts.com/highstock/yAxis.height
https://api.highcharts.com/highstock/yAxis.top
In fact it's going to work in Highcharts too (even though it's not documented).
Live demo: http://jsfiddle.net/BlackLabel/gb3jhq75/

ExtJS 4.0.7 Ext.Draw drag and resize

I add Ext.draw.Component inside grid cell as column renderer:
renderer: function(_value){
var id = Ext.id();
Ext.Function.defer(function(){
Ext.create('Ext.draw.Component', {
minWidth: width,
id: 'timer-' + id,
width: (_value * width),
style: {
position: 'absolute',
'z-index': '10000000',
},
height: 17,
renderTo: id,
resizable: {
dynamic: true,
pinned: true,
handles: 'w e',
widthIncrement: width,
},
gradients: [{
id: 'grad1',
angle: 270,
stops: {
0: {
color: '#6594cf'
},
1: {
color: '#c6d8ed'
},
99: {
color: '#5f96db'
},
100: {
color: '#6594cf'
}
}
}],
items: [{
type: 'rect',
fill: 'url(#grad1)',
width: '100%',
height: '100%',
x: 0,
y: 0
}],
draggable: {
constrain: false,
},
listeners: {
}
});
}, 25);
return '<div id="' + id + '" style="width:1000px;" class="timers" />';
}
I need to know, how to drag this draw component only by x-axis. And I need name of listeners, whitch called on drag and on resize.
There is listner resize, but funciton return only new width and height (or I dont know some thing), I need to know, to whitch resizable handle was user pooled - left or right?