diff --git a/content/data-lab/global-business-growth.md b/content/data-lab/global-business-growth.md
index 84c92af..954aab9 100644
--- a/content/data-lab/global-business-growth.md
+++ b/content/data-lab/global-business-growth.md
@@ -18,6 +18,8 @@ The chart always reflects the countries selected in the table.
{{< dropdown_filter id="days_ago_dropdown_filter" id_filter="days_ago" options="1 day:1,7 day:7,28 day:28,1 year:365,5 year:1826,10 year:3652,all time:10000" default_selection="7 day" targets="bitcoin-business-growth-chart bitcoin-business-growth-table" >}}
{{< table id="bitcoin-business-growth-table" endpoint="bitcoin_business_growth_percent_diff" headers="{'country_name': 'Country', 'date_range': 'Date Range', 'first_value': 'Previous #', 'last_value': 'Current #', 'difference': 'Diff', 'percent_difference': '% Diff'}" maxHeight="400px" sortable="true" valueId="country_name" selectableRows="multi" targets="bitcoin-business-growth-chart" defaultFirstSelected="true" >}}
+{{< chart id="bitcoin-business-growth-table" src="/js/bitcoin-business-growth-chart.js" >}}
+
{{< chart chartMethod="tableRowSelectChart" id="bitcoin-business-growth-chart" endpoint="bitcoin_business_growth_timeseries" chartType="line" xAxisField="date" yAxisField="cumulative_value" scaleChart=true xAxisType="category" >}}
#### Attribution and License
diff --git a/content/data-lab/miner-rewards.md b/content/data-lab/miner-rewards.md
index 39ac8e1..e0e522e 100644
--- a/content/data-lab/miner-rewards.md
+++ b/content/data-lab/miner-rewards.md
@@ -13,4 +13,4 @@ The following chart shows daily miner revenue in USD for the period selected in
{{< dropdown_filter id="days_ago_dropdown_filter" id_filter="days_ago" options="1 day:1,7 day:7,28 day:28,1 year:365,5 year:1826,10 year:3652,all time:10000" default_selection="7 day" targets="miner-rewards-chart" >}}
-{{< chart chartMethod="simpleChart" id="miner-rewards-chart" endpoint="miner_rewards" chartType="line" xAxisField="date" yAxisField="total_reward_usd" scaleChart=true xAxisType="category" >}}
+{{< chart id="miner-rewards" src="/js/miner-rewards.js" >}}
diff --git a/layouts/partials/chart.html b/layouts/partials/chart.html
index cf807a9..1e94b9e 100644
--- a/layouts/partials/chart.html
+++ b/layouts/partials/chart.html
@@ -97,18 +97,19 @@
});
}
- chartData = [];
function simpleChart(
id,
endpoint,
chartType,
xAxisField,
yAxisField,
+ series,
sortField = null,
scaleChart = false,
xAxisType = "time",
formatValueDecimalPlaces = null,
) {
+ console.log(series);
async function fetchDataForChart(query) {
try {
const apiEndpoint = `${apiURL}/${endpoint}?${query}`;
@@ -145,12 +146,7 @@
scale: scaleChart,
type: "value",
},
- series: [
- {
- data: chartData.map((item) => item.total_reward_usd),
- type: "line",
- },
- ],
+ series: JSON.parse(`{${series}}`),
};
myChart.setOption(option, true);
diff --git a/layouts/shortcodes/chart.html b/layouts/shortcodes/chart.html
index d8c1813..4087315 100644
--- a/layouts/shortcodes/chart.html
+++ b/layouts/shortcodes/chart.html
@@ -1,20 +1,7 @@
-{{ partial "chart.html" }}
+
" + params[0].axisValue + "
"; - params.reverse().forEach((item, index) => { - let color = colors[index % colors.length]; - let labels = - "" + - colorSpan(color) + - " " + - item.seriesName + - ": " + - nFormatter(item.data, 3); - ("
"); - tooltip += labels; - }); - - return tooltip; - }, - valueFormatter(value, index) { - return nFormatter(value, 3); - }, - }, - toolbox: toolboxParams, - xAxis: { - data: dataArr.map((row) => row.date), - axisTick: axisTick, - axisLabel: axisLabel, - axisLine: axisLine, - }, - grid: grid, - dataZoom: dataZoom(0), - yAxis: [ - { - type: "value", - name: "Rewards (USD)", - nameLocation: "middle", - nameGap: 30, - nameTextStyle: textStyleMain, - position: "left", - alignTicks: true, - axisTick: axisTick, - axisLine: axisLine, - splitLine: { - show: false, + function updateChart() { + var option = { + tooltip: { + ...tooltip, + valueFormatter(value, index) { + return formatValueDecimalPlaces == null + ? value + : nFormatter(value, formatValueDecimalPlaces); }, - axisLabel: { - ...axisLabel, - formatter(value, index) { - return nFormatter(value, 0); + }, + xAxis: { + type: "category", + data: chartData.map((item) => item.date), + }, + yAxis: [ + { + type: "value", + name: "Rewards (USD)", + nameLocation: "middle", + nameGap: 30, + nameTextStyle: textStyleMain, + position: "left", + alignTicks: true, + axisTick: axisTick, + axisLine: axisLine, + splitLine: { + show: false, + }, + axisLabel: { + ...axisLabel, + formatter(value, index) { + return nFormatter(value, 0); + }, }, }, - }, - { - type: "value", - name: "Subsidy (BTC)", - nameLocation: "middle", - nameGap: 20, - nameTextStyle: { - fontSize: 12 * fontScale, - color: textColor, + { + type: "value", + name: "Subsidy (BTC)", + nameLocation: "middle", + nameGap: 20, + nameTextStyle: { + fontSize: 12 * fontScale, + color: textColor, + }, + axisTick: axisTick, + position: "right", + alignTicks: true, + axisLine: axisLine, + splitLine: { + show: false, + }, + axisLabel: { + fontSize: 12 * fontScale, + color: textColor, + }, }, - axisTick: axisTick, - position: "right", - alignTicks: true, - axisLine: axisLine, - splitLine: { - show: false, + ], + series: [ + { + type: "line", + name: "Subsidy (USD)", + stack: "Total", + areaStyle: {}, + symbol: "none", + lineStyle: { + width: 0, + }, + data: chartData.map((row) => row.subsidy_usd), }, - axisLabel: { - fontSize: 12 * fontScale, - color: textColor, + { + type: "line", + name: "Fees (USD)", + stack: "Total", + areaStyle: {}, + symbol: "none", + lineStyle: { + width: 0, + }, + data: chartData.map((row) => row.totalfee_usd), }, - }, - ], - series: [ - { - type: "line", - name: "Subsidy (USD)", - stack: "Total", - areaStyle: {}, - symbol: "none", - lineStyle: { - width: 0, + { + type: "line", + name: "Total (USD)", + symbol: "none", + lineStyle: { + width: 1, + color: textColor, + }, + data: chartData.map((row) => row.total_reward_usd), }, - data: dataArr.map((row) => row.subsidy_usd), - }, - { - type: "line", - name: "Fees (USD)", - stack: "Total", - areaStyle: {}, - symbol: "none", - lineStyle: { - width: 0, + { + type: "line", + yAxisIndex: 1, + name: "Block Subsidy (BTC)", + symbol: "none", + lineStyle: { + width: 3, + }, + data: chartData.map((row) => row.block_subsidy), }, - data: dataArr.map((row) => row.totalfee_usd), - }, - { - type: "line", - name: "Total (USD)", - symbol: "none", - lineStyle: { - width: 1, - color: textColor, - }, - data: dataArr.map((row) => row.total_reward_usd), - }, - { - type: "line", - yAxisIndex: 1, - name: "Block Subsidy (BTC)", - symbol: "none", - lineStyle: { - width: 3, - }, - data: dataArr.map((row) => row.block_subsidy), - }, - ], - }; + ], + }; - myChart.setOption(option); -} + myChart.setOption(option, true); + } -document.addEventListener("DOMContentLoaded", function () { - let periodIndex = 2; - periodDropdown(periods, periodIndex); - fetchDataForChart(periods[periodIndex]); - const selectElement = document.getElementById("select-period-dropdown"); - - selectElement.addEventListener("change", function (event) { - const selectedValue = event.target.value; - fetchDataForChart(selectedValue); + query = queryConstructor(); + fetchDataForChart(query); + document.addEventListener("filterChange", function (event) { + query = queryConstructor(); + fetchDataForChart(query); }); -}); +} +simpleChart((endpoint = "miner_rewards"));