igDataChart with horizontal target line workaround
by georgianastasov
HTML
<script src="https://igniteui.com/js/modernizr.min.js"></script>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
<script src="https://cdn-na.infragistics.com/igniteui/latest/js/infragistics.core.js"></script>
<script src="https://cdn-na.infragistics.com/igniteui/latest/js/infragistics.dv.js"></script>
<script src="https://igniteui.com/js-data/world-energy-production"></script>
<link href="https://cdn-na.infragistics.com/igniteui/latest/css/themes/infragistics/infragistics.theme.css" rel="stylesheet"></link>
<link href="https://cdn-na.infragistics.com/igniteui/latest/css/structure/infragistics.css" rel="stylesheet"></link>
<link href="https://cdn-na.infragistics.com/igniteui/latest/css/structure/modules/infragistics.ui.chart.css" rel="stylesheet"></link>
<div>
<div>
<div id="chart" class="chart"></div>
<div id="legend" class="legend"></div>
</div>
</div>
CSS
.tooltip { margin: 0px 5px 0px 5px; }
.chart {
display: inline-block;
}
.legend {
display: inline-block;
}
.ui-chart-legend-item-text{
font-size: 1rem !important;
}
JavaScript
$(function () {
var data = [{Year: 2023, PG1: 0, PG2: 0, PG3: 0, PG4: 0, National: 20},{Year: 2023, PG1: 20, PG2: 40, PG3: 60, PG4: 40, National: 20},{Year: 2023, PG1: 0, PG2: 0, PG3: 0, PG4: 0, National: 20}];
$("#chart").igDataChart({
dataSource: data,
width: "700px",
height: "450px",
title: "Energy Production Per Country",
legend: { element: "legend" },
horizontalZoomable: true,
verticalZoomable: true,
axes: [{
type: "categoryX",
name: "XAxis",
strokeThickness: 5,
title: "Year " + data[0].Year
}, {
type: "numericY",
name: "YAxis",
minimumValue: 0,
maximumValue: 100,
strokeThickness: 5,
title: "Quadrillion Btu"
}],
series: [
CreateColumnSeries("PG1", "PG1"),
CreateColumnSeries("PG2", "PG2"),
CreateColumnSeries("PG3", "PG3"),
CreateColumnSeries("PG4", "PG4"),
CreateLineSeries("National", "National"),
],
});
function CreateLineSeries(seriesMemberPath, seriesTitle) {
var series = {
type: "line",
markerType: "none",
xAxis: "XAxis",
yAxis: "YAxis",
name: seriesMemberPath + "series",
title: seriesTitle,
valueMemberPath: seriesMemberPath,
isTransitionInEnabled: true,
isHighlightingEnabled: true,
showTooltip: true,
thickness: 3,
brush: "#000000"
}
...