diff --git a/.vscode/settings.json b/.vscode/settings.json index d93df87..b6bb7f8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,14 +11,18 @@ "aplicación", "archivo", "audiencias", + "autocolors", "avanzados", "bootcamps", "botón", "bottm", "Bottm", "cada", + "cambiar", "Cantidad", "capacidad", + "chartjs", + "choroplet", "choropleth", "científicos", "cliente", diff --git a/delete.js b/delete.js index ec35e48..3b9a31d 100644 --- a/delete.js +++ b/delete.js @@ -73,4 +73,221 @@ function handleFileUpload(event) { } } }); - } \ No newline at end of file + } + +/*intento fallido*/ +export default function updatedCharts() { + //df_clean json file + async function fetchDfData(){ + const url = 'json/df_clean.json'; + const response = await fetch(url); + const dfData = await response.json(); + return dfData; + }; + + fetchDfData().then(dfData => { + const continentData = dfData.map(continent => continent.continent); + const quantityData = dfData.map(quantity => quantity.quantity); + + ctxGraphRightPlot.data.labels = continent; + ctxGraphRightPlot.data.dataset.data = quantity; + ctxGraphRightPlot.update(); + }); + + //rfm_table json file + async function fetchRfmData(){ + const url = 'json/rfm_table.json'; + const response = await fetch(url); + const rfmData = await response.json(); + return rfmData; + }; + + fetchRfmData().then(rfmData => { + const continent = rfmData.map(function (index) { + return index.continent; + }); + }); + + //segmentation_df json file + async function fetchSegmentData(){ + const url = 'json/segmentation_df.json'; + const response = await fetch(url); + const segmentData = await response.json(); + return segmentData; + }; + + let clusterTagName = fetchSegmentData().then(segmentData => { + const clusterTag = segmentData.map(function (index) { + return index.cluster_meaning; + }); + }); + +} + +//*******************INTENTO FALLIDO 2 */ +/*import { doughnutConfig, barConfig, scatterConfig, polarAreaConfig, radarConfig } from "../js/configsPlots.js"; + + //rfm_table json file +fetch('json/rfm_table.json') +.then(function(response){ + if(response.ok == true){ + return response.json(); + } +}) +.then(function(data) { + updatedCharts(ctxMidgraphLeft, data, barConfig); +}); + +//segmentation_df json file +fetch('json/segmentation_df.json') +.then(function(response){ + if(response.ok == true){ + return response.json(); + } +}) +.then(function(data) { + updatedCharts(ctxMidgraphCenter, data, radarConfig); +}); */ + +//Mapamundi +/* fetch('https://unpkg.com/world-atlas/countries-50m.json').then((r) => r.json()).then((data) => { + const countries = ChartGeo.topojson.feature(data, data.objects.countries).features; + +const chart = new Chart(ctxBottmLeft.getContext("2d"), { +type: 'choropleth', +data: { + labels: countries.map((d) => d.properties.name), + datasets: [{ + label: 'Countries', + data: countries.map((d) => ({feature: d, value: Math.random()})), + }] +}, +options: { + showOutline: true, + showGraticule: true, + plugins: { + legend: { + display: false + }, + }, + scales: { + projection: { + axis: 'x', + projection: 'equalEarth' + } + } +} +}); +}); */ + +document.querySelector('#loadDataButton').addEventListener('click', loadDataDf); +document.querySelector('#loadDataButton').addEventListener('click', loadDataDf); +document.querySelector('#loadDataButton').addEventListener('click', loadDataDf); + +const ctxGraphCenter = document.querySelector("#canvas__graph-center"); +const ctxGraphRight = document.querySelector("#canvas__graph-right"); +const ctxMidgraphLeft = document.querySelector("#canvas__midgraph-left"); +const ctxMidgraphCenter = document.querySelector("#canvas__midgraph-center"); +const ctxBottmLeft = document.querySelector("#canvas__bottm-left"); +const ctxBottmCenter = document.querySelector("#canvas__bottm-center"); + +//df_clean json file +function loadDataDf() { + fetch('json/df_clean.json') + .then(function(response){ + if(response.ok == true){ + return response.json(); + } + }) + .then(data => viewChart(data)) + .catch((error) => console.error("Error al cargar datos:", error)); +} + +//rfm_table json file +function loadDataRFM() { + fetch('json/rfm_table.json') + .then(function(response){ + if(response.ok == true){ + return response.json(); + } + }) + .then(data => viewChart(data)) + .catch((error) => console.error("Error al cargar datos:", error)); +} + +//Gráfico 1 Promedio de ventas +const ctxGraphCenterPlot = new Chart(ctxGraphCenter, doughnutConfig); + +//Gráfico 2 Gasto total anual (USD) + +function viewChart(dataJson) { + new Chart(ctxGraphRight, { + type: 'bar', + data: { + labels: dataJson.map(row => row.continent), + datasets: [{ + label: 'Continente', + data: dataJson.map(row => row.total), + backgroundColor: [ + '#EF6A32', + '#FFF6E9', + '#36A2EB', + '#017351', + '#FBBF45', + '#B1AFFF', + '#A12A5E', + '#03C383', + '#26294A', + '#AAD962', + '#FF1A68', + '#01545A', + '#ED0345', + '#710162', + '#110141' + + ], + borderColor: [ + '#EF6A32', + '#FFF6E9', + '#36A2EB', + '#017351', + '#FBBF45', + '#B1AFFF', + '#A12A5E', + '#03C383', + '#26294A', + '#AAD962', + '#FF1A68', + '#01545A', + '#ED0345', + '#710162', + '#110141' + ], + borderWidth: 1 + }] + }, + options: { + responsive: true, + plugins: { + legend: { + position: 'top', + }}, + scales: { + y: { + beginAtZero: true + } + } + } + }); +} +//Gráfico 3 Cantidad total de usuarios +const ctxMidgraphLeftPlot = new Chart(ctxMidgraphLeft, scatterConfig); + +//Gráfico 4 Segmentos por región +const ctxMidgraphCenterPlot = new Chart(ctxMidgraphCenter, polarAreaConfig); + +//Gráfico 5 Ventas por continente (USD)*** cambiar a choroplet +const ctxBottmLeftPlot = new Chart(ctxBottmLeft, radarConfig); + +//Gráfico 6 Segmentos por continente +const ctxBottmCenterPlot = new Chart(ctxBottmCenter, polarAreaConfig); diff --git a/index.html b/index.html index 0b70d3f..be01b32 100644 --- a/index.html +++ b/index.html @@ -95,56 +95,6 @@