update chart

This commit is contained in:
MuslemRahimi 2025-02-28 18:54:52 +01:00
parent a8211fc1b8
commit 4395ae6d8b
2 changed files with 150 additions and 59 deletions

View File

@ -1,9 +1,11 @@
import Highcharts from 'highcharts'; import Highcharts from 'highcharts';
import HighchartsMore from 'highcharts/highcharts-more'; // Add this import import HighchartsMore from 'highcharts/highcharts-more'; // Add this import
//import HighchartsAnnotations from 'highcharts/modules/annotations';
import { browser } from '$app/environment'; import { browser } from '$app/environment';
if (browser) { if (browser) {
HighchartsMore(Highcharts); // Initialize the extension HighchartsMore(Highcharts); // Initialize the extension
//HighchartsAnnotations(Highcharts); // Initialize annotations module
Highcharts.setOptions({ Highcharts.setOptions({
lang: { lang: {
numericSymbols: ['K', 'M', 'B', 'T', 'P', 'E'] numericSymbols: ['K', 'M', 'B', 'T', 'P', 'E']

View File

@ -258,64 +258,67 @@
value = 0.5; value = 0.5;
break; break;
} }
const option = {
silent: true, return {
animation: false, legend: {
enabled: false,
},
credits: {
enabled: false,
},
chart: {
type: "pie",
backgroundColor: "#09090B",
plotBackgroundColor: "#09090B",
height: 360,
animation: false,
},
title: {
text: null,
},
plotOptions: {
pie: {
dataLabels: {
enabled: false,
},
enableMouseTracking: false,
states: {
hover: {
enabled: false,
},
},
startAngle: -90,
endAngle: 90,
center: ["50%", "65%"],
size: "75%", // Smaller chart
},
},
series: [ series: [
{ {
type: "gauge", type: "pie",
startAngle: 180, innerSize: "70%",
endAngle: 0, animation: false,
center: ["50%", "45%"],
radius: "70%",
min: 0,
max: 1,
splitNumber: 4,
axisLine: {
lineStyle: {
width: 25,
color: [
[0.2, "#9E190A"],
[0.4, "#D9220E"],
[0.6, "#FF9E21"],
[0.8, "#31B800"],
[1, "#008A00"],
],
},
},
pointer: {
icon: "path://M12.8,0.7l12,40.1H0.7L12.8,0.7z",
length: "25%",
width: 20,
offsetCenter: [0, "-30%"],
itemStyle: {
color: "#fff",
},
},
axisTick: {
length: 0,
},
splitLine: {
length: 0,
},
axisLabel: {
show: false,
},
detail: {
show: false, // Hide the numerical value display
},
data: [ data: [
{ {
value: value, name: "Strong Sell",
label: { y: 0.2,
show: false, // Hide the data label color: "#9E190A",
}, borderColor: "#9E190A",
},
{ name: "Sell", y: 0.2, color: "#D9220E", borderColor: "#D9220E" },
{ name: "Hold", y: 0.2, color: "#FF9E21", borderColor: "#FF9E21" },
{ name: "Buy", y: 0.2, color: "#31B800", borderColor: "#31B800" },
{
name: "Strong Buy",
y: 0.2,
color: "#008A00",
borderColor: "#008A00",
}, },
], ],
}, },
], ],
}; };
return option;
} }
if (data?.getAnalystEstimate?.length !== 0) { if (data?.getAnalystEstimate?.length !== 0) {
@ -508,6 +511,93 @@
}, },
}, },
], ],
/*
annotations: [
{
labels: [
{
point: {
x: forecastHigh[forecastHigh.length - 1][0], // Last X (timestamp)
y: forecastHigh[forecastHigh.length - 1][1], // Last Y (Average value)
xAxis: 0,
yAxis: 0,
},
text: `<b>High</b><br><span class="text-sm">$${forecastHigh[forecastHigh.length - 1][1]}</span>`,
useHTML: true,
style: {
backgroundColor: "rgba(0, 0, 0, 0.8)",
borderColor: "rgba(255, 255, 255, 0.2)",
borderWidth: 1,
fontSize: "12px",
fontWeight: "bold",
},
align: "left",
verticalAlign: "middles",
x: -10,
y: 0,
backgroundColor: "rgba(0, 0, 0, 0.8)",
borderColor: "rgba(255, 255, 255, 0.2)",
borderWidth: 1,
padding: 8,
shape: "",
},
{
point: {
x: forecastAvg[forecastAvg.length - 1][0], // Last X (timestamp)
y: forecastAvg[forecastAvg.length - 1][1], // Last Y (Average value)
xAxis: 0,
yAxis: 0,
},
text: `<b>Average</b><br><span>$${forecastAvg[forecastAvg.length - 1][1]}</span>`,
useHTML: true,
style: {
backgroundColor: "rgba(0, 0, 0, 0.8)",
borderColor: "rgba(255, 255, 255, 0.2)",
borderWidth: 1,
fontSize: "12px",
fontWeight: "bold",
},
align: "right",
verticalAlign: "middle",
x: -10,
y: 30,
backgroundColor: "rgba(0, 0, 0, 0.8)",
borderColor: "rgba(255, 255, 255, 0.2)",
borderWidth: 1,
padding: 5,
shape: "",
},
{
point: {
x: forecastLow[forecastLow.length - 1][0], // Last X (timestamp)
y: forecastLow[forecastLow.length - 1][1], // Last Y (Average value)
xAxis: 0,
yAxis: 0,
},
text: `<b>Low</b><br><span>$${forecastLow[forecastLow.length - 1][1]}</span>`,
useHTML: true,
style: {
backgroundColor: "rgba(0, 0, 0, 0.8)",
borderColor: "rgba(255, 255, 255, 0.2)",
borderWidth: 1,
fontSize: "12px",
fontWeight: "bold",
},
align: "top",
verticalAlign: "middle",
x: -10,
y: -40,
backgroundColor: "rgba(0, 0, 0, 0.8)",
borderColor: "rgba(255, 255, 255, 0.2)",
borderWidth: 1,
padding: 5,
shape: "",
},
],
},
],
*/
legend: { legend: {
enabled: false, enabled: false,
}, },
@ -631,17 +721,16 @@
from the current stock price of {price}. from the current stock price of {price}.
</p> </p>
</div> </div>
<div> <div class="relative">
<div class="app h-[160px]"> <div use:highcharts={optionsPieChart}></div>
{#if optionsPieChart !== null} <div
<Chart {init} options={optionsPieChart} class="chart" /> class="absolute left-1/2 -translate-x-1/2 -mt-20 text-center text-xl font-semibold"
{/if} >
</div>
<div class="-mt-36 text-center text-xl font-semibold">
Analyst Consensus: <span Analyst Consensus: <span
class="font-bold {['Strong Buy', 'Buy']?.includes( class="font-bold inline-block {[
consensusRating, 'Strong Buy',
) 'Buy',
]?.includes(consensusRating)
? 'text-[#00FC50]' ? 'text-[#00FC50]'
: ['Strong Sell', 'Sell']?.includes(consensusRating) : ['Strong Sell', 'Sell']?.includes(consensusRating)
? 'text-[#FF2F1F]' ? 'text-[#FF2F1F]'