Toggle Series programatically in lighning chart - lightningchart

I have UI element and I am attaching series to it
box = legendBox.addElement(UIElementBuilders.CheckBox);
series.attach(box)
Now I click the series in legendbox it toggles my line series.Is there anyway we can click the checkbox programatically ?

UICheckBox can be programmatically toggled on and off with the use of UICheckBox.setOn(isOn) method.
The following code would toggle lineSeries on and off with 1 second interval.
const ui = chart.addUIElement(UILayoutBuilders.Column)
const box = ui.addElement(UIElementBuilders.CheckBox)
lineSeries.attach(box)
setInterval(() => {
box.setOn(!box.getOn())
}, 1000)
See below for full working example where the "Diesel" series is toggled on and off programmatically through the UICheckBox.
// Extract required parts from LightningChartJS.
const {
lightningChart,
SolidLine,
SolidFill,
ColorRGBA,
AxisTickStrategies,
UIOrigins,
DataPatterns,
Themes,
UILayoutBuilders,
UIElementBuilders,
} = lcjs
// Decide on an origin for DateTime axis.
const dateOrigin = new Date(2018, 8, 1)
// ----- Cache used styles -----
const customStrokeStyle = new SolidLine({
fillStyle: new SolidFill({
color: ColorRGBA(200, 50, 50)
}),
thickness: 2
})
// Create a XY Chart.
const chart = lightningChart().ChartXY({
// theme: Themes.dark
})
// Modify the default X Axis to use DateTime TickStrategy, and set the origin for the DateTime Axis.
chart.getDefaultAxisX().setTickStrategy(AxisTickStrategies.DateTime, (tickStrategy) => tickStrategy.setDateOrigin(dateOrigin))
chart.setPadding({
right: 50
})
.setTitle('Diesel and Gasoline Price Comparison')
const diesel = [{
x: 0,
y: 1.52
},
{
x: 1,
y: 1.52
},
{
x: 2,
y: 1.52
},
{
x: 3,
y: 1.58
},
{
x: 4,
y: 2.00
},
{
x: 5,
y: 2.00
},
{
x: 6,
y: 2.00
},
{
x: 7,
y: 2.00
},
{
x: 8,
y: 2.26
},
{
x: 9,
y: 1.90
},
{
x: 10,
y: 1.90
},
{
x: 11,
y: 1.90
},
{
x: 12,
y: 1.90
},
{
x: 13,
y: 1.60
},
{
x: 14,
y: 1.60
},
{
x: 15,
y: 1.60
},
{
x: 16,
y: 1.00
},
{
x: 17,
y: 1.00
},
{
x: 18,
y: 1.00
},
{
x: 19,
y: 1.74
},
{
x: 20,
y: 1.47
},
{
x: 21,
y: 1.47
},
{
x: 22,
y: 1.47
},
{
x: 23,
y: 1.74
},
{
x: 24,
y: 1.74
},
{
x: 25,
y: 1.74
},
{
x: 27,
y: 1.5
},
{
x: 28,
y: 1.5
},
{
x: 29,
y: 1.5
}
]
const gasoline = [{
x: 0,
y: 1.35
},
{
x: 1,
y: 1.35
},
{
x: 2,
y: 1.35
},
{
x: 3,
y: 1.35
},
{
x: 4,
y: 1.90
},
{
x: 5,
y: 1.90
},
{
x: 6,
y: 1.90
},
{
x: 7,
y: 1.92
},
{
x: 8,
y: 1.50
},
{
x: 9,
y: 1.50
},
{
x: 10,
y: 1.3
},
{
x: 11,
y: 1.3
},
{
x: 12,
y: 1.3
},
{
x: 13,
y: 1.3
},
{
x: 14,
y: 1.3
},
{
x: 15,
y: 1.32
},
{
x: 16,
y: 1.40
},
{
x: 17,
y: 1.44
},
{
x: 18,
y: 1.02
},
{
x: 19,
y: 1.02
},
{
x: 20,
y: 1.02
},
{
x: 21,
y: 1.02
},
{
x: 22,
y: 1.02
},
{
x: 23,
y: 1.02
},
{
x: 24,
y: 1.02
},
{
x: 25,
y: 1.02
},
{
x: 27,
y: 1.30
},
{
x: 28,
y: 1.30
},
{
x: 29,
y: 1.30
}
]
// Add two line series.
const lineSeries = chart.addLineSeries()
.setName('Diesel')
const lineSeries2 = chart.addLineSeries()
.setName('Gasoline')
.setStrokeStyle(customStrokeStyle)
// Set the correct value to use for the data frequency.
// 1000ms * 60s * 60min * 24h
const dataFrequency = 1000 * 60 * 60 * 24
// Add the points to each Series - the X values are multiplied by dataFrequency to set the values properly on the X Axis.
lineSeries2.add(diesel.map((point) => ({
x: point.x * dataFrequency,
y: point.y
})))
lineSeries.add(gasoline.map((point) => ({
x: point.x * dataFrequency,
y: point.y
})))
// Setup view nicely.
chart.getDefaultAxisY()
.setTitle('$/litre')
.setInterval(0, 3, false, true)
// Enable AutoCursor auto-fill.
chart.setAutoCursor(cursor => cursor
.setResultTableAutoTextStyle(true)
.disposeTickMarkerX()
.setTickMarkerYAutoTextStyle(true)
)
const legend = chart.addLegendBox()
// Add Chart to LegendBox.
legend.add(chart)
const ui = chart.addUIElement(UILayoutBuilders.Column)
const box = ui.addElement(UIElementBuilders.CheckBox)
lineSeries.attach(box)
setInterval(() => {
box.setOn(!box.getOn())
}, 1000)
<script src="https://unpkg.com/#arction/lcjs#3.0.0/dist/lcjs.iife.js"></script>

