how to make a scatter with regression line graph in amcharts / highcharts? - highcharts

I read all amcharts and highcharts demo and cant figure out how to draw chart like
The issue I am having is the X axis is text, not numeric like most amcharts/highcharts demos are.

It doesn't matter that you have categories on the x axis, as far as the scatter plot is concerned - your x values are the array index of the categories (0-5 in the case of your image).
There is a plugin to auto calculate a regression line, here:
http://www.highcharts.com/plugin-registry/single/22/Highcharts%20regression
Or, you can calculate your own and plot it normally.
However, a regression line through a group of categories doesn't make much sense. I don't see how it can tell you anything useful, and is probably more likely to cause confusion or outright misunderstanding.
This seems to me to be data that would be more appropriate to plot with a bar chart than a scatter plot.
FWIW
{{edit:
After looking at this longer, I am somewhat unclear: is that actually a regression line, or is that an average, or a target...?
If that's the case, you can either plot it is a line series, or you can use plotLines:
http://api.highcharts.com/highcharts#yAxis.plotLines
Example with a plotLine:
http://jsfiddle.net/jlbriggs/3d3fuhbb/63/

The chart like this is very easily done using amCharts regular Serial chart with line graph with bullets (bullet: "diamond") and no line (lineAlpha: 0).
var chart = AmCharts.makeChart( "chartdiv", {
"type": "serial",
"dataProvider": [ {
"category": "Civil",
"value": 0.87
}, {
"category": "Piping",
"value": 1.1
}, {
"category": "Mechanical",
"value": 0.69
}, {
"category": "Electrical",
"value": 0.82
}, {
"category": "Insulation",
"value": 1.42
}, {
"category": "Completion",
"value": 1.1
} ],
"valueAxes": [ {
"guides": [{
"value": 1,
"lineAlpha": 1,
"lineThickness": 2,
"lineColor": "#f00"
}]
} ],
"startDuration": 1,
"graphs": [ {
"lineAlpha": 0,
"bullet": "diamond",
"valueField": "value",
"lineColor": "#5782bf"
} ],
"chartCursor": {
"categoryBalloonEnabled": false,
"cursorAlpha": 0,
"zoomable": false
},
"categoryField": "category",
"categoryAxis": {
"gridPosition": "start",
"gridAlpha": 0,
"tickPosition": "start"
}
} );
<script src="http://www.amcharts.com/lib/3/amcharts.js"></script>
<script src="http://www.amcharts.com/lib/3/serial.js"></script>
<div id="chartdiv" style="width: 600px; height: 200px;"></div>

Related

Set color of highcharts scatter diagram points according to a third value

I'd like to create a highcharts scatter diagram showing wind direction (y) on a time axis (x). The color of the points should be calculated using the wind speed. How could this be done? The result should look like the attached example, where red dots indicate high speed, green and yellow low speed.
One solution would be to split the data into 12 series (Beaufort 1-12) with different colors, shown in the same chart, but I would prefer to find a method to calculate the colors for each point seperately.
You can use colorAxis with dataClasses and colorKey for the series. For example:
colorAxis: {
dataClasses: [{
to: 10,
color: 'green'
}, {
to: 50,
from: 10,
color: 'yellow'
}, {
to: 100,
from: 50,
color: 'red'
}]
},
series: [{
colorKey: 'speed',
data: [{
x: 0,
y: 1,
speed: 10
}, ...],
type: 'scatter'
}]
Live demo: http://jsfiddle.net/BlackLabel/5po1Lqym/
Docs: https://www.highcharts.com/docs/maps/color-axis
API Reference: https://api.highcharts.com/highcharts/colorAxis.dataClasses

Part colour doesn't pull through from Configured Products

I have an issue that I have created 4 derived Products from a single part, that each part has a different Colour / Material set within it. I have the 4 Products called as PossibleChildren in my main part but when I try and bring in one of the 4 Products which ever is the first colour I pick, is the only colour that will select, so if for example I select RED for my first part, if I then pick the BLUE part it still only places the RED part. I created the 4 Products by importing this text...
"item_id","configuration"
"sub_s2_8t15","{""componentId"":""racksystems_test:sub_fronttile"",""parameters"":
{""tileColour"":""racksystems_test:s2_8t15""}}"
"sub_s2_7t58","{""componentId"":""racksystems_test:sub_fronttile"",""parameters"":
{""tileColour"":""racksystems_test:s2_7t58""}}"
"sub_s2_4t50","{""componentId"":""racksystems_test:sub_fronttile"",""parameters"":
{""tileColour"":""racksystems_test:s2_4t50""}}"
"sub_twinwall","{""componentId"":""racksystems_test:sub_fronttile"",""parameters"":
{""tileColour"":""racksystems_test:twinwall""}}"
And then in the master.json part I call the 4 created Products...
"itemId": "racksystems_test:sub_s2_8t15",
"condition":"((version=='Rack')&&(company=='BetaTest'))"
}, {
"itemId": "racksystems_test:sub_s2_7t58",
"condition":"((version=='Rack')&&(company=='BetaTest'))"
}, {
"itemId": "racksystems_test:sub_s2_4t50",
"condition":"((version=='Rack')&&(company=='BetaTest'))"
}, {
"itemId": "racksystems_test:sub_twinwall",
"condition":"((version=='Rack')&&(company=='BetaTest'))"
},
I have a KEY in the sub_fronttile.json as this..
{
"key": "tileColour",
"type": "Material",
"labels": {
"en": "Tile Colour?"
},
"defaultValue": "",
"valueObjects": [
{
"value": "racksystems_test:red",
"labels": {
"en": "Black"
}
},
........
Then call the colour in my geometry like this...
AddCube(Vector3f{infillWidth-20,materialThickness,infillHeight-20});
SetObjSurface(tileColour);
MoveMatrixBy(Vector3f{20,-offset,40});
So master.json is my main part and sub_fronttile.json contains my products
Is tileColour a global parameter? If yes, then the global value is assigned on dock. If tileCoulour is not a global parameter, this should not happen unless an assignmentOnDock is used.
In order to workaround the assignment in global parameters, it might help to:
have two parameters instead, tileColour_local, tileColour_global where one is global and not visible, other is not global and is visible.
tileColour_global.onValueChange: "if (parameter.userTriggeredChange) { tileColour_local = tileColour_global; }

Highcharts yAxis is not scaling to fill available height

I'm having trouble with a chart where the height of the chart is not scaling to fill the area. The chart object itself is scaling correctly into the container div, it is the yAxis itself that is stuck in a shrunk state. I believe it has something to do with working with smaller numbers, but I'm not 100% certain
Any guidance would be much appreciated
Edit - JSFiddle
"yAxis": {
"min": 0,
"categories": [],
"title": {
"text": "Hit Rate"
},
"stackLabels": {
"enabled": false
},
"labels": {
"overflow": "justify"
},
"tickInterval":0.1
}
From the doc :
tickInterval: number
The interval of the tick marks in axis units. When undefined, the tick interval is computed to approximately follow the tickPixelInterval on linear and datetime axes. On categorized axes, a undefined tickInterval will default to 1, one category.
If you remove the categories: [] option of the y-axis, the graph is auto-scaled correctly.
EDIT : I didn't see you set a tickInterval, but the solution (removing the empty categories from y-axis) still solved the problem.

Vanishing when using the price difference

With a team, we are studying how it is possible to predict the price movement with high-frequency. Instead of predicting the price directly, we have decided to try predicting price difference as well as the features. In other words, at time t+1, we predict the price difference and the features for time t+2. We use the predicted features from time t+1 to predict the price at time t+2.
We got very excited, because we thought getting good results with the following graph
We got problems in production and we wasn't known the problem till we plot the price difference.
Here is the content of the config file
{
"data": {
"sequence_length":30,
"train_test_split": 0.85,
"normalise": false,
"num_steps": 5
},
"training": {
"epochs":200,
"batch_size": 64
},
"model": {
"loss": "mse",
"optimizer": "adam",
"layers": [
{
"type": "lstm",
"neurons": 51,
"input_timesteps": 30,
"input_dim": 101,
"return_seq": true,
"activation": "relu"
},
{
"type": "dropout",
"rate": 0.1
},
{
"type": "lstm",
"neurons": 51,
"activation": "relu",
"return_seq": false
},
{
"type": "dropout",
"rate": 0.1
},
{
"type": "dense",
"neurons": 101,
"activation": "relu"
},
{
"type": "dense",
"neurons": 101,
"activation": "linear"
}
]
}
}
How can we fix the problem of the vanishing price difference?
Predicting the next price to within 1% or so is very easy. You could just use the old price as a prediction and achieve 1%. Prices don't change very fast. Therefore, the next price is almost always very close to the last price. The model has picked up on that.
I guess your model learned almost nothing except the very simple relationship that the next price is close to the last price. There is not necessarily anything wrong with your model. Predicting stock prices should be a very hard problem. The solution to this problem would make you rich. It is that hard.

highcharts: margin between two boxplot series

I have a Highcharts chart containing boxplots. The chart has 1 yaxis and 1 series containing 4 data-arrays which all are on the same yaxis, obviously.
how can i increase the padding between Series1 and Series[2]? the x-axis is based on categories.
EDIT:
of course, i tried already with groupPadding/pointpadding, but couldn't get it to work. if i apply point/groupPadding to one specific array in series then its width gets smaller. if apply it to the whole series, then the padding is between each of the boxplots. however, i only need the padding between Series1 and Series[2]. are there any other ways to try?
EDIT2:
updated/changed picture.
Use pointPlacemet for each of the series. See demo: http://jsfiddle.net/6Lftuhzk/
series: [{
pointPlacement: -0.1, // to the left
data: [ ... ]
}, {
pointPlacement: -0.1, // to the left
data: [ ... ]
}, {
pointPlacement: 0.1, // to the right
data: [ ... ]
}, {
pointPlacement: 0.1, // again, to the right
data: [ ... ]
}]

Resources