HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
97
1
anychart.onDocumentReady(function() {
2
3
// chart type
4
var chart = anychart.polar();
5
6
chart.title().text("Polar Chart");
7
8
chart.line([
9
{x: 0, value: 0},
10
{x: 10, value: 1},
11
{x: 20, value: 2},
12
{x: 30, value: 3},
13
{x: 40, value: 4},
14
{x: 50, value: 5},
15
{x: 60, value: 6},
16
{x: 70, value: 7},
17
{x: 80, value: 8},
18
{x: 90, value: 9},
19
{x: 100, value: 10}
20
]).tooltip().enabled(false);
21
22
chart.xScale().maximum(100).ticks().interval(10);
23
24
chart.yScale().ticks().interval(2);
25
26
chart.xAxis().labels().fontWeight(900);
27
chart.container("container").draw();
28
29
// create JSON config
30
chartJson = chart.toJson();
31
32
var body = document.getElementsByTagName("body")[0];
33
34
var button = document.createElement("div");
35
button.style.padding = "2px";
36
button.style.textAlign = "center";
37
button.style.position = "fixed";
38
button.style.top = "2px";
39
button.style.right = "2px";
40
button.style.backgroundColor = "#444444";
41
button.style.border = "1px solid #444444";
42
button.style.borderRadius = "5px";
43
button.style.color = "white";
44
button.style.fontFamily = "Tahoma";
45
button.style.cursor = "pointer";
46
button.style.MozUserSelect= "none";
47
button.style.KhtmlUserSelect= "none";
48
button.style.WebkitUserSelect= "none";
49
button.style.userSelect= "none";
50
button.innerHTML = "Show<br/>JSON config";
51
button.onclick = showJson;
52
body.appendChild(button);
53
54
function showJson(){
55
var display = document.createElement("div");
56
display.style.position = "absolute";
57
display.style.width = "60%";
58
display.style.height = "40%";
59
display.style.resize = "both";
60
display.style.padding = "3px";
61
display.style.top = 0;
62
display.style.left = 0;
63
display.style.right = 0;
64
display.style.backgroundColor = "rgba(255, 255, 255, 0.9)";
65
display.style.border = "1px solid #999999";
66
display.style.zIndex = 90;
67
display.style.whiteSpace = "pre";
68
display.style.overflow = "scroll";
69
display.style.margin = "auto";
70
71
// parse JSON
72
display.innerHTML = highLighter(JSON.stringify(chartJson, undefined, 2));
73
body.appendChild(display);
74
button.innerHTML = "Hide<br/>JSON config";
75
button.onclick = function(){
76
body.removeChild(display);
77
button.onclick = showJson;
78
button.innerHTML = "Show<br/>JSON config";
79
};
80
}
81
82
// highlight JSON
83
function highLighter(strJson){
84
json = strJson.replace(/&/g, "&").replace(/</g,"<").replace(/>/g, ">");
85
return strJson.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
86
var cls = "number";
87
if (/^"/.test(match)) {
88
if (/:$/.test(match)) {
89
cls = "key";
90
return "<span style=\"color: #718C00;\">" + match.substr(0, (match.length - 1)) + "<a style=\"color:black;\">:</a></span>";
91
}
92
}
93
return "<span style='color: darkorange;'>" + match + "</span>";
94
});
95
}
96
97
});