Related

Qt Qml 3 different graphs connected to a single y-axis

I want to create 3 graphs one under the other. When I move the mouse on the screen, I want to see the x value in the 3 graphs corresponding to the y value at that point. The chart I want and the outputs of my own work are as in the images. Maybe I can achieve what I want by putting a rectangle on the charts I make. But is there a more useful way or example of this?
Another problem is if I am going to continue with my own method;
When I make 3 separate charts, only the lowest one has the y axis, so there are tick counts on it. It doesn't happen in the 1st and 2nd charts. This doesn't look good either. How can I make the tick counts in the 3rd chart invisible?
When I activate the plotArea command lines and make the graphics larger and closer to each other, as in the 3rd picture, the plot description is not fully readable and 2 of the 5 numbers on the x-axis become unreadable.
for example;
output of my own code
with plotAreas open
ColumnLayout{
id: qmlWindow6GridLayout
anchors.fill: parent
ChartView {
//title: "Spline1"
id: chart1
Layout.fillWidth:true
Layout.fillHeight:true
legend.visible: true
backgroundColor: "black"
antialiasing: true
//plotArea: Qt.rect(35, 35, parent.width - 75, parent.height / 3 - 75)
SplineSeries {
//name: "Altimeter"
name: "Chart 1"
color: "red"
axisX: ValuesAxis {
visible: false
}
axisY: ValuesAxis{
labelsColor: "white"
}
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 15, 29, 00)); y: 50 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 15, 29, 20)); y: 100 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 29, 37)); y: 150 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 30, 20)); y: 200 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 45, 00)); y: 250 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 50, 00)); y: 300 }
}
}
ChartView {
//title: "Spline2"
id: chart2
Layout.fillWidth:true //yes, if wanted
Layout.fillHeight:true //yes, if wanted
legend.visible: true
backgroundColor: "black"
antialiasing: true
//plotArea: Qt.rect(35, 35, parent.width - 75, parent.height / 3 - 75)
SplineSeries {
name: "Chart 2"
color: "cyan"
axisX: ValuesAxis {
visible: false
}
axisY: ValuesAxis{
labelsColor: "white"
}
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 15, 29, 00)); y: 50 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 15, 29, 20)); y: 100 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 29, 37)); y: 150 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 30, 20)); y: 200 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 45, 00)); y: 250 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 50, 00)); y: 300 }
}
}
ChartView {
Layout.fillWidth: true
Layout.fillHeight: true
legend.visible: true
backgroundColor: "black"
antialiasing: true
//plotArea: Qt.rect(75, 75, parent.width - 125, parent.height / 3 - 125)
SplineSeries {
name: "Chart 3"
color: "purple"
axisX: DateTimeAxis {
format: "hh:mm:ss"
labelsColor: "white"
}
axisY: ValuesAxis{
labelsColor: "white"
}
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 15, 29, 00)); y: 50 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 15, 29, 20)); y: 100 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 29, 37)); y: 150 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 30, 20)); y: 200 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 45, 00)); y: 250 }
XYPoint { x: toMsecsSinceEpoch(new Date(0, 0, 0, 16, 50, 00)); y: 300 }
}
}
}

