From Dark and Darker Wiki

mNo edit summary
(Attempting to make y-axis label larger.)
 
(19 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>
<includeonly>
<div>
<div style="aspect-ratio: 2">
    <canvas id="<!--{$uniqueId|escape:'html'}-->"></canvas>
<canvas id="<!--{$uniqueId|escape:'html'}-->"></canvas>
</div>
</div>
<script>
<script>
    var datasets  = JSON.parse('<!--{$datasets|default:'[{"x": 0,"y": 0}]'|escape:'quotes'}-->');
var datasets  = JSON.parse('<!--{$datasets|escape:'quotes'}-->');
    var yAxisLabel= '<!--{$yAxisLabel|default:''|escape:'quotes'}-->';
var title    ='<!--{$title|default:''|escape:'quotes'}-->';
    var xAxisLabel= '<!--{$xAxisLabel|default:''|escape:'quotes'}-->';
var yAxisLabel= '<!--{$yAxisLabel|default:''|escape:'quotes'}-->';
    var gridColor = '<!--{$gridColor|escape:'quotes'}-->';
var xAxisLabel= '<!--{$xAxisLabel|default:''|escape:'quotes'}-->';
    var axisColor = '<!--{$axisColor|escape:'quotes'}-->';
var gridColor = '<!--{$gridColor|default:'#80808080'|escape:'quotes'}-->';
    var fontColor = '<!--{$fontColor|escape:'quotes'}-->';
var axisColor = '<!--{$axisColor|escape:'quotes'}-->';
var fontColor = '<!--{$fontColor|default:'white'|escape:'quotes'}-->';


    var yAxisBoolean = true
var hasTitle = true
    if (yAxisLabel == "") {
if (title == "") {
        yAxisBoolean = false;
hasTitle = false;
    }
}


    var xAxisBoolean = true
var yAxisBoolean = true
    if (xAxisLabel == "") {
if (yAxisLabel == "") {
        xAxisBoolean = false;
yAxisBoolean = false;
    }
}


    if (gridColor == "") {
var xAxisBoolean = true
        gridColor = "lightgray";
if (xAxisLabel == "") {
    }
xAxisBoolean = false;
}


    if (axisColor == "") {
if (axisColor == "") {
        axisColor = gridColor;
axisColor = gridColor;
    }
}


    if (fontColor == "") {
new Chart(document.getElementById('<!--{$uniqueId|escape:'html'}-->'), {
        fontColor = "gray";
type: "line",
    }
data: datasets,
options: {
plugins:{
title: {
display:hasTitle,
text:title,
font: {
size: 22
},
color:fontColor
},
legend: {
display:hasTitle
},
tooltip: {
callbacks: {
label: (ctx) => (`${ctx.dataset.label}: ${ctx.raw}`)
}
}
},
scales: {
y: {
title:{
text:yAxisLabel,
display:yAxisBoolean,
color:fontColor,
font: {
size: 18
}
},
grid: {
color:gridColor
},
border: {
color:axisColor
},
ticks: {
color:fontColor,
font: {
size: 18
}
}
},
x: {
title:{
text:xAxisLabel,
display:xAxisBoolean,
color:fontColor
},
grid: {
color:gridColor
},
border: {
color:axisColor
},
ticks: {
color:fontColor
}
}
}
}
});
</script></includeonly><noinclude>
==Parameters==
<pre style="width:fit-content">uniqueId</pre>
*Determines canvas element name
*Name needs to be unique if multiple widgets are to be displayed on the same page.
<pre style="width:fit-content">title</pre>
*Default: <code>""</code> empty string
*String of text to display as the title of the graph.
*This string also serves to detemine whether or not to show the legend.<br>If no string is provided both the legend and the title are not displayed.
<pre style="width:fit-content">yAxisLabel</pre>
*Default: <code>""</code> empty string
*String of text to display on the y-axis. Text is rendered vertically, bottom to top.
<pre style="width:fit-content">xAxisLabel</pre>
*Default: <code>""</code> empty string
*String of text to display on the x-axis.
<pre style="width:fit-content">gridColor</pre>
*Default: <code>'#80808080'</code>
<pre style="width:fit-content">axisColor</pre>
*Default: <code>var gridColor</code>
<pre style="width:fit-content">fontColor</pre>
*Default: <code>'white'</code>
<pre style="width:fit-content">datasets</pre>
*String of text that is a properly formatted JSON object when parsed by <code>JSON.parse()</code>. The graph will not render if an improper JSON object is passed.<br>It is recommended that you check the string format with some sort of tool like JSON Lint, or whatever else you prefer.
*The first set of objects within the JSON object must have the "datasets" array pair.
**For specifics on what options and formats are available, please see [https://www.chartjs.org/docs/3.9.1/general/accessibility.html the official Chart.js documentation.]


    new Chart(document.getElementById('<!--{$uniqueId|escape:'html'}-->'), {
 
        type: "line",
==Example==
        data: datasets,
<pre>{{#widget:DatasetsChart|uniqueId=ExampleChart|title=This String Becomes the Title|datasets={"labels":[0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500],"datasets":[{"label":"Luck Grade 5","data":[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],"borderColor":"#AD5AFF","backgroundColor":"#AD5AFFBB"},{"label":"Luck Grade 6","data":[1, 3, 6, 8, 10, 12, 14, 16, 18, 20, 22],"borderColor":"#F7A22D","backgroundColor":"#F7A22DBB"}]}|}}</pre>
        options: {
{{#widget:DatasetsChart|uniqueId=ExampleChart|title=This String Becomes the Title|datasets={"labels":[0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500],"datasets":[{"label":"Luck Grade 5","data":[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],"borderColor":"#AD5AFF","backgroundColor":"#AD5AFFBB"},{"label":"Luck Grade 6","data":[1, 3, 6, 8, 10, 12, 14, 16, 18, 20, 22],"borderColor":"#F7A22D","backgroundColor":"#F7A22DBB"}]}|}}
            plugins:{
</noinclude>
                legend: {
                    title: {
                        text: "Luck's Effect per Luck Grade",
                        display:true
                    }
                }
            },
            scales: {
                y: {
                    title:{
                        text:yAxisLabel,
                        display:yAxisBoolean,
                    },
                    grid: {
                        color: gridColor
                    },
                    border: {
                        color: axisColor
                    },
                    ticks: {
                        color: fontColor
                    }
                },
                x: {
                    title:{
                        text:xAxisLabel,
                        display:xAxisBoolean,
                    },
                    grid: {
                        color: gridColor
                    },
                    border: {
                        color: axisColor
                    },
                    ticks: {
                        color: fontColor
                    }
                }
            }
        }
    });
</script></includeonly><noinclude>{{#widget:TestChart|uniqueId=LuckGraph|datasets={"labels":[0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500],"datasets":[{"label":"Luck Grade 5","data":[1, 0.9952777384613406, 0.9931949559745359, 0.9920650871875678, 0.9913146604346158, 0.9908598744095304, 0.9905380145769638, 0.9903319527048099, 0.9902161906264793, 0.990116829157925, 0.9900889064632575],"borderColor":"#AD5AFF","backgroundColor":"#AD5AFFBB"},{"label":"Luck Grade 6","data":[1, 1.0409562901295728, 1.059050220737091, 1.068841599202489, 1.0753775855453624, 1.0793127027043983, 1.082114963847391, 1.0838937007227782, 1.08489821682184, 1.0857604179521987, 1.086010944296338],"borderColor":"#F7A22D","backgroundColor":"#F7A22DBB"},{"label":"Luck Grade 8","data":[1, 1.0563969273132003, 1.0810019756579428, 1.0945677602964938, 1.1032822909763158, 1.1087969788026875, 1.112544013446742, 1.1150809500621008, 1.1164588922202936, 1.1176416142169567, 1.117899919639782],"borderColor":"#E3D88C","backgroundColor":"#E3D88CBB"}]}|yAxisLabel=Multiplicative Effect|xAxisLabel=Luck}}</noinclude>

Latest revision as of 07:19, 23 June 2024

Parameters

uniqueId
  • Determines canvas element name
  • Name needs to be unique if multiple widgets are to be displayed on the same page.
title
  • Default: "" empty string
  • String of text to display as the title of the graph.
  • This string also serves to detemine whether or not to show the legend.
    If no string is provided both the legend and the title are not displayed.
yAxisLabel
  • Default: "" empty string
  • String of text to display on the y-axis. Text is rendered vertically, bottom to top.
xAxisLabel
  • Default: "" empty string
  • String of text to display on the x-axis.
gridColor
  • Default: '#80808080'
axisColor
  • Default: var gridColor
fontColor
  • Default: 'white'
datasets
  • String of text that is a properly formatted JSON object when parsed by JSON.parse(). The graph will not render if an improper JSON object is passed.
    It is recommended that you check the string format with some sort of tool like JSON Lint, or whatever else you prefer.
  • The first set of objects within the JSON object must have the "datasets" array pair.


Example

{{#widget:DatasetsChart|uniqueId=ExampleChart|title=This String Becomes the Title|datasets={"labels":[0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500],"datasets":[{"label":"Luck Grade 5","data":[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],"borderColor":"#AD5AFF","backgroundColor":"#AD5AFFBB"},{"label":"Luck Grade 6","data":[1, 3, 6, 8, 10, 12, 14, 16, 18, 20, 22],"borderColor":"#F7A22D","backgroundColor":"#F7A22DBB"}]}|}}