Reputation: 1237
I have developed a mobile application which displays line graph using amcharts. I took example of this link please visit http://jsfiddle.net/ATQUm/825/ and developed my application. Now i have stuck with setting themes. It contains different themes like "dark" , "light" , "chalk" etc. Each of them have it own JS. As a example i m attaching a link of dark.js.
var chart;
var chartData = [];
var chartCursor;
var day = 0;
var firstDate = new Date();
firstDate.setDate(firstDate.getDate() - 500);
// generate some random data, quite different range
function generateChartData() {
for (day = 0; day < 50; day++) {
var newDate = new Date(firstDate);
newDate.setDate(newDate.getDate() + day);
var visits = Math.round(Math.random() * 40) - 20;
chartData.push({
date: newDate,
visits: visits
});
}
}
// create chart
AmCharts.ready(function() {
// generate some data first
generateChartData();
// SERIAL CHART
chart = new AmCharts.AmSerialChart();
chart.pathToImages = "http://www.amcharts.com/lib/images/";
chart.marginTop = 0;
chart.marginRight = 10;
chart.autoMarginOffset = 5;
chart.zoomOutButton = {
backgroundColor: '#000000',
backgroundAlpha: 0.15
};
chart.dataProvider = chartData;
chart.categoryField = "date";
// AXES
// category
var categoryAxis = chart.categoryAxis;
categoryAxis.parseDates = true; // as our data is date-based, we set parseDates to true
categoryAxis.minPeriod = "DD"; // our data is daily, so we set minPeriod to DD
categoryAxis.dashLength = 1;
categoryAxis.gridAlpha = 0.15;
categoryAxis.axisColor = "#DADADA";
// value
var valueAxis = new AmCharts.ValueAxis();
valueAxis.axisAlpha = 0.2;
valueAxis.dashLength = 1;
chart.addValueAxis(valueAxis);
// GRAPH
var graph = new AmCharts.AmGraph();
graph.title = "red line";
graph.valueField = "visits";
graph.bullet = "round";
graph.bulletBorderColor = "#FFFFFF";
graph.bulletBorderThickness = 2;
graph.lineThickness = 2;
graph.lineColor = "#b5030d";
graph.negativeLineColor = "#0352b5";
graph.hideBulletsCount = 50; // this makes the chart to hide bullets when there are more than 50 series in selection
chart.addGraph(graph);
// CURSOR
chartCursor = new AmCharts.ChartCursor();
chartCursor.cursorPosition = "mouse";
chart.addChartCursor(chartCursor);
// SCROLLBAR
var chartScrollbar = new AmCharts.ChartScrollbar();
chartScrollbar.graph = graph;
chartScrollbar.scrollbarHeight = 40;
chartScrollbar.color = "#FFFFFF";
chartScrollbar.autoGridCount = true;
chart.addChartScrollbar(chartScrollbar);
// WRITE
chart.write("chartdiv");
// set up the chart to update every second
setInterval(function () {
// normally you would load new datapoints here,
// but we will just generate some random values
// and remove the value from the beginning so that
// we get nice sliding graph feeling
// remove datapoint from the beginning
chart.dataProvider.shift();
// add new one at the end
day++;
var newDate = new Date(firstDate);
newDate.setDate(newDate.getDate() + day);
var visits = Math.round(Math.random() * 40) - 20;
chart.dataProvider.push({
date: newDate,
visits: visits
});
chart.validateData();
}, 1000);
});
visit "http://extra.amcharts.com/tutorials/themes/amcharts/themes/dark.js " I tried setting its theme with the reference of this visit "http://www.amcharts.com/tutorials/working-with-themes/ " but i\I am not getting expected result. What mistake i am doing? Please suggest me solutions so that i could rectify my mistake.
Upvotes: 1
Views: 5435
Reputation: 1102
For the newer amCharts 5, you could easily create a custom theme. The following examples shows how to set custom colors:
// Create an amChart root, where `chartdiv` is a reactive component in our case.
let root = am5.Root.new(chartdiv);
// Create our own custom theme.
class CustomTheme extends am5.Theme {
setupDefaultRules() {
super.setupDefaultRules();
this.rule("ColorSet").setAll({
colors: [
am5.Color.fromString("#006d95"),
am5.Color.fromString("#323738"),
am5.Color.fromString("#009f9a"),
am5.Color.fromString("#ff617c"),
am5.Color.fromString("#FFD700"),
am5.Color.fromString("#007fad"),
am5.Color.fromString("#ff5159"),
am5.Color.fromString("#008780"),
],
reuse: true
});
}
}
// Use the theme
root.setThemes([
CustomTheme.new(root)
]);
Upvotes: 0
Reputation: 6025
problems:
1) you are using v2 of amcharts which doesn't support themes; 2) path to theme file is wrong 3) you do not set theme anywhere.
Fixed fiddle: http://jsfiddle.net/ATQUm/830/
Script to be included:
<script src="http://www.amcharts.com/lib/3/amcharts.js" type="text/javascript"></script>
<script src="http://www.amcharts.com/lib/3/serial.js" type="text/javascript"></script>
<script src="http://www.amcharts.com/lib/3/themes/dark.js"></script>
theme line:
AmCharts.theme = AmCharts.themes.dark;
Upvotes: 3