How control how the layout manage the drag and drop 'displacements' of the cells with react-grid-layout

This code creates a 10x1 layout with react-grid-layout . All the elements can move.
But I need it when I move one column to another only column don't add an extra row in the 10x1. I need all the movements to happen only in the 10x1.
How I can say this to the Grid ?
I have this code :
import '/node_modules/react-grid-layout/css/styles.css'
import '/node_modules/react-resizable/css/styles.css'
import GridLayout from "react-grid-layout";
export function MyFirstGrid () {
const widthCell=1;
const heightCell=1;
const layout = [
{ i: "0000", x: 0, y: 0, w: widthCell, h: heightCell,isResizable:false},
{ i: "0100", x: 1, y: 0, w: widthCell, h: heightCell,isResizable:false},
{ i: "0200", x: 2, y: 0, w: widthCell, h: heightCell,isResizable:false},
{ i: "0300", x: 3, y: 0, w: widthCell, h: heightCell,isResizable:false},
{ i: "0400", x: 4, y: 0, w: widthCell, h: heightCell,isResizable:false},
{ i: "0500", x: 5, y: 0, w: widthCell, h: heightCell,isResizable:false},
{ i: "0600", x: 6, y: 0, w: widthCell, h: heightCell,isResizable:false},
{ i: "0700", x: 7, y: 0, w: widthCell, h: heightCell,isResizable:false},
{ i: "0800", x: 8, y: 0, w: widthCell, h: heightCell,isResizable:false},
{ i: "0900", x: 9, y: 0, w: widthCell, h: heightCell,isResizable:false}
];
const getLayouts = () => {
const savedLayouts = localStorage.getItem("grid-layout");
return savedLayouts ? JSON.parse(savedLayouts) : layout;
};
const handleLayoutChange = (layout) => {
localStorage.setItem("grid-layout", JSON.stringify(layout));
};
const borderAdditive="border"
return (<div>
<GridLayout
layout={getLayouts()}
className="layout"
cols={10}
rowHeight={50}
width={1200}
onLayoutChange={handleLayoutChange}
margin={[1,1]}
>
<div className={borderAdditive} key="0000">0000</div>
<div className={borderAdditive} key="0100">0100</div>
<div className={borderAdditive} key="0200">0200</div>
<div className={borderAdditive} key="0300">0300</div>
<div className={borderAdditive} key="0400">0400</div>
<div className={borderAdditive} key="0500">0500</div>
<div className={borderAdditive} key="0600">0600</div>
<div className={borderAdditive} key="0700">0700</div>
<div className={borderAdditive} key="0800">0800</div>
<div className={borderAdditive} key="0900">0900</div>
</GridLayout>
</div>
);
}
To be graphical on a 10x10 layout now this happens :
I moved the element 0000 to 0100 and an extra row is added .
I want to move from 0000 to 0001 and those cells interchange the position. Something like that :
I know this solution is not perfect. But I want to share if anyone can use this.
// These get a array with only the X and Y of the updated Layout
function GetXYArray(layout){
let XYArray=[];
layout.map(item=>{XYArray.push({x:item.x,y:item.y})})
return XYArray
}
// This get what the cell spaces
function AvailableCoordinates(ChangedLayout,MaxValueX,MaxValueY){
let ArrayAvailableCoordinates=[];
let MaxValueColumn=MaxValueY+1;
for (let xCheck=0;xCheck<=MaxValueX;xCheck++){
let tempLayOut=ChangedLayout.filter(item=>{return item.x===xCheck})
if(ChangedLayout.filter(item=>{return item.x===xCheck}).length<MaxValueColumn){
for (let yCheck=0;yCheck<=MaxValueY;yCheck++){
if (tempLayOut.filter(item=>{return item.y===yCheck}).length===0){
ArrayAvailableCoordinates.push({x:xCheck,y:yCheck})
}
}
}
}
return ArrayAvailableCoordinates;
}
const handleOnDragStop=(layout)=>{
const MaxArrayYValue=9;
const MaxValueX=9;
const MaxValueY=9;
let VarAvailableCoordinates=AvailableCoordinates(GetXYArray(layout),MaxValueX,MaxValueY);
const itemsValueGreaterThanMaxArrayYValue=layout.filter(function (item){return item.y > MaxArrayYValue})
// This part reallocate the cells outside of the array and use the spaces Available. For one only one cell , this part can be improved
// on the user case a element have more than 1x1 cell
itemsValueGreaterThanMaxArrayYValue.map(GTMaxArrayYValue=>(layout.map(item=>{if (item.i===GTMaxArrayYValue.i) { item.x=VarAvailableCoordinates[0].x;
item.y=VarAvailableCoordinates[0].y}})))
}
The layout for testing is :
const layout = [
{ i: "0000", x: 0, y: 0, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0100", x: 1, y: 0, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0200", x: 2, y: 0, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0300", x: 3, y: 0, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0400", x: 4, y: 0, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0500", x: 5, y: 0, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0600", x: 6, y: 0, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0700", x: 7, y: 0, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0800", x: 8, y: 0, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0900", x: 9, y: 0, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0001", x: 0, y: 1, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0101", x: 1, y: 1, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0201", x: 2, y: 1, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0301", x: 3, y: 1, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0401", x: 4, y: 1, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0501", x: 5, y: 1, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0601", x: 6, y: 1, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0701", x: 7, y: 1, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0801", x: 8, y: 1, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0901", x: 9, y: 1, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0002", x: 0, y: 2, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0102", x: 1, y: 2, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0202", x: 2, y: 2, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0302", x: 3, y: 2, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0402", x: 4, y: 2, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0502", x: 5, y: 2, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0602", x: 6, y: 2, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0702", x: 7, y: 2, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0802", x: 8, y: 2, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0902", x: 9, y: 2, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0003", x: 0, y: 3, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0103", x: 1, y: 3, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0203", x: 2, y: 3, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0303", x: 3, y: 3, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0403", x: 4, y: 3, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0503", x: 5, y: 3, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0603", x: 6, y: 3, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0703", x: 7, y: 3, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0803", x: 8, y: 3, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0903", x: 9, y: 3, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0004", x: 0, y: 4, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0104", x: 1, y: 4, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0204", x: 2, y: 4, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0304", x: 3, y: 4, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0404", x: 4, y: 4, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0504", x: 5, y: 4, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0604", x: 6, y: 4, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0704", x: 7, y: 4, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0804", x: 8, y: 4, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0904", x: 9, y: 4, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0005", x: 0, y: 5, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0105", x: 1, y: 5, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0205", x: 2, y: 5, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0305", x: 3, y: 5, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0405", x: 4, y: 5, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0505", x: 5, y: 5, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0605", x: 6, y: 5, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0705", x: 7, y: 5, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0805", x: 8, y: 5, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0905", x: 9, y: 5, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0006", x: 0, y: 6, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0106", x: 1, y: 6, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0206", x: 2, y: 6, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0306", x: 3, y: 6, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0406", x: 4, y: 6, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0506", x: 5, y: 6, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0606", x: 6, y: 6, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0706", x: 7, y: 6, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0806", x: 8, y: 6, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0906", x: 9, y: 6, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0007", x: 0, y: 7, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0107", x: 1, y: 7, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0207", x: 2, y: 7, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0307", x: 3, y: 7, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0407", x: 4, y: 7, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0507", x: 5, y: 7, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0607", x: 6, y: 7, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0707", x: 7, y: 7, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0807", x: 8, y: 7, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0907", x: 9, y: 7, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0008", x: 0, y: 8, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0108", x: 1, y: 8, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0208", x: 2, y: 8, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0308", x: 3, y: 8, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0408", x: 4, y: 8, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0508", x: 5, y: 8, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0608", x: 6, y: 8, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0708", x: 7, y: 8, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0808", x: 8, y: 8, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0908", x: 9, y: 8, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0009", x: 0, y: 9, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0109", x: 1, y: 9, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0209", x: 2, y: 9, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0309", x: 3, y: 9, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0409", x: 4, y: 9, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0509", x: 5, y: 9, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0609", x: 6, y: 9, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0709", x: 7, y: 9, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0809", x: 8, y: 9, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag},
{ i: "0909", x: 9, y: 9, w: widthCell, h: heightCell,isResizable:false,isBounded:BoundedFlag}
];

