In this guide, I'll demonstrate how you can integrate a chart into the application.
- Bar Chart: Displays data as rectangular bars with lengths proportional to the values they represent.
- Scatter Plot: Shows individual data points on a two-dimensional plane.
To access supplier/model data, follow these steps:
- Subscribe to the
selectedModels
store to get the currently selected model IDs. - Filter the
suppliers
data based on the selected model IDs. - Sort the filtered data based on the desired metric (e.g., cost per million tokens).
- Extract necessary data (e.g., model names, cost per million tokens, speed) for chart generation.
- Format the data according to the required shape for the chosen chart type.
To generate charts within Chart.svelte
, follow these steps:
- Add the name of the chart you've chosen to
activeChart
andchartTypes
. - Inside the
selectedModels
scope, structure the data according to the documentation. Note: Ensure to utilize thesortedData
variable as a dataset to dynamically update your chart based on user actions. - If you require additional options for the chart, place them inside the
chartOptions.ts
file. - Once all the data is set, include it in the HTML like this:
{#if activeChart === 'bar'}
<Bar data="{dataBar}" options="{optionsBar}" width="{900}" height="{100}" />
{:else if activeChart === 'scatter'}
<Scatter data="{dataScatter}" options="{optionsScatter}" width="{900}" height="{100}" />
{:else if activeChart === 'custom'}
<YourChart data="{yourData}" options="{yourOptions}" width="{900}" height="{100}" />
{/if}