As you see, the line graph can use different color for ups and downs. If previous value is bigger than current value, the line will use <strong>negativeLineColor</strong>. This feature can also be used with <strong>step </strong>and <strong>column </strong>graphs. To use it, you must set <strong>useNegativeColorIfDown </strong>to true. In case you define <strong>openField</strong> for the graph, values will be compared to <strong>openField</strong> instead of previous values.
var chartData = generatechartData();
function generatechartData() {
var chartData = [];
var firstDate = new Date();
firstDate.setDate(firstDate.getDate() - 150);
for (var i = 0; i < 150; i++) {
// we create date objects here. In your data, you can have date strings
// and then set format of your dates using chart.dataDateFormat property,
// however when possible, use date objects, as this will speed up chart rendering.
var newDate = new Date(firstDate);
newDate.setDate(newDate.getDate() + i);
var visits = Math.round(Math.random() * 100 - 50);
chartData.push({
date: newDate,
visits: visits
});
}
return chartData;
}
var chart = AmCharts.makeChart("chartdiv", {
"theme": "light",
"type": "serial",
"autoMargins": false,
"marginLeft":8,
"marginRight":8,
"marginTop":10,
"marginBottom":26,
"pathToImages": "http://www.amcharts.com/lib/3/images/",
"dataProvider": chartData,
"valueAxes": [{
"id":"v1",
"axisAlpha": 0,
"inside": true
}],
"graphs": [{
"useNegativeColorIfDown":true,
"balloonText": "[[category]]<br><b>value: [[value]]</b>",
"bullet": "round",
"bulletBorderAlpha": 1,
"bulletBorderColor": "#FFFFFF",
"hideBulletsCount": 50,
"lineThickness": 2,
"lineColor": "#fdd400",
"negativeLineColor": "#67b7dc",
"valueField": "visits"
}],
"chartScrollbar": {
},
"chartCursor": {
"valueLineEnabled":true,
"valueLineBalloonEnabled":true
},
"categoryField": "date",
"categoryAxis": {
"parseDates": true,
"axisAlpha": 0,
"minHorizontalGap":60
}
});
chart.addListener("dataUpdated", zoomChart);
//zoomChart();
function zoomChart(){
if(chart.zoomToIndexes){
chart.zoomToIndexes(130, chartData.length - 1);
}
}
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.