How to prevent first/last bars from being cut off in a chart with time scale

How do I prevent the first and last bars from being cut off (showing half)?
I need to show the short month names on the x-axis. I've tried playing around with various min/max settings, but I can't seem to get it right.
var graphData = {
dates: [
'2016-06-01',
'2016-07-01',
'2016-08-01',
'2016-09-01',
'2016-10-01',
'2016-11-01',
'2016-12-01',
'2017-01-01',
'2017-02-01',
'2017-03-01',
'2017-04-01',
'2017-05-01'
],
wins: [23, 5, 13, 24, 8, 11, 23, 5, 13, 24, 8, 11],
draws: [2, 1, 2, 0, 2, 2, 3, 1, 2, 4, 0, 1],
losses: [3, 1, 2, 10, 8, 8, 3, 1, 2, 10, 8, 8],
winRates: [50, 40, 72, 30, 46, 80, 50, 40, 72, 30, 46, 80]
};
var winsMax = Math.max.apply(Math, graphData.wins);
var lossesMax = Math.max.apply(Math, graphData.losses);
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: "bar",
data: {
labels: graphData.dates.map((date) => moment(date)),
datasets: [
{
type: "bar",
backgroundColor: "green",
hoverBackgroundColor: "green",
data: graphData.wins,
yAxisID: "winsAndLosses"
},
{
type: "bar",
backgroundColor: "red",
hoverBackgroundColor: "red",
data: graphData.losses.map((i) => -i),
yAxisID: "winsAndLosses"
},
{
type: "line",
data: graphData.winRates,
fill: true,
backgroundColor: "gray",
pointRadius: 0,
pointHoverRadius: 0,
yAxisID: "winRate"
}
]
},
options: {
legend: {
display: false
},
scales: {
xAxes: [{
type: "time",
time: {
unit: "month",
displayFormats: {
month: "MMM"
}
},
stacked: true,
gridLines: {
display: false
},
ticks: {
callback: (label) => label.toUpperCase(),
fontSize: 10
}
}],
yAxes: [
{
id: "winsAndLosses",
stacked: true,
ticks: {
min: (lossesMax + 10) * -1,
max: winsMax + 10,
callback: (label) => Math.abs(label) // TODO: Localization (number formatting).
},
display: false
},
{
id: "winRate",
ticks: {
min: 0,
max: 100,
stepSize: 10,
callback: (label) => label + "%", // TODO: Localization (number formatting).
fontSize: 10
}
}
]
}
}
});
.myChartDiv {
max-width: 800px;
max-height: 400px;
}
<script src="https://npmcdn.com/chart.js#latest/dist/Chart.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<html>
<body>
<div class="myChartDiv">
<canvas id="myChart" width="800" height="400"></canvas>
</div>
</body>
</html>
There's a setting called offset which seems to work for me:
xAxes: [{
offset: true
}]
var graphData = {
dates: [
'2016-06-01',
'2016-07-01',
'2016-08-01',
'2016-09-01',
'2016-10-01',
'2016-11-01',
'2016-12-01',
'2017-01-01',
'2017-02-01',
'2017-03-01',
'2017-04-01',
'2017-05-01'
],
wins: [23, 5, 13, 24, 8, 11, 23, 5, 13, 24, 8, 11],
draws: [2, 1, 2, 0, 2, 2, 3, 1, 2, 4, 0, 1],
losses: [3, 1, 2, 10, 8, 8, 3, 1, 2, 10, 8, 8],
winRates: [50, 40, 72, 30, 46, 80, 50, 40, 72, 30, 46, 80]
};
var winsMax = Math.max.apply(Math, graphData.wins);
var lossesMax = Math.max.apply(Math, graphData.losses);
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: "bar",
data: {
labels: graphData.dates.map((date) => moment(date)),
datasets: [
{
type: "bar",
backgroundColor: "green",
hoverBackgroundColor: "green",
data: graphData.wins,
yAxisID: "winsAndLosses"
},
{
type: "bar",
backgroundColor: "red",
hoverBackgroundColor: "red",
data: graphData.losses.map((i) => -i),
yAxisID: "winsAndLosses"
},
{
type: "line",
data: graphData.winRates,
fill: true,
backgroundColor: "gray",
pointRadius: 0,
pointHoverRadius: 0,
yAxisID: "winRate"
}
]
},
options: {
legend: {
display: false
},
scales: {
xAxes: [{
type: "time",
time: {
unit: "month",
displayFormats: {
month: "MMM"
}
},
stacked: true,
gridLines: {
display: false
},
ticks: {
callback: (label) => label.toUpperCase(),
fontSize: 10
},
offset:true
}],
yAxes: [
{
id: "winsAndLosses",
stacked: true,
ticks: {
min: (lossesMax + 10) * -1,
max: winsMax + 10,
callback: (label) => Math.abs(label) // TODO: Localization (number formatting).
},
display: false
},
{
id: "winRate",
ticks: {
min: 0,
max: 100,
stepSize: 10,
callback: (label) => label + "%", // TODO: Localization (number formatting).
fontSize: 10
}
}
]
}
}
});
.myChartDiv {
max-width: 800px;
max-height: 400px;
}
<script src="https://npmcdn.com/chart.js#latest/dist/Chart.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.min.js"></script>
<html>
<body>
<div class="myChartDiv">
<canvas id="myChart" width="800" height="400"></canvas>
</div>
</body>
</html>

