anychart.theme(anychart.themes.darkEarth);
anychart.onDocumentReady(function () {
var dataSet = anychart.data.set([
['P1', 969.5, 2040, 1200, 1600,2000],
['P2', 779.1, 1794, 1124, 1724,4000],
['P3', 739.2, 2026, 1006, 1806,5000]
]);
var seriesData_1 = dataSet.mapAs({x: [0], value: [1]});
var seriesData_2 = dataSet.mapAs({x: [0], value: [2]});
var seriesData_3 = dataSet.mapAs({x: [0], value: [3]});
var seriesData_4 = dataSet.mapAs({x: [0], value: [4]});
var seriesData_5 = dataSet.mapAs({x: [0], value: [5]});
chart = anychart.column();
chart.animation(true);
chart.container('container');
chart.title('Combination of Stacked Column and Line Chart (Dual Y-Axis)');
var scale = anychart.scales.linear();
scale.stackMode('value');
chart.column(seriesData_2);
var lineSeries = chart.area(seriesData_1);
lineSeries.yScale(scale);
var lineSeries2 = chart.area(seriesData_5);
lineSeries2.yScale(scale);
chart.column(seriesData_3);
chart.column(seriesData_4);
chart.draw();
});
I am trying to add a Series Column chart with Stacked Area.
But the Series Column and Stacked Area should have different Scales to make them separate from Stacking.
How to integrate these two Scales into the Yaxis.
Is there any to do that? Please do suggest!!
I think you can use additional axis from the left or from the right of the chart.
Left axis example:
var secondYAxis = chart.yAxis(1).scale(scale);
http://jsfiddle.net/cgquc1pz/1/
Right axis example:
var secondYAxis = chart.yAxis(1).scale(scale);
secondYAxis.orientation('right');
http://jsfiddle.net/cgquc1pz/2/
Related
I have an anychart chart with 2 Y-axes with their own scales.
For both scales the gridlines are active.
The number of gridlines for both axes differ (see attached example image).
Is it possible to align the gridlines for both Y-axes?
example image
You should enable grid lines on your chart with yGrid() and tweak the configuration of your vertical scales, especially ticks intervals.
Here is an example:
anychart.onDocumentReady(() => {
let data1 = [
["A", 7],
["B", 3]
];
let data2 = [
["A", 112365],
["B", 99986]
];
let chart = anychart.column(),
series1 = chart.column(data1),
series2 = chart.column(data2);
let yScale = chart.yScale();
yScale.minimum(0);
yScale.ticks().interval(2); // <--- HERE
let extraYScale = anychart.scales.linear();
extraYScale.minimum(0);
extraYScale.ticks().interval(40000); // <--- HERE
let yAxis = chart.yAxis(0);
yAxis.stroke("red");
yAxis.ticks().stroke("red");
yAxis.labels().fontColor("red");
let extraYAxis = chart.yAxis(1);
extraYAxis.scale(extraYScale);
extraYAxis.orientation("right");
extraYAxis.stroke("green");
extraYAxis.ticks().stroke("green");
extraYAxis.labels().fontColor("green");
series1.yScale(yScale);
series2.yScale(extraYScale);
series1.normal().fill("red", 0.5);
series1.normal().stroke("red", 1);
series2.normal().fill("green", 0.5);
series2.normal().stroke("green", 1);
chart.yGrid(true); // <--- HERE
chart.container("container");
chart.draw();
});
#container {
width: 100%;
height: 350px;
}
<script src="https://cdn.anychart.com/releases/8.11.0/js/anychart-core.min.js"></script>
<script src="https://cdn.anychart.com/releases/8.11.0/js/anychart-cartesian.min.js"></script>
<div id="container"></div>
I'm trying to combine a jump line with a multiseries column chart. Is it possible to create a jump line specifically for each column of the multiseries column chart? For now the only thing that i could obtain is a jump line for each group of the dataset, here's an example:
anychart.onDocumentReady(function () {
var data = [
["January", 12000, 10000, 8100],
["February", 15000, 12000, 8200],
["March", 16000, 18000, 8300],
];
var dataSet = anychart.data.set(data);
var mapping1 = dataSet.mapAs({x: 0, value: 1});
var mapping2 = dataSet.mapAs({x: 0, value: 2});
var jump1 = dataSet.mapAs({x: 0, value: 3});
// create a chart
var chart = anychart.column();
// create the series and set the data
var series1 = chart.column(mapping1);
var series2 = chart.column(mapping2);
var series3 = chart.jumpLine(jump1);
series3.stroke("3 #FFFF00");
chart.container("container");
chart.draw();
});
If I got your idea correctly, then you can create an additional xScale and xAxis. Then bind the jump series to that additional scale. Here is the live sample based on your code.
If someone needs this, thanks to #AnyChart Support 's answer here's the code for combining this two chart.
anychart.onDocumentReady(function () {
var data = [
["January", 12000, 10000],
["February", 15000, 12000],
["March", 16000, 18000],
];
var jumpData = [
['January_1', 1000],
['January_2', 3000],
['February_1', 5000],
['February_2', 6000],
['March_1', 5000],
['March_2', 7500],
];
var dataSet = anychart.data.set(data);
var jumpDataSet = anychart.data.set(jumpData);
var mapping1 = dataSet.mapAs({x: 0, value: 1});
var mapping2 = dataSet.mapAs({x: 0, value: 2});
var jump1 = jumpDataSet.mapAs({x: 0, value: 1});
// create a chart
var chart = anychart.column();
chart.barGroupsPadding(1);
// Set the padding between bars or columns.
chart.barsPadding(1);
// create the series and set the data
var series1 = chart.column(mapping1);
var series2 = chart.column(mapping2);
var additionalXscale = anychart.scales.ordinal();
chart.xAxis(1).scale(additionalXscale).enabled(false);
var series3 = chart.jumpLine(jump1);
series3.pointWidth('60%');
series3.xScale(additionalXscale);
series3.stroke("5 #00FF00");
series3.name = "AAA"
chart.container("container");
chart.draw();
});
I've successfully built and displayed a custom geometry (a cube) in SceneKit from this post
Custom Geometry
Now, I want to set the color of each face to a different color. I found this post that supposed to do that
Per Vertex Color
Unfortunately, I can't seem to set the color of a face of the cube to a specific color. For example, if I set the color of all vertices to SCNVector3(x:1,y:0,z:0), I would expect all faces to be red, but, instead, they're all green. Setting the colors to SCNVector3(x:0,y:1,z:0) turns the faces black. Here's the relevant code
let colors = [SCNVector3](count:vertices.count, repeatedValue:SCNVector3(x:1, y:0, z:0))
let colorData = NSData(bytes: colors, length: sizeof(SCNVector3) * colors.count)
let colorSource = SCNGeometrySource(data: colorData, semantic: SCNGeometrySourceSemanticColor, vectorCount: colors.count, floatComponents: true, componentsPerVector: 3, bytesPerComponent: sizeof(Float), dataOffset: 0, dataStride: sizeof(SCNVector3))
let geometry = SCNGeometry(sources: [colorSource, vertexSource, normalSource], elements: [element])
// Create a node and assign our custom geometry
let node = SCNNode()
let material = SCNMaterial()
material.diffuse.contents = NSColor.whiteColor()
geometry.materials = [material]
node.geometry = geometry
Does anyone know why it's not working?
You have to create a material per face with a different color.
For example:
let material1 = SCNMaterial()
material1.diffuse.contents = NSColor.whiteColor()
let material2 = SCNMaterial()
material2.diffuse.contents = NSColor.greenColor()
let material3 = SCNMaterial()
material3.diffuse.contents = NSColor.redColor()
let material4 = SCNMaterial()
material4.diffuse.contents = NSColor.blackColor()
let material5 = SCNMaterial()
material5.diffuse.contents = NSColor.blueColor()
let material6 = SCNMaterial()
material6.diffuse.contents = NSColor.whiteColor()
geometry.materials = [material1,material2,material3,material4,material5,material6]
I am using react, d3 chart to generate the line chart. I used d3.min and d3.max to generate the min and max values for both x and y axis. The data for the xAxis all ways comes in the string format lets say "2017-12-31" and I am using timeparse to parse the string into date format and pass it to x axis.
Now the xAxis scale shows as Jan, Feb, March ....
g.append("g")
.attr("class", "axis axis--x")
.attr("transform", "translate(0," + height + ")")
.call(d3Axis.axisBottom(x).tickFormat(d3Time.timeFormat("%b")))
Now when ever the minimum value of xAxis is last date of month it was not showing up in the scale of xAxis.
For example if the the minimum value is '2018-07-01' Then axis scale will be showing "July, Aug, Sep, Oct"
but if the minimum value is '2018-07-31' then axis scale will be showing "Aug, Sep, Oct"
The data is formatted in such way that the dates of all previously months will be showing as the last of the month.
ex: [{date: '2018-07-31', value: 10},
{date: '2018-08-31', value: 10},
{date: '2018-09-30', value: 10},
{date: '2018-10-31', value: 10}]
Is it possible to show the Month Name even if the minimal value is last of the month.
d3.scaleTime().nice is what you'll be looking for in this case.
Quoting the docs:
This method typically modifies the scale’s domain, and may only extend the bounds to the nearest round value. Nicing is useful if the domain is computed from data, say using extent, and may be irregular.
Example without using nice method
var data = [{date: '2018-07-31', value: 10},
{date: '2018-08-31', value: 10},
{date: '2018-09-30', value: 10},
{date: '2018-10-31', value: 10}];
var parseTime = d3.timeParse('%Y-%m-%d');
data.forEach(function (d) {
d.date = parseTime(d.date);
});
var svg = d3.select('body').append('svg').attr('width', 500).attr('height', 400);
var gAxis = svg.append('g').classed('x axis', true);
var xScale = d3.scaleTime().domain(d3.extent(data, d => d.date)).range([10, 490]);
var xAxis = d3.axisBottom(xScale).tickFormat(d3.timeFormat("%b"));
gAxis.call(xAxis);
<script src="https://d3js.org/d3.v4.min.js"></script>
Example using the scale's nice method
var data = [{date: '2018-07-31', value: 10},
{date: '2018-08-31', value: 10},
{date: '2018-09-30', value: 10},
{date: '2018-10-31', value: 10}];
var parseTime = d3.timeParse('%Y-%m-%d');
data.forEach(function (d) {
d.date = parseTime(d.date);
});
var svg = d3.select('body').append('svg').attr('width', 500).attr('height', 400);
var gAxis = svg.append('g').classed('x axis', true);
var xScale = d3.scaleTime().domain(d3.extent(data, d => d.date)).range([10, 490]).nice();
var xAxis = d3.axisBottom(xScale).tickFormat(d3.timeFormat("%b"));
gAxis.call(xAxis);
<script src="https://d3js.org/d3.v4.min.js"></script>
Hope this helps.
I am using openlayers 3 and I am looking for a way to load track data not from urls, but directly by adding text to vectorsource IGC. I have the data with coordinates and times as arrays. What format is right? So, insted of this:
var vectorSource = new ol.source.IGC({
projection: 'EPSG:3857',
urls: [
'data/igc/Clement-Latour.igc',
'data/igc/Damien-de-Baenst.igc',
'data/igc/Sylvain-Dhonneur.igc',
'data/igc/Tom-Payne.igc',
'data/igc/Ulrich-Prinz.igc'
]
});
I'd like to use something like this (not sure about the format):
var vectorSource = new ol.source.IGC({
projection: 'EPSG:3857',
text: [
array1,
array2,
array3 // or arrayall with all three arrays, or text.. What is correct?
]
});
For more control and flexibility you can use an ol.source.Vector and an ol.format.IGC instead of the "convenient" ol.source.IGC. For example:
var source = new ol.source.Vector();
var format = new ol.format.IGC();
var readOptions = {featureProjection: 'EPSG:3857'};
var features = [
format.readFeature(text1, readOptions),
format.readFeature(text2, readOptions),
format.readFeature(text3, readOptions)
];
source.addFeatures(features);
var layer = new ol.layer.Vector({source: source});