primevue-mirror/pages/chart/BarChartDoc.vue

477 lines
14 KiB
Vue
Raw Normal View History

2022-09-09 20:41:18 +00:00
<template>
2022-12-20 17:28:51 +00:00
<AppDoc name="ChartDemo" :sources="sources" :dependencies="{ 'chart.js': '3.3.2' }" component="Chart" github="chart/BarChartDemo.vue" />
2022-09-09 20:41:18 +00:00
</template>
<script>
export default {
data() {
return {
sources: {
'options-api': {
tabName: 'Options API Source',
content: `
<template>
<div>
<div class="card">
<h5>Vertical</h5>
<Chart type="bar" :data="basicData" :options="basicOptions" />
</div>
<div class="card">
<h5>Horizontal</h5>
<Chart type="bar" :data="basicData" :options="horizontalOptions" />
</div>
<div class="card">
<h5>Multi Axis</h5>
<Chart type="bar" :data="multiAxisData" :options="multiAxisOptions "/>
</div>
<div class="card">
<h5>Stacked</h5>
<Chart type="bar" :data="stackedData" :options="stackedOptions" />
</div>
</div>
</template>
<script>
export default {
data() {
return {
basicData: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [
{
label: 'My First dataset',
backgroundColor: '#42A5F5',
data: [65, 59, 80, 81, 56, 55, 40]
},
{
label: 'My Second dataset',
backgroundColor: '#FFA726',
data: [28, 48, 40, 19, 86, 27, 90]
}
]
},
multiAxisData: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'Dataset 1',
backgroundColor: ['#EC407A','#AB47BC','#42A5F5','#7E57C2','#66BB6A','#FFCA28','#26A69A'],
yAxisID: 'y-axis-1',
data: [65, 59, 80, 81, 56, 55, 10]
}, {
label: 'Dataset 2',
backgroundColor: '#78909C',
yAxisID: 'y-axis-2',
data: [28, 48, 40, 19, 86, 27, 90]
}]
},
stackedData: {
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
type: 'bar',
label: 'Dataset 1',
backgroundColor: '#42A5F5',
data: [50,25,12,48,90,76,42]
}, {
type: 'bar',
label: 'Dataset 2',
backgroundColor: '#66BB6A',
data: [21,84,24,75,37,65,34]
}, {
type: 'bar',
label: 'Dataset 3',
backgroundColor: '#FFA726',
data: [41,52,24,74,23,21,32]
}]
},
basicOptions: {
plugins: {
legend: {
labels: {
color: '#495057'
}
}
},
scales: {
x: {
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
},
y: {
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
}
}
},
horizontalOptions: {
indexAxis: 'y',
plugins: {
legend: {
labels: {
color: '#495057'
}
}
},
scales: {
x: {
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
},
y: {
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
}
}
},
multiAxisOptions: {
plugins: {
legend: {
labels: {
color: '#495057'
}
},
tooltip: {
mode: 'index',
intersect: true
}
},
scales: {
x: {
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
},
y: {
type: 'linear',
display: true,
position: 'left',
ticks: {
min: 0,
max: 100,
color: '#495057'
},
grid: {
color: '#ebedef'
}
},
y1: {
type: 'linear',
display: true,
position: 'right',
grid: {
drawOnChartArea: false,
color: '#ebedef'
},
ticks: {
min: 0,
max: 100,
color: '#495057'
}
}
}
},
stackedOptions: {
plugins: {
tooltip: {
mode: 'index',
intersect: false
},
legend: {
labels: {
color: '#495057'
}
}
},
scales: {
x: {
stacked: true,
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
},
y: {
stacked: true,
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
}
}
}
}
}
}
<\\/script>`
},
'composition-api': {
tabName: 'Composition API Source',
content: `
<template>
<div>
<div class="card">
<h5>Vertical</h5>
<Chart type="bar" :data="basicData" :options="basicOptions" />
</div>
<div class="card">
<h5>Horizontal</h5>
<Chart type="bar" :data="basicData" :options="horizontalOptions" />
</div>
<div class="card">
<h5>Multi Axis</h5>
<Chart type="bar" :data="multiAxisData" :options="multiAxisOptions "/>
</div>
<div class="card">
<h5>Stacked</h5>
<Chart type="bar" :data="stackedData" :options="stackedOptions" />
</div>
</div>
</template>
<script>
import { ref } from 'vue';
export default {
setup() {
const basicData = ref({
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [
{
label: 'My First dataset',
backgroundColor: '#42A5F5',
data: [65, 59, 80, 81, 56, 55, 40]
},
{
label: 'My Second dataset',
backgroundColor: '#FFA726',
data: [28, 48, 40, 19, 86, 27, 90]
}
]
});
const multiAxisData = ref({
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
label: 'Dataset 1',
backgroundColor: ['#EC407A','#AB47BC','#42A5F5','#7E57C2','#66BB6A','#FFCA28','#26A69A'],
yAxisID: 'y-axis-1',
data: [65, 59, 80, 81, 56, 55, 10]
}, {
label: 'Dataset 2',
backgroundColor: '#78909C',
yAxisID: 'y-axis-2',
data: [28, 48, 40, 19, 86, 27, 90]
}]
});
const stackedData = ref({
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
datasets: [{
type: 'bar',
label: 'Dataset 1',
backgroundColor: '#42A5F5',
data: [50,25,12,48,90,76,42]
}, {
type: 'bar',
label: 'Dataset 2',
backgroundColor: '#66BB6A',
data: [21,84,24,75,37,65,34]
}, {
type: 'bar',
label: 'Dataset 3',
backgroundColor: '#FFA726',
data: [41,52,24,74,23,21,32]
}]
});
const basicOptions = ref(
{
plugins: {
legend: {
labels: {
color: '#495057'
}
}
},
scales: {
x: {
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
},
y: {
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
}
}
}
);
const horizontalOptions = ref(
{
indexAxis: 'y',
plugins: {
legend: {
labels: {
color: '#495057'
}
}
},
scales: {
x: {
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
},
y: {
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
}
}
}
);
const multiAxisOptions = ref(
{
plugins: {
legend: {
labels: {
color: '#495057'
}
},
tooltip: {
mode: 'index',
intersect: true
}
},
scales: {
x: {
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
},
y: {
type: 'linear',
display: true,
position: 'left',
ticks: {
min: 0,
max: 100,
color: '#495057'
},
grid: {
color: '#ebedef'
}
},
y1: {
type: 'linear',
display: true,
position: 'right',
grid: {
drawOnChartArea: false,
color: '#ebedef'
},
ticks: {
min: 0,
max: 100,
color: '#495057'
}
}
}
}
);
const stackedOptions = ref(
{
plugins: {
tooltip: {
mode: 'index',
intersect: false
},
legend: {
labels: {
color: '#495057'
}
}
},
scales: {
x: {
stacked: true,
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
},
y: {
stacked: true,
ticks: {
color: '#495057'
},
grid: {
color: '#ebedef'
}
}
}
}
);
return { basicData, multiAxisData, stackedData,
basicOptions, horizontalOptions, multiAxisOptions, stackedOptions }
}
}
<\\/script>
`
}
}
};
}
};
</script>