How do I draw line after receiving data - Route from GPS Trace

I just started using Here Maps. Before I used Google Direction, I want to try use 'Here Maps' API. This is example JSON result. After I got this result, How do I implement this into Polyline or Direction (MAP Here)? Thanks
{
RouteLinks: [
{
linkId: 25664478,
functionalClass: 5,
shape: "51.1017723 0.3934907 51.1018066 0.3933491 51.1018295 0.39326",
linkLength: 15.575699313408467
},
{
linkId: 25664473,
functionalClass: 4,
shape: "51.1018295 0.39326 51.1022491 0.39348",
linkLength: 44.17562556306323
},
{
linkId: 25664459,
functionalClass: 4,
shape: "51.1022491 0.39348 51.1022987 0.39351",
linkLength: 5.305684979980019
},
{
linkId: 781742854,
functionalClass: 4,
shape: "51.1022987 0.39351 51.1025505 0.39365",
linkLength: 26.670487136749067
},
{
linkId: 781742855,
functionalClass: 4,
shape: "51.1025505 0.39365 51.1027794 0.39378",
linkLength: 24.302012297623005
},
{
linkId: 25664450,
functionalClass: 4,
shape: "51.1027794 0.39378 51.1030807 0.39403",
linkLength: 33.974229462422905
},
{
linkId: 25664444,
functionalClass: 4,
shape: "51.1030807 0.39403 51.103241 0.39413",
linkLength: 17.215963662407898
},
{
linkId: 25664440,
functionalClass: 4,
shape: "51.103241 0.39413 51.1033783 0.39421 51.1035385 0.39433 51.1036797 0.39445",
linkLength: 48.32839625333388
},
{
linkId: 25664427,
functionalClass: 4,
shape: "51.1036797 0.39445 51.1038017 0.39454",
linkLength: 13.445306290244636
},
{
linkId: 860272608,
functionalClass: 4,
shape: "51.1038017 0.39454 51.1039391 0.39465",
linkLength: 15.378381014646559
},
{
linkId: 860272609,
functionalClass: 4,
shape: "51.1039391 0.39465 51.1041908 0.39484",
linkLength: 27.85427285471891
},
{
linkId: 781742870,
functionalClass: 4,
shape: "51.1041908 0.39484 51.1043282 0.39494 51.1045609 0.39506",
linkLength: 39.56626207722863
},
{
linkId: 781742871,
functionalClass: 4,
shape: "51.1045609 0.39506 51.1047287 0.39515 51.1050262 0.3953021",
linkLength: 48.951382959921716
}
],
TracePoints: [
{
confidenceValue: 1, linkIdMatched: 25664478, matchDistance: 1.46,
routeLinkSeqNrMatched: 0, lat: 51.10177, lon: 0.39349,
elevation: 0, speedMps: 0, headingDegreeNorthClockwise: 10000,
latMatched: 51.10178065190155, lonMatched: 0.3934977183445852,
timestamp: 0, headingMatched: 114.46568884011239,
minError: 1.3027890756593314
},
{
confidenceValue: 1, linkIdMatched: 25664478, matchDistance: 1.57,
routeLinkSeqNrMatched: 0, lat: 51.10181, lon: 0.39335,
elevation: 0, speedMps: 0, headingDegreeNorthClockwise: 10000,
latMatched: 51.10182, lonMatched: 0.39336,
timestamp: 0, headingMatched: -65.53429247174023,
minError: 1000000
},
{
confidenceValue: 1, linkIdMatched: 781742854, matchDistance: 1,
routeLinkSeqNrMatched: 4, lat: 51.10255, lon: 0.39366,
elevation: 0, speedMps: 0, headingDegreeNorthClockwise: 10000,
latMatched: 51.102547928304084, lonMatched: 0.3936687569824506,
timestamp: 0, headingMatched: 20.644254301899522,
minError: 0.6541474931313044
},
{
confidenceValue: 1, linkIdMatched: 860272608, matchDistance: 4.59,
routeLinkSeqNrMatched: 10, lat: 51.10398, lon: 0.39466,
elevation: 0, speedMps: 0, headingDegreeNorthClockwise: 10000,
latMatched: 51.10394, lonMatched: 0.39465,
timestamp: 0, headingMatched: 25.217234923243595,
minError: 1.2405405512432781
},
{
confidenceValue: 1, linkIdMatched: 1022687693, matchDistance: 1.33,
routeLinkSeqNrMatched: 14, lat: 51.10501, lon: 0.39533,
elevation: 0, speedMps: 0, headingDegreeNorthClockwise: 10000,
latMatched: 51.105012239590245, lonMatched: 0.39531827230152644,
timestamp: 0, headingMatched: 16.91643828307876,
minError: 0.8568378930601925
}
],
Warnings: [
{
"tracePointSeqNum": -1,
"routeLinkSeqNum": 3,
"category": 3,
"text": "Entering link 781742854 into forbidden driving direction"
}
],
MapVersion: "2013Q4" }
*linkId,shape is like that trip points which is given by Heremap api step1.
You just draw route by polyline function.
addPolylineToMap(map,linkId);
function addPolylineToMap(map,linkId) {
for (j = 0; j < (shape.length - 1); j = j + 2) {
var strip = new H.geo.Strip();
strip.pushPoint({lat: shape[j],lng: shape[j+1]});
}
}

