Brush by default active on scatter chart - echarts

Is there any Option for active brush without showing a toolbox.
Working with Echarts library version 3 . trying to find a solution with Echarts provided Document
"https://ecomfe.github.io/echarts-doc/public/en/option.html#toolbox.feature.brush.icon.rect"
Sample Code
{
brush: {
toolbox: ['rect'],
brushLink: [0, 1, 2, 3],
brushType: 'rect',
brushMode: ['single'],
outOfBrush: {
color: '#abc'
},
brushStyle: {
borderWidth: 2,
color: 'rgba(0,0,0,0.2)',
borderColor: 'rgba(0,0,0,0.5)'
},
throttleDelay: 300
},
toolbox: {
show: false,
feature: {
brush: {
type: ['rect'],
title: {
rect: 'Active Brush'
}
}
}
}
}

To enable dataZoom feature (pragmatically) in echarts toolbar I have used below method
echartInstance._componentsMap[Object.keys(echartInstance._componentsMap)[0]]._features['dataZoom'].model.iconPaths.zoom.trigger('click');
or
echartInstance._componentsMap[' - 0_toolbox']._features['dataZoom'].model.iconPaths.zoom.trigger('click');
Similarly you can enable any echarts toolbar feature using the same mechanism.
Note: If you are using latest EChart then you may have to use _componentsViews instead of _componentsMap.
Thanks to Rob Laverty for updating us for above change.

Just did this to Echarts 5:
echartInstance._componentsViews
.find(c => c._features && c._features.dataZoom)
._features.dataZoom.model.iconPaths.zoom.trigger('click')

Related

How to color individual boxes of an echarts boxplot based on function

How do I color each boxes individually in an echarts box-plot based on a function?
The following function works on a simple bar chart and colors the bars appropriately:
series: [{
data: [120, 200, 150, 80, 70, 110, 130],
type: 'bar',
showBackground: true,
itemStyle: {
color: function(seriesIndex) {
return ProfessionColor[seriesIndex.name.split("_", 1).toString()]
},
},
}]
However, it does not work on a box-plot:
series: [{
name: 'boxplot',
type: 'boxplot',
datasetIndex: 1,
itemStyle: {
color: function(seriesIndex) {
return ProfessionColor[seriesIndex.name.split('_', 1)];
}
},
encode: {
tooltip: [1, 2, 3, 4, 5]
}
},
{
name: 'outlier',
type: 'scatter',
encode: {
x: 1,
y: 0
},
datasetIndex: 2
}
]
If I provide color: "red" rather than a function all boxes are colored red. This leads me to believe that it needs to happen in the transform.config which I can't find in the documents or tutorial.
Echarts Box-Plot currently
The link is the complete charts in its current form.
Apparently, echarts only allows scripting (i.e., using a function for) either the line color -- option itemStyle.borderColor or the fill color -- option itemStyle.color.
The difference between the two appears to be made by the value of the internal property BoxplotSeriesModel#visualDrawType. It is now set to "stroke", which means that borderColor can be set via a function.
Since you wanted to set the fill color, its value should be set to "fill". I searched a way to change that property - it was rather difficult for echarts don't document an API for extensions. Still, navigating the source code I came up with this hacky solution:
const BoxplotSeriesModel = echarts.ComponentModel.getClassesByMainType('series').find(cls=>cls.type==='series.boxplot');
const BoxplotSeriesModelFill = function(...args){
const _this = new BoxplotSeriesModel(...args);
_this.visualDrawType = 'fill';
return _this;
}
BoxplotSeriesModelFill.type = BoxplotSeriesModel.type;
echarts.ComponentModel.registerClass(BoxplotSeriesModelFill);
That's a "patch" to be applied at the beginning of your script, immediately after you have the echarts global defined.
Here's a forked version of your code that uses that patch. The only other change I made was to set a borderColor (can now only be a fixed value) to black.
This will not get you all the way, but if you add colorBy: "data" to your options and remove the itemStyle, it will look like this:

ECharts: Multiple series (lines) with own yAxis

I want to switch from Highcharts to ECharts (preferably 3), but my current graphs have multiple series ('lines' in my case), with each their own yaxis, and it seems ECharts doesn't support this.
These metrics do not relate at all, so they all need their own yaxis. I combine them in 1 chart so they can be compared relative to each other (500 visits, €30000, 3% conversion.. etc). It makes no sense to plot 500 visits and 3% conversion rate on the same yaxis.
Is there a way to give each line it's own yaxis? It doesn't have to be a visible one (since there can only be two with ECharts, left/right of canvas, and that's ok), but the data needs to be plotted to an individual axis.
try this
yAxis: [
{
type: 'value',
name: 'left_yaxis',
nameTextStyle: {
color: '#fff'
},
splitLine:{
show:false,
},
axisLabel: {
textStyle:{
color:'#fff',
}
}
},
{
type: 'value',
name: 'right_yaxis',
nameTextStyle: {
color: '#fff'
},
axisLabel: {
interval:'0',
textStyle:{
color:'#fff',
}
},
splitLine: {
lineStyle: {
color: ['#454545'],
}
},
min:0,
//max:800000,
splitNumber:5
}
],
Here ar example from echarts for dual y axis:
example 1
example 2
You can add more than one y axis in echarts by making yaxis element as a array
Yes, ECharts supports multi-axis. See example at ECharts Gallery.

Google embed api set chart background color

i am trying to edit the background colour of my chart however it isnt working i can only edit the background colour of the full thing not the chart area, my code is below
var sessions = {
query: {
dimensions: 'ga:date',
metrics: 'ga:sessions'
},
chart: {
type: 'LINE',
options: {
width: '100%',
title: 'Sessions',
titleTextStyle: {
color: '#0f55c4',
fontSize: '16',
bold: true
}
}
}
};
I have tried all the following combinations none have worked;
backgroundColor: 'red', (changed background colour not chart colour)
chartArea: {
backgroundColor:'red'
} (again background colour only)
chartArea: {
backgroundColor: {
fill: 'red'
}
} (again background colour only)
chartArea: {
fill: 'red'
} (doesn't work)
Not to sure what else i can try I've tried everything i can find in the documentation and several sites nothing seams to work it just goes onto the whole background not just the chart area, any help is greatly appreciated.
Thanks.
According to the documentation you're able to change the background color and the backgroundcolor of the chartArea.
I'm able to change both of these colors with the following option:
var options = {
backgroundColor: '#ccc',
chartArea: {
backgroundColor:'#e5e5e5'
}
};
Fiddle.
Sadly I'm not familiar with the way you have arranged your options and such, but my guess would be that you should place this option within
options: {
width: '100%',
.....
chartArea: {
backgroundColor:'#e5e5e5'
}
.......
};
I hope this helps you out!

How to change plot value color in highcharts?

I want to change the color of plot numeric values(1000, 2000...9000) as shown in below snapshot. I couldn't find an option to do so in highcharts api.
Whilst your comments are't that clear I believe you want the xAsis lines color changed:
xAxis: {
lineColor: '#FFFFFF'
}
Add the above to the highcharts object: graph.highcharts({});
See here for more details: http://api.highcharts.com/highcharts#xAxis
Edit
In that case you'll still want the xAsis. Thankfully highCharts let us do things as simply as CSS:
xAxis: {
labels: {
style: {
color: '#fff'
}
}

Embed bubble charts on a web site

I'm looking for a way to create what come to know to be called a "bubble chart" for a website I'm building. It needs to be compatible with IE7 and above, and of course all the good browsers like Firefox, Chrome and Safari. And no flash since this thing will need to run on iOS.
The chart needs to look like this, http://www.flickr.com/photos/jgrahamthomas/5591441300/
I've browse online and tried a few things, including:
Google Scatter Charts. This doesn't work as it seems Google Charts limits the size of a point to something smaller than I need. And Venn Diagrams are limited to three circles.
Protovis Dots. Great library, but isn't compatible with IE8.
Raphael Javascript. This one might be my best bet, but there's no explicit support for bubble charts.
Thanks for your help.
It looks like Raphael javascript is the way to go. It's compatible with IE6. I found a great tutorial at http://net.tutsplus.com/tutorials/javascript-ajax/an-introduction-to-the-raphael-js-library/ and am able to get the example working on my rails site with this code:
# window.onload = function() {
# var paper = new Raphael(document.getElementById('canvas_container'), 500, 500);
# var circle = paper.circle(100, 100, 80);
# for(var i = 0; i < 5; i+=1) {
# var multiplier = i*5;
# paper.circle(250 + (2*multiplier), 100 + multiplier, 50 - multiplier)
# }
# var rectangle = paper.rect(200, 200, 250, 100);
# var ellipse = paper.ellipse(200, 400, 100, 50);
# }
You can give Protovis a chance, the library looks good for your needs: http://vis.stanford.edu/protovis/ex/
Another charting library is Highcharts, but I haven't tried it yet: http://www.highcharts.com/
Have you had a look at flot?
It's a plotting library for jQuery. While it technically doesn't have any "native" support for bubble charts it is possible to create bubble charts with it by using a few tricks, the simplest one probably being to simply put each point in its own data series (thus allowing you to control the radius of each individual point.
By defining your points similar to this you'll be able to create a bubble chart:
var dataSet = [{
color:"rgba(0,0,0,0)", // Set the color so it's transparent
shadowSize:0, // No drop shadow effect
data: [[0,1],], // Coordinates of the point, normally you'd have several
// points listed here...
points: {
show:true,
fill:true,
radius: 2, // Here we set the radius of the point (or rather, all points
// in the data series which in this case is just one)
fillColor: "rgba(255,140,0,1)", // Bright orange :D
}
},
/* Insert more points here */
];
There is a bubble chart available for flot here
Note that you need to scale your bubbles size yourself if you don't want them to coverup the graph. Documentation is here.
To use it, add the following at the beggining of your html page:
and call it from a json result or any data object like in this sample:
$.getJSON('myQuery.py?'+params, function(oJson) {
// ... Some validation here to see if the query worked well ...
$.plot('#myContainer',
// ---------- Series ----------
[{
label: 'Line Sample',
data: oJson.lineData,
color: 'rgba(192, 16, 16, .2)',
lines: { show: true },
points: { show: false }
},{
label: 'Bubble Sample',
data: oJson.bubbleData, // arrays of [x,y,size]
color: 'rgba(80, 224, 80, .5)',
lines: { show: false },
points: { show: false },
},{
label: 'Points sample',
data: oJson.pointsData,
color: 'rgba(255, 255, 0, 1)',
lines: { show: false },
points: { show: true, fillColor: 'rgba(255, 255, 0, .8)' }
},{
...other series
}],
// ---------- Options ----------
{ legend: {
show: true,
labelBoxBorderColor: 'rgba(32, 32, 32, .2)',
noColumns: 6,
position: "se",
backgroundColor: 'rgba(224, 224, 224, .2)',
backgroundOpacity: .2,
sorted: false
},
series: {
bubbles: { active: true, show: true, fill: true, linewidth: 2 }
},
grid: { hoverable: true, clickable: true } },
xaxis: { tickLength: 0 }
}); // End of plot call
// ...
}); // End of getJSON call
I tried to do the same thing with jqPlot which has some advantages but doesn't work with bubbles and other kind of series on the same graph. Also Flot does a better job to synchronise common axis scale with many series. Highchart does a really good job here (mixing bubble chart with other kind of series) but isn't free for us (government context).