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>
Related
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 hope someone can please help me.
I've got a pie chart on a web page using Google Chart. I've popped the code below.
The problem I am having is that I want the legend which is on the right hand side when on a desktop screen to move underneath the pie chart when being viewed on a mobile device.
I've seen some posts about this, but they didn't quite give me what I needed and were not new.
Can anyone please advise, I'd be very grateful!
function drawChart() {
// Create the data table.
var data = new google.visualization.DataTable();
data.addColumn('string', 'Toppings');
data.addColumn('number', 'Cost in pence');
data.addRows([
['Cheese: 42 pence', 42],
['Ham: 21 pence', 21],
['Pepparami: 4 pence', 4],
['Anchovies: 11 pence', 11],
['Chicken: 3 pence', 3],
['Pineapple: 7 pence', 7],
['Beef: 12 pence', 12]
]);
// Set chart options
var options = {'title':'How much are your toppings?',
tooltip: {isHtml: true},
chartArea:{left:0,top:0},
'height':450,
width:680,
'pieHole':0.4,
'pieSliceText':'value',
colors: ['#fbc900', '#e6007e', '#ee7203', '#009a44', '#e22a1b','#95c11f','#0099b3'],
tooltip: {
text: 'none'
},
titleTextStyle: {color: 'black', fontName: 'Lato', fontSize: '1'},
pieSliceTextStyle: {fontSize: '20'},
legend: {textStyle: {fontSize: 12}}
};
function resize() {
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
window.onload = resize();
window.onresize = resize;
}
</script>
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 trying to generate a section of image views which will sit at the top of an application and update as the user progresses through the quiz.
My array variable is Qs, the code I have to generate an imageView is as follows:
var imageView: UIImageView!
var i = 0
var total = Int(Qs.capacity) // Just testing what .capacity does.
for i in 0..<(Qs.count-1){
imageView - UIImageView(frame: CGRect(x: 0, y: 75, width: 50, height: 50))
imageView.image = UIImage(named:"InfoIcon")
imageView.contentMode = .scaleAspectFit
self.view.addSubView(imageView)
}
I already have a variable which tracks the users progress through the quiz with just an integer if that would be any help, its declared along with the quiz functionality.
Here is a fantastically draw visual of what I am trying to accomplish:
Any help is appreciated,
thanks
Lets assume you have a container view attached at the top, then you can use this method to add any number of imageView's.
func addProgressImages(to view: UIView, count: Int) {
let screenSize = UIScreen.main.bounds.size
for i in 0..<count {
let spacing: CGFloat = 2
let tag = i + 888
let width: CGFloat = screenSize.width/CGFloat(count)
let height: CGFloat = width
if let view = view.viewWithTag(tag) {
view.removeFromSuperview()
}
let x = spacing + CGFloat(i) * width
let imageView = UIImageView(frame: CGRect(x: x, y: 100, width: width - spacing, height: height))
imageView.image = UIImage(named:"InfoIcon")
imageView.tag = tag
imageView.contentMode = .scaleAspectFit
view.addSubview(imageView)
}
}
You can play with y value for vertical alignment.
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/