.myEvents {
position: absolute;
text-align: center;
width: 20px;
height: 20px;
line-height: 20px;
color: white;
}
/*style dividents to be a blue circle*/
.myEvents.dividend {
background-color: blue;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-ms-border-radius: 50%;
border-radius: 50%;
}
/*style news to be a small red square*/
.myEvents.news {
background-color: red;
width: 15px;
height: 15px;
line-height: 15px;
}
.myEvents.earnings {
background-color: purple;
}
JavaScript
import { CIQ } from "https://jsfiddle.chartiq.com/chart/js/advanced.js";
// Activate the License Key
import getLicenseKey from "https://jsfiddle.chartiq.com/chart/key.js";
getLicenseKey(CIQ);
import sampleData from "https://jsfiddle.chartiq.com/chart/examples/data/STX_SAMPLE_DAILY.js";
const stxx = new CIQ.ChartEngine({
container: document.querySelector(".chartContainer")
});
function showEvents(typeOfEvent) {
// see how you can set the vertical location for the marker based on event type
// by setting the 'yPoistioner'
// - 'earnings' will display on the very top,
// - 'news' will display on the very bottom
// - all others default to 'above_candle'
var yPositioner;
if (typeOfEvent == 'news') yPositioner = 'bottom'
else if (typeOfEvent == 'earnings') yPositioner = 'top'
// This sample code just randomly goes trough the masterData to pick event dates to display.
// In your chart, this data will probably come from a markers feed.
if (!stxx.masterData) return;
for (var i = 0; i < stxx.masterData.length; i += Math.floor(Math.random() * 20) + 1) {
let newNode = document.querySelector("#stxEventPrototype").cloneNode(true);
newNode.id = null;
newNode.innerHTML = typeOfEvent.toUpperCase().charAt(0);
newNode.classList.add(typeOfEvent);
new CIQ.Marker({
stx: stxx,
xPositioner: "date",
x: stxx.masterData[i].DT,
yPositioner: yPositioner,
label: typeOfEvent,
node: newNode
});
}
// first add all the markers, then draw them all at once.
stxx.draw();
}
var eventsAreDisplayed = {};
window.toggleEvents = function(typeOfEvent) { // This is called by the menu item
if (eventsAreDisplayed[typeOfEvent]) {
eventsAreDisplayed[typeOfEvent] = false;
CIQ.Marker.removeByLabel(stxx, typeOfEvent);
} else {
showEvents(typeOfEvent);
eventsAreDisplayed[typeOfEvent] = true;
}
}
stxx.loadChart("SPY", sampleData);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.