highcharts, four aeraranges with linear gradients

I'm trying to create chart in Highcharts with four arearanges and one line. I'm doing my best to get something like on image:
arearanges
I'v managed to do something like this:
$(function () {
var rangesHI = [
[1246406400000, 90, 75],
[1248998400000, 90, 75]
],
rangesME = [
[1246406400000, 75, 60],
[1248998400000, 75, 60]
],
rangesNO = [
[1246406400000, 60, 35],
[1248998400000, 60, 35]
],
rangesLO = [
[1246406400000, 35, 15],
[1248998400000, 35, 15]
],
averages = [
[1246406400000, 31.5],
[1246492800000, 32.1],
[1246579200000, 33],
[1246665600000, 33.8],
[1246752000000, 31.4],
[1246838400000, 31.3],
[1246924800000, 38.3],
[1247011200000, 35.4],
[1247097600000, 36.4],
[1247184000000, 47.7],
[1247270400000, 47.5],
[1247356800000, 37.6],
[1247443200000, 47.7],
[1247529600000, 46.8],
[1247616000000, 47.7],
[1247702400000, 46.3],
[1247788800000, 47.8],
[1247875200000, 48.1],
[1247961600000, 57.2],
[1248048000000, 54.4],
[1248134400000, 53.7],
[1248220800000, 55.7],
[1248307200000, 54.6],
[1248393600000, 55.3],
[1248480000000, 45.3],
[1248566400000, 55.8],
[1248652800000, 65.2],
[1248739200000, 74.8],
[1248825600000, 44.4],
[1248912000000, 55],
[1248998400000, 43.6]
];
$('#container').highcharts({
title: {
text: null
},
xAxis: {
type: 'datetime'
},
yAxis: {
max:90,
min:20,
title: {
text: null
}
},
series: [{
name: 'RH',
data: averages,
zIndex: 1
}, {
data: rangesHI,
type: 'arearange',
lineWidth: 0,
fillColor: {
linearGradient: [0, 0, 0, 300],
stops: [
[0, 'rgba(255,0,0, 0.2)'],
[1, 'rgba(255,0,0, 1)']
]
},
zIndex: 0
}, {
data: rangesME,
type: 'arearange',
lineWidth: 0,
fillColor: {
linearGradient: [300, 0, 300, 400],
stops: [
[0, 'rgba(237,230,126, 0.2)'],
[1, 'rgba(237,230,126, 1)']
]
},
zIndex: 0
}, {
data: rangesNO,
type: 'arearange',
lineWidth: 0,
fillColor: {
linearGradient: [500, 0, 500, 600],
stops: [
[0, 'rgba(104,217,91, 0.2)'],
[1, 'rgba(104,217,91, 0.7)']
]
},
zIndex: 0
}, {
data: rangesLO,
type: 'arearange',
lineWidth: 0,
fillColor: {
linearGradient: [0, 0, 0, 220],
stops: [
[0, 'rgba(91,187,217, 0.2)'],
[1, 'rgba(91,187,217, 0.7)']
]
},
zIndex: 0
}]
}, function (chart) {
chart.renderer.text('EKSTREMALNA', 80, 95).css({
fontSize: '16pt',
color: 'rgba(255,0,0, 1)'
}).add();
chart.renderer.text('WYSOKA', 80, 145).css({
fontSize: '16pt',
color: 'rgba(237,230,126, 1)'
}).add();
chart.renderer.text('KOMFORTOWA', 80, 225).css({
fontSize: '16pt',
color: 'rgba(104,217,91, 01)'
}).add();
chart.renderer.text('NISKA', 80, 305).css({
fontSize: '16pt',
color: 'rgba(91,187,217, 1)'
}).add();
});
http://jsfiddle.net/qazopap4/1/ but this is far from what I'v expected.
I can't make linear gradient for each arearange separately.
You can use plotBands which allows you to apply gradients.
yAxis: {
plotBands: [{
from: 60,
to: 90,
color: {
linearGradient: [0, 0, 0, 300],
stops: [
[0, 'rgba(255,0,0, 0.2)'],
[1, 'rgba(255,0,0, 1)']
]
}
}],
max: 90,
min: 20,
title: {
text: null
}
},
Example: http://jsfiddle.net/pag5qgsm

Resources