Related
I don't know how to convert the unit of the cirle radius, now it's meters but I need to convert it into pixel.
I also want to know how to make the border of the circle become dashed border, like the picture (the circle with the white dashed border)
Here is the code.
const map_data = [];
const current_map_data = [];
this.current_map = this.$echarts.init(document.getElementById('map_id'));
this.$echarts.registerMap('my_map', map_data);
const typhoon_points = [
{name: 0, value: [124.36, 23, 6]},
{name: 1, value: [122, 23.8, 6]},
{name: 2, value: [120, 24.4, 6]},
{name: 3, value: [118.5, 24.8, 6]},
{name: 4, value: [117.2, 25.5, 6]}
];
const typhoon_lines = [
{"point": [0, 1], "coords": [[124.36,23], [122, 23.8]]},
{"point": [1, 2], "coords": [[122, 23.8], [120, 24.4]]},
{"point": [2, 3], "coords": [[120, 24.4], [118.5, 24.8]]},
{"point": [3, 4], "coords": [[118.5, 24.8], [117.2,25.5]]},
];
const option = {
geo: [{
map: map_name,
roam: 'move',
boundingCoords:[ [118, 26.5], [122.4,21.5] ],
center: center,
layoutCenter: ['50%', '50%'],
aspectScale: 1,
scaleLimit: { min: 1.6, max: 12.0 },
left: '0%',
zoom: zoom,
itemStyle: {
areaColor: 'none',
borderColor : '#999',
borderWidth: 1,
emphasis: {
areaColor: 'inherit',
},
},
}],
series: [{
selectedMode: false,
name: 'current_map',
type: 'map',
geoIndex: 0,
data: current_map_data,
zlevel: 3
}, {
name: "",
type: "lines",
zlevel: 6,
lineStyle: {
type: 'solid',
width: 1,
opacity: 1,
curveness: 0,
orient: 'horizontal',
color: "#000",
},
data: typhoon_lines,
}, {
name: '',
type: 'scatter',
coordinateSystem: 'geo',
color: ['#000'],
itemStyle: {
borderType: 'dashed', // it's not working
borderWidth: 50, // The unit of the symbol size is pixel, I need to convert it into pixel.
borderColor: 'green',
color: '#000',
},
data: typhoon_points,
}],
};
I created a line & circle layer into series, but I don't know how to change the border style and the unit of the symbol size (I think it's the radius of the circle)
Is there anywhere to make linear gradient on full date/year
https://jsfiddle.net/0712nw3g/64/
for example if i move/scroll the graph in 3 month zoom, color gradient should be the same as 1year/all
series: [{
type: 'line',
name: 'Volume',
id: 'stock',
data: volume,
yAxis: 0,
dataGrouping: {
units: groupingUnits
},
lineWidth: 10,
color: {
linearGradient: [0, 0, this.plotWidth, 0],
stops: [
[0, '#26A69A'],
[1, '#CE1510']
]
},
}
]
You can set the options xAxis.events.afterSetExtremes to modify the color gradient in the graph but the color in the navigator also changes.
https://jsfiddle.net/BlackLabel/j3ca7oyh/
Highcharts.getJSON('https://demo-live-data.highcharts.com/aapl-c.json', function(data) {
Highcharts.stockChart('container', {
xAxis: {
events: {
afterSetExtremes: function() {
const dataRange = this.dataMax - this.dataMin,
currentRange = this.max - this.min
this.series[0].update({
color: {
linearGradient: [0, 0, this.plotWidth, 0],
stops: [
[1 - currentRange / dataRange, 'blue'],
[1, 'yellow']
]
},
})
}
}
},
series: [{
name: 'AAPL',
data: data,
color: {
linearGradient: [0, 0, this.plotWidth, 0],
stops: [
[0, 'blue'],
[1, 'yellow']
]
},
}]
});
});
Another way will be adding a series inside the navigator and trying to calculate gradient color.
https://jsfiddle.net/BlackLabel/qLp61uft/
Highcharts.getJSON('https://demo-live-data.highcharts.com/aapl-c.json', function(data) {
Highcharts.stockChart('container', {
xAxis: {
events: {
afterSetExtremes: function() {
const dataRange = this.dataMax - this.dataMin,
currentRange = this.max - this.min
this.series[0].update({
color: {
linearGradient: [0, 0, this.plotWidth, 0],
stops: [
[0, 'red'],
[1, 'yellow']
]
},
})
}
}
},
navigator: {
series: {
name: 'AAPL',
data: data,
fillColor: {
linearGradient: [0, 0, this.plotWidth, 0],
stops: [
[0, 'blue'],
[1, 'yellow']
]
},
}
},
series: [{
name: 'AAPL',
data: data,
color: {
linearGradient: [0, 0, this.plotWidth, 0],
stops: [
[0, 'blue'],
[1, 'yellow']
]
},
}]
});
});
What I really want is a combo chart where right axis and left axis have the same viewWindowMax which is the one that will let all the data in the chart.
For this, I try to get the highest of the 2 and set both of them to that max.
batchUpdate of a chart in google sheets requires to update the whole chart["spec"] with updateChartSpec. I have test cases where I set viewWindowMax to a hardcoded arbitrary number. It updates properly the left axis, but the left axis goes back to a default condition with an empty viewWindowOptions even if it did have some other value before the update. IE I get this result with no error message:
{'position': 'LEFT_AXIS', 'viewWindowOptions': {'viewWindowMin': 0, 'viewWindowMax': 40, 'viewWindowMode': 'PRETTY'}}, {'position': 'RIGHT_AXIS', 'viewWindowOptions': {}}
when in the request it was like so:
{'position': 'LEFT_AXIS', 'viewWindowOptions': {'viewWindowMin': 0, 'viewWindowMax': 40, 'viewWindowMode': 'PRETTY'}}, {'position': 'RIGHT_AXIS', 'viewWindowOptions': {'viewWindowMin': 0, 'viewWindowMax': 40}}
removing the 'PRETTY' thing or adding it changes nothing.
Full request code looks like this:
requests = [
{
"updateChartSpec": {
"chartId": chart['chartId'],
"spec": spec
}
}
]
body = {
'requests': requests
}
response = build('sheets', 'v4', credentials=creds.credentials).spreadsheets().batchUpdate(
spreadsheetId=spreadsheet_id, body=body).execute()
with spec variable =
{'title': 'Tickets Opened and Closed', 'basicChart': {'chartType': 'COMBO', 'legendPosition': 'BOTTOM_LEGEND', 'axis': [{'position': 'BOTTOM_AXIS', 'viewWindowOptions': {}}, {'position': 'LEFT_AXIS', 'viewWindowOptions': {'viewWindowMin': 0, 'viewWindowMax': 40, 'viewWindowMode': 'PRETTY'}}, {'position': 'RIGHT_AXIS', 'viewWindowOptions': {'viewWindowMin': 0, 'viewWindowMax': 40}}], 'domains': [{'domain': {'sourceRange': {'sources': [{'sheetId': 1666134379, 'startRowIndex': 0, 'endRowIndex': 14, 'startColumnIndex': 0, 'endColumnIndex': 1}]}}}], 'series': [{'series': {'sourceRange': {'sources': [{'sheetId': 1666134379, 'startRowIndex': 0, 'endRowIndex': 14, 'startColumnIndex': 1, 'endColumnIndex': 2}]}}, 'targetAxis': 'LEFT_AXIS', 'type': 'COLUMN', 'color': {'red': 1}, 'colorStyle': {'rgbColor': {'red': 1}}}, {'series': {'sourceRange': {'sources': [{'sheetId': 1666134379, 'startRowIndex': 0, 'endRowIndex': 14, 'startColumnIndex': 2, 'endColumnIndex': 3}]}}, 'targetAxis': 'LEFT_AXIS', 'type': 'COLUMN', 'color': {'red': 1, 'green': 0.42745098, 'blue': 0.003921569}, 'colorStyle': {'themeColor': 'ACCENT5'}}, {'series': {'sourceRange': {'sources': [{'sheetId': 1666134379, 'startRowIndex': 0, 'endRowIndex': 14, 'startColumnIndex': 3, 'endColumnIndex': 4}]}}, 'targetAxis': 'LEFT_AXIS', 'type': 'COLUMN', 'color': {'red': 0.9764706, 'green': 0.79607844, 'blue': 0.6117647}, 'colorStyle': {'rgbColor': {'red': 0.9764706, 'green': 0.79607844, 'blue': 0.6117647}}}, {'series': {'sourceRange': {'sources': [{'sheetId': 1666134379, 'startRowIndex': 0, 'endRowIndex': 14, 'startColumnIndex': 4, 'endColumnIndex': 5}]}}, 'targetAxis': 'LEFT_AXIS', 'type': 'COLUMN'}, {'series': {'sourceRange': {'sources': [{'sheetId': 1666134379, 'startRowIndex': 0, 'endRowIndex': 14, 'startColumnIndex': 5, 'endColumnIndex': 6}]}}, 'targetAxis': 'RIGHT_AXIS', 'type': 'COLUMN', 'color': {'red': 1}, 'colorStyle': {'rgbColor': {'red': 1}}}, {'series': {'sourceRange': {'sources': [{'sheetId': 1666134379, 'startRowIndex': 0, 'endRowIndex': 14, 'startColumnIndex': 6, 'endColumnIndex': 7}]}}, 'targetAxis': 'RIGHT_AXIS', 'type': 'COLUMN', 'color': {'red': 1, 'green': 0.42745098, 'blue': 0.003921569}, 'colorStyle': {'themeColor': 'ACCENT5'}}, {'series': {'sourceRange': {'sources': [{'sheetId': 1666134379, 'startRowIndex': 0, 'endRowIndex': 14, 'startColumnIndex': 7, 'endColumnIndex': 8}]}}, 'targetAxis': 'RIGHT_AXIS', 'type': 'COLUMN', 'color': {'red': 0.9764706, 'green': 0.79607844, 'blue': 0.6117647}, 'colorStyle': {'rgbColor': {'red': 0.9764706, 'green': 0.79607844, 'blue': 0.6117647}}}, {'series': {'sourceRange': {'sources': [{'sheetId': 1666134379, 'startRowIndex': 0, 'endRowIndex': 14, 'startColumnIndex': 8, 'endColumnIndex': 9}]}}, 'targetAxis': 'RIGHT_AXIS', 'type': 'COLUMN', 'color': {'red': 0.20392157, 'green': 0.65882355, 'blue': 0.3254902}, 'colorStyle': {'themeColor': 'ACCENT4'}}, {'series': {'sourceRange': {'sources': [{'sheetId': 1666134379, 'startRowIndex': 0, 'endRowIndex': 14, 'startColumnIndex': 9, 'endColumnIndex': 10}]}}, 'targetAxis': 'LEFT_AXIS', 'type': 'LINE', 'color': {}, 'colorStyle': {'themeColor': 'TEXT'}}], 'headerCount': 1, 'stackedType': 'STACKED'}, 'hiddenDimensionStrategy': 'SKIP_HIDDEN_ROWS_AND_COLUMNS', 'titleTextFormat': {'fontFamily': 'Roboto'}, 'fontName': 'Roboto'}
I took the liberty to report this behavior here: https://issuetracker.google.com/151918491
Ive got some chart code whereas I add a MouseIndicator to a line chart. I want the text on the MouseIndicator to be HTML and I am not sure if this is possible since it is not working. Ive added a labelFunc to return the HTML I want, but it only ever shows up as plain text.
Ive got the code on JSFiddle (and below) so you can try it out.
Any help is appreciated.
require(["dojox/charting/Chart",
"dojox/charting/action2d/Magnify",
"dojox/charting/action2d/Highlight",
"dojox/charting/action2d/Tooltip",
"dojox/charting/widget/Legend",
"dojox/charting/themes/PlotKit/green",
"dojox/charting/plot2d/StackedLines",
"dojox/charting/action2d/MouseIndicator",
"dojox/charting/axis2d/Default",
"dojo/ready"
], function(Chart, Magnify, Highlight, Tooltip, Legend, theme_green, _lines, MouseIndicator, _axis, ready) {
// wrapped in domready event
ready(function() {
// create a chart with placeholder div#charty
var chart2 = new Chart("chart");
chart2.setTheme(theme_green);
chart2.addPlot("default", {
type: "StackedLines",
markers: true,
// create round dots on plot-points
tension: 3,
// curve slightly
shadows: { // add shadow
dx: 2,
dy: 2,
dw: 2
}
});
chart2.addAxis("x", {
min: 0,
majorTick: {
stroke: "black",
length: 3
},
minorTick: {
stroke: "gray",
length: 3
}
});
chart2.addAxis("y", {
vertical: true,
min: 0,
max: 6,
majorTick: {
stroke: "black",
length: 3
},
minorTick: {
stroke: "gray",
length: 3
}
});
// each point, added to a series.
// note the first entry in Series A which has the
// customizable object notation
// Hover mouse over lower left point (first red square"
chart2.addSeries("Series A", [{
x: 0.5,
y: 3.5,
tooltip: "Custom data"}
, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6], {
stroke: {
color: "red",
width: 2
},
fill: "lightpink",
marker: "m-3,-3 l0,6 6,0 0,-6 z"
});
chart2.addSeries("Series B", [1, 1.6, 1.3, 1.4, 1.1, 1.5, 1.1], {
stroke: {
color: "blue",
width: 2
},
fill: "lightblue",
marker: "m-3,0 c0,-4 6,-4 6,0 m-6,0 c0,4 6,4 6,0"
});
chart2.addSeries("Series C", [1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6], {
stroke: {
color: "green",
width: 2
},
fill: "lightgreen",
marker: "m0,-3 l3,3 -3,3 -3,-3 z"
});
var anim2a = new Magnify(chart2, "default", {
scale: 3
});
var anim2b = new Highlight(chart2, "default");
var anim2c = new Tooltip(chart2, "default");
var legend2 = new Legend({
chart: chart2
}, "legend2");
new dojox.charting.action2d.MouseIndicator(chart2, "default", {
series : "Series A",
mouseOver: true,
labelFunc: function(v, v2){
return "<div>fred</br></br>betty</div>";
},
fillFunc: function(v){
return '#fcfcfc';
},
fontColor:'black',
stroke: {width: 2, color: 'purple'},
lineStroke: {width: 2, color: 'green'},
dualIndicator: true
});
chart2.render();
});
});
By default only plain text is rendered because the rendering is either done by SVG or Canvas (or VML for old IEs). However you should be able to customize this to render some HTML.
The way to proceed is to tell the data indicator to not render the labels itself (labels: false) and do it yourself in when a change event occurs. Something like the following (here using a dijit/Tooltip but you can use any other way to render HTML):
require(["dojo/ready", "dojo/on", "dojox/charting/Chart", "dojox/charting/axis2d/Default", "dojox/charting/plot2d/Lines",
"dojox/charting/action2d/MouseIndicator", "dijit/Tooltip", "dijit/place"],
function(ready, on, Chart, Default, Lines, MouseIndicator, Tooltip, place){
ready(function(){
var chart = new Chart("chart", { margins : {l :20, t:10, b:10, r: 50}});
chart.addAxis("x", {fixLower: "minor", natural: true, stroke: "gray",
majorTick: {color: "red", length: 4}, minorTick: {color: "blue", length: 2}});
chart.addAxis("y", {vertical: true, min: 0, max: 100, majorTickStep: 10, minorTickStep: 5, stroke: "gray",
majorTick: {stroke: "black", length: 4}, minorTick: {stroke: "gray", length: 2}});
chart.addPlot("default", {type: Lines, markers: false});
chart.addSeries("Series A", [
{ x: 1, y: 8},{ x: 2, y: 7},{ x: 3, y: 3},{ x: 4, y: 2},{ x: 5, y: 5},{ x: 6, y: 7},{ x: 7, y: 9},{ x: 8, y: 10},{ x: 9, y: 2},{ x: 10, y: 10},
{ x: 15, y: 14},{ x: 16, y: 16},{ x: 17, y: 18},{ x: 18, y: 13},{ x: 19, y: 16},{ x: 20, y: 15},{ x: 21, y: 20},{ x: 22, y: 19},{ x: 23, y: 15},{ x: 24, y: 12},
{ x: 25, y: 24},{ x: 26, y: 20},{ x: 27, y: 20},{ x: 28, y: 26},{ x: 29, y: 28},{ x: 30, y: 26},{ x: 31, y: 28},{ x: 32, y: 29},{ x: 33, y: 24},{ x: 34, y: 29},
{ x: 35, y: 31},{ x: 36, y: 35},{ x: 37, y: 37},{ x: 38, y: 31},{ x: 39, y: 35},{ x: 40, y: 37},{ x: 41, y: 37},{ x: 42, y: 36},{ x: 43, y: 31},{ x: 44, y: 30},
{ x: 45, y: 50},{ x: 46, y: 49},{ x: 47, y: 42},{ x: 48, y: 46},{ x: 49, y: 44},{ x: 50, y: 40},{ x: 51, y: 47},{ x: 52, y: 43},{ x: 53, y: 48},{ x: 54, y: 47},
{ x: 55, y: 51},{ x: 56, y: 52},{ x: 57, y: 52},{ x: 58, y: 51},{ x: 59, y: 54},{ x: 60, y: 57},{ x: 61, y: 58},{ x: 62, y: 50},{ x: 63, y: 54},{ x: 64, y: 51},
{ x: 65, y: 62},{ x: 66, y: 68},{ x: 67, y: 67},{ x: 68, y: 62},{ x: 69, y: 62},{ x: 70, y: 65},{ x: 71, y: 61},{ x: 72, y: 66},{ x: 73, y: 65},{ x: 74, y: 62},
{ x: 75, y: 74},{ x: 76, y: 78},{ x: 77, y: 78},{ x: 78, y: 77},{ x: 79, y: 74},{ x: 80, y: 74},{ x: 81, y: 72},{ x: 82, y: 74},{ x: 83, y: 70},{ x: 84, y: 78},
{ x: 85, y: 84},{ x: 86, y: 83},{ x: 87, y: 85},{ x: 88, y: 86},{ x: 89, y: 86},{ x: 90, y: 89},{ x: 91, y: 89},{ x: 92, y: 85},{ x: 93, y: 86},{ x: 94, y: 86},
{ x: 95, y: 98},{ x: 96, y: 97},{ x: 97, y: 93},{ x: 98, y: 91},{ x: 99, y: 92},{ x: 100, y: 92}
]);
var i = MouseIndicator(chart, "default", { series: "Series A", labels: false });
var tooltip = new Tooltip();
on(i, "Change", function(evt){
if(evt.label){
var around = chart.getPlot("default").toPage({ x: evt.start.x, y: maxVertical });
around.w = 1;
around.h = 1;
tooltip.label = "<h1>value:</h1><h2>" + evt.start.y + "</h2>";
tooltip.position = ["above-centered"];
if (!shown) {
shown = true;
tooltip.open(around);
} else {
Tooltip._masterTT.containerNode.innerHTML = tooltip.label;
place.around(Tooltip._masterTT.domNode, around, ["above-centered"]);
}
} else {
// hide
tooltip.close();
shown = false;
}
});
chart.render();
var maxVertical = chart.getAxis("y").getScaler().bounds.to;
var shown = false;
})
});
I am using a dojo column chart. I want to add a custom line (some kind of a threshold line) that is drawn on the plot.
So, lets say y axis ranges from 0 to 5. I want a horizontal line at, lets say, 4.2 running across the plot.
It is a column chart.
I was hoping to find some drawing APIs that can help me do custom drawing on the plot but i am unable to figure out how. I know the chart uses gfx and surface so if i can get a handle to the chart/plot surface perhaps i can draw a custom line? Will also need data to rendered co-ordinates mapping to make this happen
My current chart uses code like:
var mychart = new dojox.charting.Chart2D("columns").
addAxis("x", {fixLower: "minor", fixUpper: "minor", natural: true,
font: "normal normal 10pt Arial",
labels: [{value: 1, text: "Q2 FY11"},
{value: 2, text: "Q3 FY11"},
{value: 3, text: "Q4 FY11"},
{value: 4, text: "Q1 FY12"}]
}).
addAxis("y", {vertical: true, includeZero: false, fixLower: "major", fixUpper: "major", min: 0, max: 5, font: "normal normal 10pt Arial", majorTick: {color: "black", length: 6}, minorTicks: false}).
addPlot("default", {type: "ClusteredColumns", tension: "S", shadows: {dx: 2, dy: 2}, gap: 5, minBarSize : 14, maxBarSize:24, animate: { duration: 1000, easing: dojo.fx.easing.linear} }).
addSeries("Series A", [{ y: 2.3, tooltip: "FFFF"}, { y: 3.5, tooltip: "GGGG"}]).
addSeries("Series B", [1.2, 2.5]);
You could render the line using another plot.
new dojox.charting.Chart2D("columns").
addAxis("x", {fixLower: "minor", fixUpper: "minor", natural: true,
font: "normal normal 10pt Arial",
labels: [{value: 1, text: "Q2 FY11"},
{value: 2, text: "Q3 FY11"},
{value: 3, text: "Q4 FY11"},
{value: 4, text: "Q1 FY12"}]
}).
addAxis("y", {vertical: true, includeZero: false, fixLower: "major", fixUpper: "major", min: 0, max: 5, font: "normal normal 10pt Arial", majorTick: {color: "black", length: 6}, minorTicks: false}).
addPlot("default", {type: "ClusteredColumns", tension: "S", shadows: {dx: 2, dy: 2}, gap: 5, minBarSize : 14, maxBarSize:24, animate: { duration: 1000, easing: dojo.fx.easing.linear} }).
addSeries("Series A", [{ y: 2.3, tooltip: "FFFF"}, { y: 3.5, tooltip: "GGGG"}]).
addSeries("Series B", [1.2, 2.5]).
addPlot("threshold", { type: "Lines" }).
addSeries("threshold", [{x: 0, y: 4.2}, {x: 4, y: 4.2}], { plot: "threshold" }).
render();
Another simple example representing max_temperature as Lines and Min_temperature as Columns in the same chart:
var chart = new Chart("chartNode");
chart.addPlot("tempMaxPlot", {
type: "Lines",
markers: false
});
chart.addPlot("tempMinPlot", {
type: "Columns",
markers: true,
gap: 5
});
chart.addAxis("x");
chart.addAxis("y", { min: -3, max: 13, vertical: true, fixLower: "minor", fixUpper: "major" });
var chartData_tmax = [11,13,12,11,10,9,9,10];
chart.addSeries("tmax",chartData_tmax, { plot: "tempMaxPlot" });
var chartData_tmin = [1,1,2,1,0,-1,-1,0];
chart.addSeries("tmin",chartData_tmin, { plot: "tempMinPlot" });
chart.render();
Last but not least you can gfx drawing functions to draw a line manually, as described below:
Add a line (not a series) to a dojo chart