<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ #data visualisation - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ #data visualisation - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 14 May 2026 22:43:52 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/data-visualisation-1/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Build an Interactive University Ranking System Using React and Data Viz Tools ]]>
                </title>
                <description>
                    <![CDATA[ Hi! I'm Daria, and I'm a software engineering student with a keen interest in data visualization. I've been actively exploring various visualization tools through small pet projects, and I'd like to s ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-an-interactive-ranking-system-using-react-and-data-viz-tools/</link>
                <guid isPermaLink="false">69c44d7d10e664c5daefbf5c</guid>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ #data visualisation ]]>
                    </category>
                
                    <category>
                        <![CDATA[ charts ]]>
                    </category>
                
                    <category>
                        <![CDATA[ pivottable ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Daria Filozop ]]>
                </dc:creator>
                <pubDate>Wed, 25 Mar 2026 21:02:53 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/uploads/covers/5e1e335a7a1d3fcc59028c64/5f31dd6f-e199-4cf3-a76a-daf985a4e7d7.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Hi! I'm Daria, and I'm a software engineering student with a keen interest in data visualization. I've been actively exploring various visualization tools through small pet projects, and I'd like to share my latest demo with you.</p>
<p>In this tutorial, we'll build a project that displays the historical rankings of universities around the world. It's interesting to check out and analyze which institutions consistently maintain their top-tier positions and which ones experience significant movement up or down the rankings over the years.</p>
<p>While building the dashboard, we'll load and structure the dataset, display all important information in a pivot table, and then create charts to visualize the top 10 universities and their ranking trends over time.</p>
<p>Even though we'll walk through this specific example here, you can apply this same approach to many other datasets to build data viz dashboards.</p>
<h2 id="heading-what-well-cover">What We’ll Cover:</h2>
<ol>
<li><p><a href="#heading-tech-stack">Tech Stack</a></p>
</li>
<li><p><a href="#heading-flexmonster-pivot-table-setup">Flexmonster Pivot Table Setup</a></p>
</li>
<li><p><a href="#heading-loading-and-displaying-the-data">Loading and Displaying the Data</a></p>
</li>
<li><p><a href="#heading-creating-charts">Creating Charts</a></p>
</li>
<li><p><a href="#heading-adding-year-filtering-buttons">Adding Year Filtering Buttons</a></p>
</li>
<li><p><a href="#heading-styling">Styling</a></p>
</li>
</ol>
<h2 id="heading-tech-stack">Tech Stack</h2>
<p>Let’s talk about the tools we’ll be using so you know what you’ll need to have before following along.</p>
<p>First, we’ll use <a href="https://react.dev/"><strong>React</strong></a>, which is a popular JavaScript library for building interactive web interfaces. It helps create reusable components and manage data efficiently. According to <a href="https://survey.stackoverflow.co/2025/technology"><strong>the 2025 Stack Overflow Developer Survey</strong></a>, React is the second most popular web framework.</p>
<p>We’ll also use <a href="https://www.flexmonster.com/"><strong>Flexmonster Pivot Table</strong></a>, a web component for displaying data in a table format. In general, pivot tables are widely used for data visualization because they allow you to quickly group, aggregate, filter, and explore large datasets from different perspectives.</p>
<p>With Flexmonster, you can easily create reports and customize your information. It also integrates smoothly with almost all popular modern frameworks (like React, which we’re using here!).</p>
<p>Next, we have <a href="https://echarts.apache.org/en/index.html"><strong>ECharts</strong></a>, which complements the detailed data provided by the pivot table. It’s a powerful, open-source charting library that’ll give us the visual insights we need, offering over 20 chart types to effectively visualize historical university ranking trends.</p>
<p>Finally, we’ll use the <a href="https://www.kaggle.com/datasets/mylesoneill/world-university-rankings"><strong>World University Rankings Dataset</strong></a>. It contains data from three global rankings (<a href="https://www.timeshighereducation.com/world-university-rankings"><strong>THE</strong></a>, <a href="https://www.shanghairanking.com/"><strong>ARWU</strong></a>, and <a href="https://cwur.org/"><strong>CWUR</strong></a>), providing information about well-known universities from 2012 to 2015 for detailed analytical research. The dataset size is 186.38 kB.</p>
<p>As a small disclaimer, this tutorial uses React, so some familiarity with it will help you follow along. But actually, you can use any other framework that's convenient for you. Flexmonster Pivot Table offers <a href="https://www.flexmonster.com/doc/available-tutorials-integration/">many integrations with popular frameworks</a>, including Angular, Vue, Svelte, and more.</p>
<p>When we’re done with the project, we’ll get an interactive dashboard like this:</p>
<img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXe49D_OM3dE-Q8bLmhsYyejXE0CF0PZTZeXhm_3vJfCDOO8JmQMCbLk8x_d_FBAWJjcsKFd0Mm3uTntW2zcp6NYGMXUVnyfjpwWI0izXInLvUhcHgtoSPoCt4EFtHpVm5WOzP-khwnxPryrgO1FjEUqWXSEWtI?key=44ff_UPj0hN24gZs8A8Dew" alt="Interactive dashboard for visualizing university ratings" width="600" height="400" loading="lazy">

<p>So now that you’re familiar with the tools, let’s get started!</p>
<h2 id="heading-flexmonster-pivot-table-setup">Flexmonster Pivot Table Setup</h2>
<p>To get started, you’ll need to integrate Flexmonster into your React project. I’ll walk you through how it works with React, but you can use other frameworks, too. You can find complete instructions in <a href="https://www.flexmonster.com/doc/available-tutorials-integration/"><strong>the Flexmonster docs</strong></a>.</p>
<p>First, create a React application using Vite:</p>
<pre><code class="language-shell">npm create vite@latest flexmonster-project -- --template react
</code></pre>
<p>Also, don’t forget to install npm dependencies:</p>
<pre><code class="language-shell">cd flexmonster-project
npm install
</code></pre>
<p>Next, we’ll install the Flexmonster wrapper for React. To do this, use this command:</p>
<pre><code class="language-shell">npm install -g flexmonster-cli
flexmonster add react-flexmonster
</code></pre>
<p>Then add Flexmonster styles and the component to your App.jsx file:</p>
<pre><code class="language-javascript">import FlexmonsterReact from "react-flexmonster";
import "flexmonster/flexmonster.css";
</code></pre>
<h2 id="heading-loading-and-displaying-the-data">Loading and Displaying the Data</h2>
<p>Now it’s time to create a report object. This is a configuration that defines how the pivot table should load and display data. It describes how the fields should be interpreted, and how the table should organize and aggregate the information.</p>
<p>The first part of this is <code>dataSource</code>. It defines where the data comes from and how it should be read by the pivot table (format of the dataset, location of the file, and the structure of the fields that will be used).</p>
<p>In our case, we'll load a CSV file that contains the university rankings dataset and define the fields that will appear in the pivot table:</p>
<pre><code class="language-javascript">&nbsp;&nbsp;const report = {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dataSource: {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type: "csv",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filename: "/data/world-university-rankings.csv",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mapping: {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;world_rank: { type: "number", caption: "World Rank" },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;institution: { type: "string" },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;country: { type: "string" },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;score: { type: "number", caption: "Score" },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;year: { type: "number", caption: "Year" },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},
…
}
</code></pre>
<p>The second part is the slice section. It defines which subset of the dataset will be displayed and how it should be organized. There, you'll render a table by setting measures, rows, and columns. You can also set the <code>flatOrder</code> property, where you define the order of the fields in the flat form.</p>
<p>You can find more detailed information about the <a href="https://www.flexmonster.com/api/slice-object/"><strong>Slice Object here</strong></a>. There are lots of interesting functional possibilities!</p>
<pre><code class="language-javascript">const report = {
…
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;slice: {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rows: [{ uniqueName: "institution" }],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;columns: [{ uniqueName: "[Measures]" }],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;measures: [
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ uniqueName: "world_rank", aggregation: "min" },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uniqueName: "year",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aggregation: "none",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter: { members: [`year.[${selectedYear}]`] },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;flatOrder: ["institution", "world_rank"],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options: {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;grid: { type: "flat", showGrandTotals: "off" },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;};
</code></pre>
<p>You’ll also need to include Flexmonster inside the React component. In this example, we'll include the <code>FlexmonsterReact</code> tag in JSX and pass the report object (which we defined earlier) as a property. You can do that with this code snippet:</p>
<pre><code class="language-javascript">&lt;FlexmonsterReact
&nbsp;&nbsp;&nbsp;&nbsp;ref={pivotRef}
&nbsp;&nbsp;&nbsp;&nbsp;toolbar={true}
&nbsp;&nbsp;&nbsp;&nbsp;report={report}
&nbsp;&nbsp;&nbsp;&nbsp;width="100%"
&nbsp;&nbsp;&nbsp;&nbsp;height="100%"
&nbsp;&nbsp;&nbsp;&nbsp;reportcomplete={createChart}
/&gt;
</code></pre>
<p>As a result, we've got pivot table with all the info about the universities:</p>
<img src="https://cdn.hashnode.com/uploads/covers/690da61ea51d4259bd4a849b/ab96b9fc-c322-482c-b95a-33d17887a94e.png" alt="Pivot table with university data and rankings" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<h2 id="heading-creating-charts">Creating Charts</h2>
<p>For some users, charts are easier to understand than tables, so let’s also create some now. I decided to display the top 10 universities in the world using bar charts. Bar charts are commonly used to compare values between categories, and they're quite useful for highlighting rankings or top performers.</p>
<p>We'll use ECharts here, but you can easily integrate Flexmonster with <a href="https://www.flexmonster.com/doc/available-tutorials-charts/"><strong>the most convenient chart library for you</strong></a>.</p>
<p>As a first step, make sure to install ECharts in your project:</p>
<pre><code class="language-shell">npm install echarts
</code></pre>
<p>To prepare our data for display in the charts, we’ll create the <code>prepareData()</code> function. This function picks out the universities' names and their ranks, removes any invalid data, sorts it by rank, and keeps only the top 10. It returns two arrays: one with the names (for chart labels) and another with the rankings (for chart values):</p>
<pre><code class="language-javascript">const prepareData = (rawData) =&gt; {
&nbsp;&nbsp;&nbsp;&nbsp;const rows = rawData.data
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.map((r) =&gt; ({ name: r.r0, rank: r.v0 }))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.filter((r) =&gt; r.name &amp;&amp; !isNaN(r.rank))
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.sort((a, b) =&gt; a.rank - b.rank)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.slice(0, 10);
&nbsp;&nbsp;&nbsp;&nbsp;return {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;labels: rows.map((r) =&gt; r.name).reverse(),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;values: rows.map((r) =&gt; r.rank).reverse(),
&nbsp;&nbsp;&nbsp;&nbsp;};
};
</code></pre>
<p>Next, we'll set up chart options. You’ll need to decide in what form your dataset will be displayed: in this example, we'll choose a bar chart. We'll also set the title (here "Top 10 Universities by World Rank"), x-axis (shows the rank numbers) and y-axis (shows universities names), and tooltip, which shows info when you hover over a bar.</p>
<p>Also, don't forget to initialize the chart and apply these options. You can do all this with this code snippet:</p>
<pre><code class="language-javascript">const drawChart = (rawData) =&gt; {
&nbsp;&nbsp;&nbsp;&nbsp;const { labels, values } = prepareData(rawData);
&nbsp;&nbsp;&nbsp;&nbsp;const options = {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title: {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;text: "Top 10 Universities by World Rank",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;left: "center",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;textStyle: { fontSize: 20, fontWeight: "bold" },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tooltip: { trigger: "axis", axisPointer: { type: "shadow" } },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;xAxis: { type: "value", name: "Rank" },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;yAxis: { type: "category", data: labels },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;series: [{ type: "bar", data: values, barMaxWidth: 30 }],
&nbsp;&nbsp;&nbsp;&nbsp;};
&nbsp;&nbsp;&nbsp;&nbsp;chartInstance = echarts.init(chartRef.current);
&nbsp;&nbsp;&nbsp;&nbsp;chartInstance.setOption(options);
};
</code></pre>
<p>Also, an important part of chart configuration is the <code>updateCharts()</code> function, which redraws the chart when needed:</p>
<pre><code class="language-javascript">const updateChart = (rawData) =&gt; {
&nbsp;&nbsp;&nbsp;&nbsp;if (chartInstance) chartInstance.dispose();
&nbsp;&nbsp;&nbsp;&nbsp;drawChart(rawData);
};
</code></pre>
<p>So now we can see the charts we've created! This might look a bit basic and really hard to read, but don’t worry – we’ll make it look nicer and easier to understand in a later section.</p>
<img src="https://cdn.hashnode.com/uploads/covers/690da61ea51d4259bd4a849b/65cf5e06-f0dd-4d45-b1eb-e78797b44d2b.png" alt="Bar charts showing the top 10 universities by world rank" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<h2 id="heading-adding-year-filtering-buttons">Adding Year Filtering Buttons</h2>
<p>You might have noticed that the dataset contains ratings for different years (from 2012 to 2015). It would be great if we could use the whole dataset, not just information for one year.</p>
<p>To manage this, we'll create filtering buttons for each year to provide more straightforward navigation.</p>
<p>First, we’ll add a div element which contains buttons for each year:</p>
<pre><code class="language-javascript">&lt;div className="years-container"&gt;
&nbsp;&nbsp;&nbsp;&nbsp;{[2012, 2013, 2014, 2015].map((year) =&gt; (
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;button
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;key={year}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;onClick={() =&gt; handleYearChange(year)}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;className={`year-btn ${selectedYear === year ? "active" : ""}`}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{year}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/button&gt;
&nbsp;&nbsp;&nbsp;&nbsp;))}
&lt;/div&gt;
</code></pre>
<p>In the above code snippet, you can see that each button calls <code>handleYearChange(year)</code> when being clicked. Let’s now examine what this handler does:</p>
<pre><code class="language-javascript">const handleYearChange = (year) =&gt; {
&nbsp;&nbsp;&nbsp;&nbsp;setSelectedYear(year);

&nbsp;&nbsp;&nbsp;&nbsp;const pivot = pivotRef.current?.flexmonster;
&nbsp;&nbsp;&nbsp;&nbsp;if (pivot) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;const newReport = {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...report,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;slice: {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...report.slice,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;measures: [
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ uniqueName: "world_rank", aggregation: "min" },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uniqueName: "year",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aggregation: "none",
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;filter: { members: [`year.[${year}]`] },
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;],
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;};
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pivot.setReport(newReport);
&nbsp;&nbsp;&nbsp;&nbsp;}
};&nbsp;
</code></pre>
<p>This function modifies the pivot table report to filter by that year, and refreshes the table. This way, clicking a button instantly shows only the data for the chosen year.</p>
<p>And now we've got buttons which display years from our dataset:</p>
<img src="https://cdn.hashnode.com/uploads/covers/690da61ea51d4259bd4a849b/184608a5-6207-44d8-b5fe-80fd355201c0.png" alt="Buttons to filter data by year" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<h2 id="heading-styling">Styling</h2>
<p>Finally, here’s my favorite part of every project: customization! I love experimenting with different styles and choosing the most appropriate one.</p>
<p>For this dashboard, I chose light violet and white colors to make the interface clean and easy to read. I personally associate the university vibe with these colors, so I think they match our dashboard perfectly. So let's go step by step through it.</p>
<p>The main container defines the overall layout and background. It centers the content on the page, adds some spacing, and sets the base font and colors.</p>
<pre><code class="language-javascript">.app-container {
    min-height: 100vh;
    width: 100vw;
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;

    background: #ebe6f7;
    font-family: "Inter", system-ui, -apple-system, sans-serif;
    color: #1b2a4e;
}
</code></pre>
<p>Next, we'll style the year filter buttons. They have rounded corners, a soft shadow, and a small hover effect so the interface feels interactive. The active button gets a violet background so it’s easy to see which year is selected.</p>
<pre><code class="language-javascript">.year-btn {
    padding: 10px 20px;
    background: #ffffff;
    border: 1px solid #cdd2e0;
    border-radius: 8px;
    cursor: pointer;
}

.year-btn:hover {
    background: #e1dffa;
}

.year-btn.active {
    background: #6c5ce7;
    color: white;
}
</code></pre>
<p>Also, the pivot table and the chart are located inside simple containers with rounded corners and slight shadows. This visually separates the components and keeps the layout logically structured.</p>
<pre><code class="language-javascript">.pivot-container,
.chart-container {
    width: 90%;
    background: #ffffff;
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 6px 20px rgba(15, 35, 95, 0.12);
}

.pivot-container {
    height: 56vh;
    margin-bottom: 24px;
}

.chart-container {
    height: 40vh;
}
</code></pre>
<p>And now, here's the result of our work!</p>
<img src="https://cdn.hashnode.com/uploads/covers/690da61ea51d4259bd4a849b/ed35dbdd-9c5d-4f7e-b6e1-4f0546a0d660.png" alt="Universities ranking pivot table with interactive year filters" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<img src="https://cdn.hashnode.com/uploads/covers/690da61ea51d4259bd4a849b/1a0b0f1c-9c26-40e2-8c28-bd45517ea145.png" alt="Charts showing the top 10 universities by world rank" style="display:block;margin:0 auto" width="600" height="400" loading="lazy">

<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>In this tutorial, we've build an interactive dashboard for visualizing the world's top university rankings over the years. You learned how to load and show data in pivot table in a convenient and compact way, make bar charts to show comparative data, and add buttons to filter info by year.</p>
<p>You can now use these skills to visualize other datasets and play with different charts and customization options.</p>
<p>If you want to look closer at my code and get detailed styling code, you can check out my GitHub: <a href="https://github.com/filozopdasha/universities-dashboard"><strong>https://github.com/filozopdasha/universities-dashboard</strong></a></p>
<p>I would be delighted to hear your thoughts about this small project. I’m curious to see what you build!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Use Chart js for Interactive Data Visualization ]]>
                </title>
                <description>
                    <![CDATA[ Data surrounds us, but its raw form can be overwhelming and difficult to interpret. That's where data visualization comes in. It can help you take your data and turn it into charts and graphs that make sense at a glance. Among the many data visualiza... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-chart-js-for-interactive-data-visualization/</link>
                <guid isPermaLink="false">66e2e5406bc43703e551036f</guid>
                
                    <category>
                        <![CDATA[ #data visualisation ]]>
                    </category>
                
                    <category>
                        <![CDATA[ charts ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Oluwadamisi Samuel ]]>
                </dc:creator>
                <pubDate>Thu, 12 Sep 2024 12:57:36 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1725821135508/79767987-8760-4626-a924-212e402b051f.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Data surrounds us, but its raw form can be overwhelming and difficult to interpret. That's where data visualization comes in. It can help you take your data and turn it into charts and graphs that make sense at a glance.</p>
<p>Among the many data visualization libraries available, Chart.js stands out for its simplicity, flexibility, and interactivity.</p>
<p>This guide is like a roadmap to making charts with Chart.js. It doesn't matter if you're a coding expert or just getting started – I'll show you everything you need to know. We'll break down the basics of Chart.js, show you different types of charts (like bars and lines), and teach you how to make them look great and even respond to clicks.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ol>
<li><p><a class="post-section-overview" href="#heading-what-is-chartjs">What is Chart.js?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-benefits-of-using-chartjs-for-data-visualization">Benefits of Using Chart.js for Data Visualization</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-get-started-with-chartjs">How to Get Started with Chart.js</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-chart-types-in-chartjs">Chart Types in Chart.js</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-customization-and-interactivity-in-chartjs">Customization and Interactivity in Chart.js</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-work-with-data-in-chartjs">How to Work with Data in Chart.js</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-advanced-chartjs-features">Advanced Chart.js Features</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-best-practices-for-chart-design">Best Practices for Chart Design</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ol>
<h2 id="heading-what-is-chartjs">What is Chart.js?</h2>
<p>Chart.js is a popular open-source JavaScript library that allows you to create beautiful and interactive charts on the web. It's easy to use and supports various types of charts, such as line, bar, pie, radar, and more.</p>
<p>Chart.js is highly customizable, allowing you to modify the appearance and behavior of the charts to fit your specific needs. It uses the HTML5 <code>&lt;canvas&gt;</code> element to render the charts, making it compatible with modern web browsers.</p>
<h2 id="heading-benefits-of-using-chartjs-for-data-visualization">Benefits of Using Chart.js for Data Visualization</h2>
<p>Using Chart.js for data visualization offers numerous benefits that make it an excellent choice for developers and non-developers alike. The primary advantages include:</p>
<h3 id="heading-easy-to-use">Easy to Use</h3>
<p>Chart.js is known for its simplicity and ease of use. Even if you're new to JavaScript, you can quickly create and customize charts with minimal code.</p>
<p>The library's clear and concise documentation provides step-by-step instructions and examples, making it accessible for beginners and experienced developers alike.</p>
<h3 id="heading-versatile-chart-types">Versatile Chart Types</h3>
<p>Chart.js supports a wide range of chart types, including line, bar, pie, doughnut, radar, polar area, bubble, and scatter charts. This versatility allows you to choose the best chart type to represent your data effectively.</p>
<p>Whether you need to show trends over time, compare different categories, or display proportions, Chart.js has you covered.</p>
<h3 id="heading-highly-customizable">Highly Customizable</h3>
<p>One of the standout features of Chart.js is its high level of customization. You can tweak almost every aspect of your charts, from colors, fonts, and sizes to tooltips, legends, and animations. This flexibility ensures that your charts match the look and feel of your website or application perfectly.</p>
<h3 id="heading-responsive-design">Responsive Design</h3>
<p>Chart.js charts are responsive by default, meaning they automatically adjust their size and layout based on the screen size. This is particularly important in today's world, where users access websites and applications from various devices, including desktops, tablets, and smartphones. With Chart.js, you can be confident that your charts will look great on any device.</p>
<h3 id="heading-interactive-features">Interactive Features</h3>
<p>Interactivity is a key component of modern data visualization, and Chart.js excels in this area. Charts created with Chart.js can include interactive features like tooltips, which display detailed information when users hover over data points, and clickable legends, which allow users to toggle the visibility of different datasets. These features make your charts more engaging and informative.</p>
<h3 id="heading-lightweight-and-fast">Lightweight and Fast</h3>
<p>Chart.js is a lightweight library, meaning it doesn't add significant load time to your website or application. Despite its small size, it is highly efficient and capable of rendering complex charts quickly. This performance is crucial for maintaining a smooth user experience, especially when dealing with large datasets.</p>
<h3 id="heading-open-source-and-community-support">Open Source and Community Support</h3>
<p>As an open-source project, Chart.js is free to use and benefits from a vibrant community of developers who contribute to its improvement and extension.</p>
<p>The active community support means you can find numerous plugins, extensions, and third-party integrations to enhance the functionality of Chart.js. You can also rely on community forums and resources for troubleshooting and inspiration.</p>
<h3 id="heading-compatibility-with-modern-web-technologies">Compatibility with Modern Web Technologies</h3>
<p>Chart.js leverages the HTML5 <code>&lt;canvas&gt;</code> element to render charts, making it compatible with modern web browsers. This compatibility ensures that your charts will display correctly across different platforms and devices.</p>
<p>Also, you can easily integrate Chart.js with popular JavaScript frameworks and libraries, such as React, Angular, and Vue.js, allowing you to incorporate charts seamlessly into your projects.</p>
<h3 id="heading-accessibility-features">Accessibility Features</h3>
<p>Accessibility is a crucial consideration in web development, and Chart.js includes features to support this. You can add alternative text descriptions and ARIA labels to your charts, making them more accessible to users with disabilities.</p>
<p>This commitment to accessibility helps you create inclusive data visualizations that can be enjoyed by a wider audience.</p>
<h3 id="heading-continuous-improvement">Continuous Improvement</h3>
<p>The development team behind Chart.js is committed to continuously improving the library. Regular updates bring new features, performance enhancements, and bug fixes, ensuring that Chart.js remains a cutting-edge tool for data visualization.</p>
<h2 id="heading-how-to-get-started-with-chartjs">How to Get Started with Chart.js</h2>
<p>Creating interactive and visually appealing charts is straightforward thanks to Chart.js. In this section, I'll walk you through the initial steps to get Chart.js up and running in your project, including setting up the library and creating your first chart.</p>
<h3 id="heading-set-up-your-project">Set Up Your Project</h3>
<p>To get started with Chart.js, you need to include the library in your project. You can do this by either downloading the Chart.js library or linking to it via a Content Delivery Network (CDN). Using a CDN is often the easiest way to get started.</p>
<h4 id="heading-include-chartjs-via-cdn">Include Chart.js via CDN</h4>
<p>Add the following <code>&lt;script&gt;</code> tag to the <code>&lt;head&gt;</code> or <code>&lt;body&gt;</code> section of your HTML file:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Chart.js Example<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/chart.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- Chart container --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"myChart"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"400"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"200"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- Your JavaScript code will go here --&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<h3 id="heading-create-your-first-chart">Create Your First Chart</h3>
<p>Next, you need to create a <code>&lt;canvas&gt;</code> element in your HTML file where the chart will be rendered. This element acts as a container for the chart. In the example above, we already added a <code>&lt;canvas&gt;</code> element with the <code>id</code> of <code>myChart</code>.</p>
<h3 id="heading-write-the-javascript-code">Write the JavaScript Code</h3>
<p>Now, let's write some JavaScript to create a basic chart. Place the following script in the <code>&lt;body&gt;</code> section of your HTML file, below the <code>&lt;canvas&gt;</code> element, or in an external JavaScript file:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
    <span class="hljs-comment">// Get the context of the canvas element we want to select</span>
    <span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);

    <span class="hljs-comment">// Create a new Chart object</span>
    <span class="hljs-keyword">var</span> myChart = <span class="hljs-keyword">new</span> Chart(ctx, {
        <span class="hljs-attr">type</span>: <span class="hljs-string">'bar'</span>, <span class="hljs-comment">// The type of chart we want to create</span>
        <span class="hljs-attr">data</span>: {
            <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Red'</span>, <span class="hljs-string">'Blue'</span>, <span class="hljs-string">'Yellow'</span>, <span class="hljs-string">'Green'</span>, <span class="hljs-string">'Purple'</span>, <span class="hljs-string">'Orange'</span>], <span class="hljs-comment">// Labels for the chart</span>
            <span class="hljs-attr">datasets</span>: [{
                <span class="hljs-attr">label</span>: <span class="hljs-string">'Votes'</span>,
                <span class="hljs-attr">data</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">19</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], <span class="hljs-comment">// Data points for the chart</span>
                <span class="hljs-attr">backgroundColor</span>: [
                    <span class="hljs-string">'rgba(255, 99, 132, 0.2)'</span>,
                    <span class="hljs-string">'rgba(54, 162, 235, 0.2)'</span>,
                    <span class="hljs-string">'rgba(255, 206, 86, 0.2)'</span>,
                    <span class="hljs-string">'rgba(75, 192, 192, 0.2)'</span>,
                    <span class="hljs-string">'rgba(153, 102, 255, 0.2)'</span>,
                    <span class="hljs-string">'rgba(255, 159, 64, 0.2)'</span>
                ],
                <span class="hljs-attr">borderColor</span>: [
                    <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
                    <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                    <span class="hljs-string">'rgba(255, 206, 86, 1)'</span>,
                    <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
                    <span class="hljs-string">'rgba(153, 102, 255, 1)'</span>,
                    <span class="hljs-string">'rgba(255, 159, 64, 1)'</span>
                ],
                <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
            }]
        },
        <span class="hljs-attr">options</span>: {
            <span class="hljs-attr">scales</span>: {
                <span class="hljs-attr">y</span>: {
                    <span class="hljs-attr">beginAtZero</span>: <span class="hljs-literal">true</span> <span class="hljs-comment">// Start the y-axis at 0</span>
                }
            }
        }
    });
</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>Alright, let's understand what's going on in this code:</p>
<ol>
<li><p><strong>Get the Canvas Context</strong>: The first line of the script selects the <code>&lt;canvas&gt;</code> element by its <code>id</code> and gets its 2D drawing context. This context is necessary for creating the chart.</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
</code></pre>
</li>
<li><p><strong>Create a New Chart</strong>: The <code>Chart</code> constructor creates a new chart. You need to pass two arguments: the context and a configuration object.</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">var</span> myChart = <span class="hljs-keyword">new</span> Chart(ctx, {
     <span class="hljs-attr">type</span>: <span class="hljs-string">'bar'</span>, <span class="hljs-comment">// The type of chart we want to create</span>
</code></pre>
</li>
<li><p><strong>Data Object</strong>: The <code>data</code> property of the configuration object defines the chart's data and labels. In this example, we use an array of colors as labels and an array of numbers as data points.</p>
<pre><code class="lang-javascript"> data: {
     <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Red'</span>, <span class="hljs-string">'Blue'</span>, <span class="hljs-string">'Yellow'</span>, <span class="hljs-string">'Green'</span>, <span class="hljs-string">'Purple'</span>, <span class="hljs-string">'Orange'</span>],
     <span class="hljs-attr">datasets</span>: [{
         <span class="hljs-attr">label</span>: <span class="hljs-string">'Votes'</span>,
         <span class="hljs-attr">data</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">19</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
</code></pre>
</li>
<li><p><strong>Styling</strong>: The <code>backgroundColor</code> and <code>borderColor</code> properties specify the colors for the bars and their borders. The <code>borderWidth</code> sets the width of the borders.</p>
<pre><code class="lang-javascript"> backgroundColor: [
     <span class="hljs-string">'rgba(255, 99, 132, 0.2)'</span>,
     <span class="hljs-string">'rgba(54, 162, 235, 0.2)'</span>,
     <span class="hljs-string">'rgba(255, 206, 86, 0.2)'</span>,
     <span class="hljs-string">'rgba(75, 192, 192, 0.2)'</span>,
     <span class="hljs-string">'rgba(153, 102, 255, 0.2)'</span>,
     <span class="hljs-string">'rgba(255, 159, 64, 0.2)'</span>
 ],
 <span class="hljs-attr">borderColor</span>: [
     <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
     <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
     <span class="hljs-string">'rgba(255, 206, 86, 1)'</span>,
     <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
     <span class="hljs-string">'rgba(153, 102, 255, 1)'</span>,
     <span class="hljs-string">'rgba(255, 159, 64, 1)'</span>
 ],
 <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
</code></pre>
</li>
<li><p><strong>Options Object</strong>: The <code>options</code> property contains configuration options for the chart. In this example, we set the <code>beginAtZero</code> option to <code>true</code> to start the y-axis at 0.</p>
<pre><code class="lang-javascript"> options: {
     <span class="hljs-attr">scales</span>: {
         <span class="hljs-attr">y</span>: {
             <span class="hljs-attr">beginAtZero</span>: <span class="hljs-literal">true</span>
         }
     }
 }
</code></pre>
</li>
</ol>
<h3 id="heading-view-your-chart">View Your Chart</h3>
<p>Once you've added the code, open the HTML file in a web browser. You should see a bar chart displaying the data you provided.</p>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/joanayebola/embed/YzowGeQ?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/joanayebola/pen/YzowGeQ">
  Basic Chart.js example</a> by joan? (<a href="https://codepen.io/joanayebola">@joanayebola</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<p>Congratulations, you've created your first chart with Chart.js!</p>
<p>Feel free to experiment with different chart types, data, and customization options to explore the full potential of Chart.js.</p>
<h2 id="heading-chart-types-in-chartjs">Chart Types in Chart.js</h2>
<p>Chart.js supports a variety of chart types, each designed to visualize data in different ways. Below are some of the most commonly used chart types available in Chart.js:</p>
<h3 id="heading-1-line-chart">1. Line Chart</h3>
<p>A line chart is used to show trends over time or to demonstrate continuous data. It's effective for displaying data that changes continuously over a period. Here's an example of a simple line chart:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
    <span class="hljs-keyword">var</span> lineChart = <span class="hljs-keyword">new</span> Chart(ctx, {
      <span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>,
      <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">labels</span>: [<span class="hljs-string">'January'</span>, <span class="hljs-string">'February'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>, <span class="hljs-string">'May'</span>, <span class="hljs-string">'June'</span>],
        <span class="hljs-attr">datasets</span>: [{
          <span class="hljs-attr">label</span>: <span class="hljs-string">'Sales'</span>,
          <span class="hljs-attr">data</span>: [<span class="hljs-number">30</span>, <span class="hljs-number">45</span>, <span class="hljs-number">60</span>, <span class="hljs-number">35</span>, <span class="hljs-number">50</span>, <span class="hljs-number">40</span>],
          <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
          <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">2</span>,
          <span class="hljs-attr">fill</span>: <span class="hljs-literal">false</span>
        }]
      },
      <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">scales</span>: {
          <span class="hljs-attr">y</span>: {
            <span class="hljs-attr">beginAtZero</span>: <span class="hljs-literal">true</span>
          }
        }
      }
    });
</code></pre>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/joanayebola/embed/eYwJdKY?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/joanayebola/pen/eYwJdKY">
  Line Chart</a> by joan? (<a href="https://codepen.io/joanayebola">@joanayebola</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<h3 id="heading-2-bar-chart">2. Bar Chart</h3>
<p>A bar chart is used to compare different categories of data. It's ideal for showing discrete data points and comparing magnitudes between categories. Here's how you can create one:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
<span class="hljs-keyword">var</span> barChart = <span class="hljs-keyword">new</span> Chart(ctx, {
    <span class="hljs-attr">type</span>: <span class="hljs-string">'bar'</span>,
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Red'</span>, <span class="hljs-string">'Blue'</span>, <span class="hljs-string">'Yellow'</span>, <span class="hljs-string">'Green'</span>, <span class="hljs-string">'Purple'</span>, <span class="hljs-string">'Orange'</span>],
        <span class="hljs-attr">datasets</span>: [{
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Votes'</span>,
            <span class="hljs-attr">data</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">19</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
            <span class="hljs-attr">backgroundColor</span>: [
                <span class="hljs-string">'rgba(255, 99, 132, 0.2)'</span>,
                <span class="hljs-string">'rgba(54, 162, 235, 0.2)'</span>,
                <span class="hljs-string">'rgba(255, 206, 86, 0.2)'</span>,
                <span class="hljs-string">'rgba(75, 192, 192, 0.2)'</span>,
                <span class="hljs-string">'rgba(153, 102, 255, 0.2)'</span>,
                <span class="hljs-string">'rgba(255, 159, 64, 0.2)'</span>
            ],
            <span class="hljs-attr">borderColor</span>: [
                <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
                <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                <span class="hljs-string">'rgba(255, 206, 86, 1)'</span>,
                <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
                <span class="hljs-string">'rgba(153, 102, 255, 1)'</span>,
                <span class="hljs-string">'rgba(255, 159, 64, 1)'</span>
            ],
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
        }]
    },
    <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">scales</span>: {
            <span class="hljs-attr">y</span>: {
                <span class="hljs-attr">beginAtZero</span>: <span class="hljs-literal">true</span>
            }
        }
    }
});
</code></pre>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/joanayebola/embed/BagjLOO?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/joanayebola/pen/BagjLOO">
  Bar Chart</a> by joan? (<a href="https://codepen.io/joanayebola">@joanayebola</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<h3 id="heading-3-pie-chart">3. Pie Chart</h3>
<p>A pie chart is used to show proportions or percentages of a whole. It's effective for illustrating how parts contribute to the whole. Here's what one looks like in code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
<span class="hljs-keyword">var</span> pieChart = <span class="hljs-keyword">new</span> Chart(ctx, {
    <span class="hljs-attr">type</span>: <span class="hljs-string">'pie'</span>,
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Red'</span>, <span class="hljs-string">'Blue'</span>, <span class="hljs-string">'Yellow'</span>, <span class="hljs-string">'Green'</span>, <span class="hljs-string">'Purple'</span>, <span class="hljs-string">'Orange'</span>],
        <span class="hljs-attr">datasets</span>: [{
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Votes'</span>,
            <span class="hljs-attr">data</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">19</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
            <span class="hljs-attr">backgroundColor</span>: [
                <span class="hljs-string">'rgba(255, 99, 132, 0.2)'</span>,
                <span class="hljs-string">'rgba(54, 162, 235, 0.2)'</span>,
                <span class="hljs-string">'rgba(255, 206, 86, 0.2)'</span>,
                <span class="hljs-string">'rgba(75, 192, 192, 0.2)'</span>,
                <span class="hljs-string">'rgba(153, 102, 255, 0.2)'</span>,
                <span class="hljs-string">'rgba(255, 159, 64, 0.2)'</span>
            ],
            <span class="hljs-attr">borderColor</span>: [
                <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
                <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                <span class="hljs-string">'rgba(255, 206, 86, 1)'</span>,
                <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
                <span class="hljs-string">'rgba(153, 102, 255, 1)'</span>,
                <span class="hljs-string">'rgba(255, 159, 64, 1)'</span>
            ],
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
        }]
    },
    <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">responsive</span>: <span class="hljs-literal">true</span>,
        <span class="hljs-attr">plugins</span>: {
            <span class="hljs-attr">legend</span>: {
                <span class="hljs-attr">position</span>: <span class="hljs-string">'top'</span>,
            },
            <span class="hljs-attr">tooltip</span>: {
                <span class="hljs-attr">callbacks</span>: {
                    <span class="hljs-attr">label</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">tooltipItem</span>) </span>{
                        <span class="hljs-keyword">return</span> tooltipItem.label + <span class="hljs-string">': '</span> + tooltipItem.raw.toFixed(<span class="hljs-number">2</span>);
                    }
                }
            }
        }
    }
});
</code></pre>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/joanayebola/embed/vYqLXQW?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/joanayebola/pen/vYqLXQW">
  Pie Chart</a> by joan? (<a href="https://codepen.io/joanayebola">@joanayebola</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<h3 id="heading-4-doughnut-chart">4. Doughnut Chart</h3>
<p>A doughnut chart is similar to a pie chart but has a hollow center. It's useful for comparing proportions while also displaying total values.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
<span class="hljs-keyword">var</span> doughnutChart = <span class="hljs-keyword">new</span> Chart(ctx, {
    <span class="hljs-attr">type</span>: <span class="hljs-string">'doughnut'</span>,
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Red'</span>, <span class="hljs-string">'Blue'</span>, <span class="hljs-string">'Yellow'</span>, <span class="hljs-string">'Green'</span>, <span class="hljs-string">'Purple'</span>, <span class="hljs-string">'Orange'</span>],
        <span class="hljs-attr">datasets</span>: [{
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Votes'</span>,
            <span class="hljs-attr">data</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">19</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
            <span class="hljs-attr">backgroundColor</span>: [
                <span class="hljs-string">'rgba(255, 99, 132, 0.2)'</span>,
                <span class="hljs-string">'rgba(54, 162, 235, 0.2)'</span>,
                <span class="hljs-string">'rgba(255, 206, 86, 0.2)'</span>,
                <span class="hljs-string">'rgba(75, 192, 192, 0.2)'</span>,
                <span class="hljs-string">'rgba(153, 102, 255, 0.2)'</span>,
                <span class="hljs-string">'rgba(255, 159, 64, 0.2)'</span>
            ],
            <span class="hljs-attr">borderColor</span>: [
                <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
                <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                <span class="hljs-string">'rgba(255, 206, 86, 1)'</span>,
                <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
                <span class="hljs-string">'rgba(153, 102, 255, 1)'</span>,
                <span class="hljs-string">'rgba(255, 159, 64, 1)'</span>
            ],
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
        }]
    },
    <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">responsive</span>: <span class="hljs-literal">true</span>,
        <span class="hljs-attr">plugins</span>: {
            <span class="hljs-attr">legend</span>: {
                <span class="hljs-attr">position</span>: <span class="hljs-string">'top'</span>,
            },
            <span class="hljs-attr">tooltip</span>: {
                <span class="hljs-attr">callbacks</span>: {
                    <span class="hljs-attr">label</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">tooltipItem</span>) </span>{
                        <span class="hljs-keyword">return</span> tooltipItem.label + <span class="hljs-string">': '</span> + tooltipItem.raw.toFixed(<span class="hljs-number">2</span>);
                    }
                }
            }
        }
    }
});
</code></pre>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/joanayebola/embed/VwJeKgM?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/joanayebola/pen/VwJeKgM">
  Doughnut Chart</a> by joan? (<a href="https://codepen.io/joanayebola">@joanayebola</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<h3 id="heading-5-scatter-charts">5. Scatter Charts</h3>
<p>A scatter chart is used to display relationships between two or more variables. It's effective for showing correlations and distributions of data points.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
<span class="hljs-keyword">var</span> scatterChart = <span class="hljs-keyword">new</span> Chart(ctx, {
    <span class="hljs-attr">type</span>: <span class="hljs-string">'scatter'</span>,
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">datasets</span>: [{
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Scatter Dataset'</span>,
            <span class="hljs-attr">data</span>: [
                { <span class="hljs-attr">x</span>: <span class="hljs-number">10</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">20</span> },
                { <span class="hljs-attr">x</span>: <span class="hljs-number">15</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">25</span> },
                { <span class="hljs-attr">x</span>: <span class="hljs-number">7</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">10</span> },
                { <span class="hljs-attr">x</span>: <span class="hljs-number">12</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">18</span> },
                { <span class="hljs-attr">x</span>: <span class="hljs-number">20</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">30</span> }
            ],
            <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">'rgba(54, 162, 235, 0.5)'</span>,
            <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
        }]
    },
    <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">scales</span>: {
            <span class="hljs-attr">x</span>: {
                <span class="hljs-attr">type</span>: <span class="hljs-string">'linear'</span>, <span class="hljs-comment">// Scatter charts support only 'linear' scale type for x-axis</span>
                <span class="hljs-attr">position</span>: <span class="hljs-string">'bottom'</span>
            },
            <span class="hljs-attr">y</span>: {
                <span class="hljs-attr">type</span>: <span class="hljs-string">'linear'</span>, <span class="hljs-comment">// Scatter charts support only 'linear' scale type for y-axis</span>
                <span class="hljs-attr">position</span>: <span class="hljs-string">'left'</span>
            }
        }
    }
});
</code></pre>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/joanayebola/embed/dyBGOPJ?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/joanayebola/pen/dyBGOPJ">
  Scatter Chart</a> by joan? (<a href="https://codepen.io/joanayebola">@joanayebola</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<h3 id="heading-6-bubble-charts">6. Bubble Charts</h3>
<p>A bubble chart is similar to a scatter chart but uses bubble-like markers to represent data points. It's useful for comparing relationships between variables and showing data distribution with sizes of bubbles.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
<span class="hljs-keyword">var</span> bubbleChart = <span class="hljs-keyword">new</span> Chart(ctx, {
    <span class="hljs-attr">type</span>: <span class="hljs-string">'bubble'</span>,
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">datasets</span>: [{
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Bubble Dataset'</span>,
            <span class="hljs-attr">data</span>: [
                { <span class="hljs-attr">x</span>: <span class="hljs-number">10</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">20</span>, <span class="hljs-attr">r</span>: <span class="hljs-number">5</span> },
                { <span class="hljs-attr">x</span>: <span class="hljs-number">15</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">25</span>, <span class="hljs-attr">r</span>: <span class="hljs-number">8</span> },
                { <span class="hljs-attr">x</span>: <span class="hljs-number">7</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">10</span>, <span class="hljs-attr">r</span>: <span class="hljs-number">6</span> },
                { <span class="hljs-attr">x</span>: <span class="hljs-number">12</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">18</span>, <span class="hljs-attr">r</span>: <span class="hljs-number">10</span> },
                { <span class="hljs-attr">x</span>: <span class="hljs-number">20</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">30</span>, <span class="hljs-attr">r</span>: <span class="hljs-number">7</span> }
            ],
            <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">'rgba(255, 99, 132, 0.5)'</span>,
            <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
        }]
    },
    <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">scales</span>: {
            <span class="hljs-attr">x</span>: {
                <span class="hljs-attr">type</span>: <span class="hljs-string">'linear'</span>, <span class="hljs-comment">// Bubble charts support only 'linear' scale type for x-axis</span>
                <span class="hljs-attr">position</span>: <span class="hljs-string">'bottom'</span>
            },
            <span class="hljs-attr">y</span>: {
                <span class="hljs-attr">type</span>: <span class="hljs-string">'linear'</span>, <span class="hljs-comment">// Bubble charts support only 'linear' scale type for y-axis</span>
                <span class="hljs-attr">position</span>: <span class="hljs-string">'left'</span>
            }
        }
    }
});
</code></pre>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/joanayebola/embed/ExBPNjZ?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/joanayebola/pen/ExBPNjZ">
  Bubble Chart</a> by joan? (<a href="https://codepen.io/joanayebola">@joanayebola</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<h3 id="heading-7-radar-chart">7. Radar Chart</h3>
<p>A radar chart (or spider chart) is used to display multivariate data in the form of a two-dimensional chart of three or more quantitative variables represented on axes starting from the same point. Here's how you can create one:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
<span class="hljs-keyword">var</span> radarChart = <span class="hljs-keyword">new</span> Chart(ctx, {
    <span class="hljs-attr">type</span>: <span class="hljs-string">'radar'</span>,
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Math'</span>, <span class="hljs-string">'Physics'</span>, <span class="hljs-string">'Chemistry'</span>, <span class="hljs-string">'Biology'</span>, <span class="hljs-string">'English'</span>, <span class="hljs-string">'History'</span>],
        <span class="hljs-attr">datasets</span>: [{
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Student A'</span>,
            <span class="hljs-attr">data</span>: [<span class="hljs-number">85</span>, <span class="hljs-number">90</span>, <span class="hljs-number">75</span>, <span class="hljs-number">80</span>, <span class="hljs-number">70</span>, <span class="hljs-number">85</span>],
            <span class="hljs-attr">fill</span>: <span class="hljs-literal">true</span>,
            <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">'rgba(54, 162, 235, 0.2)'</span>,
            <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
            <span class="hljs-attr">pointBackgroundColor</span>: <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
            <span class="hljs-attr">pointBorderColor</span>: <span class="hljs-string">'#fff'</span>,
            <span class="hljs-attr">pointHoverBackgroundColor</span>: <span class="hljs-string">'#fff'</span>,
            <span class="hljs-attr">pointHoverBorderColor</span>: <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
        }, {
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Student B'</span>,
            <span class="hljs-attr">data</span>: [<span class="hljs-number">70</span>, <span class="hljs-number">85</span>, <span class="hljs-number">80</span>, <span class="hljs-number">75</span>, <span class="hljs-number">85</span>, <span class="hljs-number">90</span>],
            <span class="hljs-attr">fill</span>: <span class="hljs-literal">true</span>,
            <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">'rgba(255, 99, 132, 0.2)'</span>,
            <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
            <span class="hljs-attr">pointBackgroundColor</span>: <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
            <span class="hljs-attr">pointBorderColor</span>: <span class="hljs-string">'#fff'</span>,
            <span class="hljs-attr">pointHoverBackgroundColor</span>: <span class="hljs-string">'#fff'</span>,
            <span class="hljs-attr">pointHoverBorderColor</span>: <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
        }]
    },
    <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">scales</span>: {
            <span class="hljs-attr">r</span>: {
                <span class="hljs-attr">suggestedMin</span>: <span class="hljs-number">0</span>,
                <span class="hljs-attr">suggestedMax</span>: <span class="hljs-number">100</span>
            }
        }
    }
});
</code></pre>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/joanayebola/embed/Yzowpya?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/joanayebola/pen/Yzowpya">
  Untitled</a> by joan? (<a href="https://codepen.io/joanayebola">@joanayebola</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<h3 id="heading-8-polar-area-chart">8. Polar Area Chart</h3>
<p>A polar area chart is similar to a pie chart, but the sectors are equal angles and differ in how far they extend from the center of the circle. It's useful for showing data distributions with the proportion of each category.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
<span class="hljs-keyword">var</span> polarAreaChart = <span class="hljs-keyword">new</span> Chart(ctx, {
    <span class="hljs-attr">type</span>: <span class="hljs-string">'polarArea'</span>,
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Red'</span>, <span class="hljs-string">'Blue'</span>, <span class="hljs-string">'Yellow'</span>, <span class="hljs-string">'Green'</span>, <span class="hljs-string">'Purple'</span>, <span class="hljs-string">'Orange'</span>],
        <span class="hljs-attr">datasets</span>: [{
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Votes'</span>,
            <span class="hljs-attr">data</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">19</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
            <span class="hljs-attr">backgroundColor</span>: [
                <span class="hljs-string">'rgba(255, 99, 132, 0.5)'</span>,
                <span class="hljs-string">'rgba(54, 162, 235, 0.5)'</span>,
                <span class="hljs-string">'rgba(255, 206, 86, 0.5)'</span>,
                <span class="hljs-string">'rgba(75, 192, 192, 0.5)'</span>,
                <span class="hljs-string">'rgba(153, 102, 255, 0.5)'</span>,
                <span class="hljs-string">'rgba(255, 159, 64, 0.5)'</span>
            ],
            <span class="hljs-attr">borderColor</span>: [
                <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
                <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                <span class="hljs-string">'rgba(255, 206, 86, 1)'</span>,
                <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
                <span class="hljs-string">'rgba(153, 102, 255, 1)'</span>,
                <span class="hljs-string">'rgba(255, 159, 64, 1)'</span>
            ],
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
        }]
    },
    <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">scales</span>: {
            <span class="hljs-attr">r</span>: {
                <span class="hljs-attr">suggestedMin</span>: <span class="hljs-number">0</span>,
                <span class="hljs-attr">suggestedMax</span>: <span class="hljs-number">20</span>
            }
        }
    }
});
</code></pre>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/joanayebola/embed/zYVroqN?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/joanayebola/pen/zYVroqN">
  Polar Area Chart</a> by joan? (<a href="https://codepen.io/joanayebola">@joanayebola</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<p>These are just a few examples of the chart types available in Chart.js. Each chart type has its own unique features and is suitable for different types of data visualization tasks. Experiment with these chart types and explore Chart.js documentation for more advanced options and customization.</p>
<h2 id="heading-customization-and-interactivity-in-chartjs">Customization and Interactivity in Chart.js</h2>
<p>Chart.js offers extensive options for customizing the appearance and interactivity of your charts. This section covers customizing chart appearance, adding tooltips and legends, and making charts interactive with features like zooming and hovering.</p>
<h3 id="heading-customizing-chart-appearance">Customizing Chart Appearance</h3>
<p>Customizing the appearance of your charts helps make them more visually appealing and tailored to your specific needs. You can customize colors, fonts, borders, and other properties.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> customChart = <span class="hljs-keyword">new</span> Chart(ctx, {
    <span class="hljs-attr">type</span>: <span class="hljs-string">'bar'</span>,
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Red'</span>, <span class="hljs-string">'Blue'</span>, <span class="hljs-string">'Yellow'</span>, <span class="hljs-string">'Green'</span>, <span class="hljs-string">'Purple'</span>, <span class="hljs-string">'Orange'</span>],
        <span class="hljs-attr">datasets</span>: [{
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Votes'</span>,
            <span class="hljs-attr">data</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">19</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
            <span class="hljs-attr">backgroundColor</span>: [
                <span class="hljs-string">'rgba(255, 99, 132, 0.8)'</span>,
                <span class="hljs-string">'rgba(54, 162, 235, 0.8)'</span>,
                <span class="hljs-string">'rgba(255, 206, 86, 0.8)'</span>,
                <span class="hljs-string">'rgba(75, 192, 192, 0.8)'</span>,
                <span class="hljs-string">'rgba(153, 102, 255, 0.8)'</span>,
                <span class="hljs-string">'rgba(255, 159, 64, 0.8)'</span>
            ],
            <span class="hljs-attr">borderColor</span>: [
                <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
                <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                <span class="hljs-string">'rgba(255, 206, 86, 1)'</span>,
                <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
                <span class="hljs-string">'rgba(153, 102, 255, 1)'</span>,
                <span class="hljs-string">'rgba(255, 159, 64, 1)'</span>
            ],
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">2</span>
        }]
    },
    <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">plugins</span>: {
            <span class="hljs-attr">legend</span>: {
                <span class="hljs-attr">display</span>: <span class="hljs-literal">true</span>,
                <span class="hljs-attr">labels</span>: {
                    <span class="hljs-attr">color</span>: <span class="hljs-string">'rgb(255, 99, 132)'</span>,
                    <span class="hljs-attr">font</span>: {
                        <span class="hljs-attr">size</span>: <span class="hljs-number">16</span>,
                        <span class="hljs-attr">family</span>: <span class="hljs-string">"'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"</span>
                    }
                }
            },
            <span class="hljs-attr">tooltip</span>: {
                <span class="hljs-attr">backgroundColor</span>: <span class="hljs-string">'rgba(0, 0, 0, 0.8)'</span>,
                <span class="hljs-attr">titleFont</span>: {
                    <span class="hljs-attr">size</span>: <span class="hljs-number">18</span>
                },
                <span class="hljs-attr">bodyFont</span>: {
                    <span class="hljs-attr">size</span>: <span class="hljs-number">14</span>
                },
                <span class="hljs-attr">callbacks</span>: {
                    <span class="hljs-attr">label</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">context</span>) </span>{
                        <span class="hljs-keyword">return</span> context.dataset.label + <span class="hljs-string">': '</span> + context.raw + <span class="hljs-string">' votes'</span>;
                    }
                }
            }
        },
        <span class="hljs-attr">scales</span>: {
            <span class="hljs-attr">x</span>: {
                <span class="hljs-attr">ticks</span>: {
                    <span class="hljs-attr">color</span>: <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                    <span class="hljs-attr">font</span>: {
                        <span class="hljs-attr">size</span>: <span class="hljs-number">14</span>
                    }
                }
            },
            <span class="hljs-attr">y</span>: {
                <span class="hljs-attr">ticks</span>: {
                    <span class="hljs-attr">color</span>: <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                    <span class="hljs-attr">font</span>: {
                        <span class="hljs-attr">size</span>: <span class="hljs-number">14</span>
                    }
                }
            }
        }
    }
});
</code></pre>
<p>In this example:</p>
<ul>
<li><p><strong>Chart Type:</strong> The chart is defined as a <code>bar</code> chart.</p>
</li>
<li><p><strong>Background and Border Colors:</strong> The <code>backgroundColor</code> and <code>borderColor</code> arrays are customized for each bar. For example, the "Red" bar is colored with a semi-transparent background (<code>rgba(255, 99, 132, 0.8)</code>) and a solid border (<code>rgba(255, 99, 132, 1)</code>).</p>
</li>
<li><p><strong>Font and Color for Legends:</strong> The <code>legend</code> configuration customizes the display of the chart’s legend, where the font size is set to 16, and the font family is <code>'Helvetica Neue', 'Helvetica', 'Arial', sans-serif'</code>. Additionally, the text color of the legend labels is customized to <code>rgb(255, 99, 132)</code>.</p>
</li>
<li><p><strong>Font and Color for Axes:</strong> The <code>scales</code> section customizes the appearance of both the X and Y axes. The font size for axis labels is set to 14, and their color is <code>rgba(54, 162, 235, 1)</code>.</p>
</li>
</ul>
<h3 id="heading-adding-tooltips-and-legends">Adding Tooltips and Legends</h3>
<p>Tooltips provide additional information when you hover over chart elements. Legends help users understand the data by showing which dataset each color represents. Both can be customized extensively, like this for example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> chartWithTooltipsAndLegend = <span class="hljs-keyword">new</span> Chart(ctx, {
    <span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>,
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">labels</span>: [<span class="hljs-string">'January'</span>, <span class="hljs-string">'February'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>, <span class="hljs-string">'May'</span>, <span class="hljs-string">'June'</span>],
        <span class="hljs-attr">datasets</span>: [{
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Sales'</span>,
            <span class="hljs-attr">data</span>: [<span class="hljs-number">30</span>, <span class="hljs-number">45</span>, <span class="hljs-number">60</span>, <span class="hljs-number">35</span>, <span class="hljs-number">50</span>, <span class="hljs-number">40</span>],
            <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">2</span>,
            <span class="hljs-attr">fill</span>: <span class="hljs-literal">false</span>
        }]
    },
    <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">plugins</span>: {
            <span class="hljs-attr">legend</span>: {
                <span class="hljs-attr">display</span>: <span class="hljs-literal">true</span>,
                <span class="hljs-attr">position</span>: <span class="hljs-string">'top'</span>,
                <span class="hljs-attr">labels</span>: {
                    <span class="hljs-attr">font</span>: {
                        <span class="hljs-attr">size</span>: <span class="hljs-number">14</span>
                    }
                }
            },
            <span class="hljs-attr">tooltip</span>: {
                <span class="hljs-attr">enabled</span>: <span class="hljs-literal">true</span>,
                <span class="hljs-attr">callbacks</span>: {
                    <span class="hljs-attr">label</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">tooltipItem</span>) </span>{
                        <span class="hljs-keyword">return</span> <span class="hljs-string">'Sales: $'</span> + tooltipItem.raw;
                    }
                }
            }
        }
    }
});
</code></pre>
<p>In this example:</p>
<ul>
<li><p><strong>Tooltips:</strong> Tooltips appear when the user hovers over elements of the chart. The tooltip background is customized to be black (<code>rgba(0, 0, 0, 0.8)</code>) with font sizes for both the title (18) and body text (14). The content of the tooltip is dynamically generated by a <code>callback</code> function, which appends the word "votes" to the dataset value.</p>
</li>
<li><p><strong>Legends:</strong> The legends describe the data on the chart and are placed at the top. The customization here includes setting the font size to 14 and making the legend displayable by configuring <code>display: true</code>.</p>
</li>
</ul>
<h3 id="heading-making-charts-interactive-zooming-hovering-and-so-on">Making Charts Interactive (Zooming, Hovering, and so on)</h3>
<p>Adding interactivity to your charts can enhance the user experience. Features like zooming, panning, and custom hover effects can be implemented using additional Chart.js plugins such as <code>chartjs-plugin-zoom</code>.</p>
<p>First, include the zoom plugin in your project:</p>
<pre><code class="lang-html"><span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom@1.0.0"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
<p>Then, configure your chart to enable zooming and panning:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> interactiveChart = <span class="hljs-keyword">new</span> Chart(ctx, {
    <span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>,
    <span class="hljs-attr">data</span>: {
        <span class="hljs-attr">labels</span>: [<span class="hljs-string">'January'</span>, <span class="hljs-string">'February'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>, <span class="hljs-string">'May'</span>, <span class="hljs-string">'June'</span>],
        <span class="hljs-attr">datasets</span>: [{
            <span class="hljs-attr">label</span>: <span class="hljs-string">'Sales'</span>,
            <span class="hljs-attr">data</span>: [<span class="hljs-number">30</span>, <span class="hljs-number">45</span>, <span class="hljs-number">60</span>, <span class="hljs-number">35</span>, <span class="hljs-number">50</span>, <span class="hljs-number">40</span>],
            <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
            <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">2</span>,
            <span class="hljs-attr">fill</span>: <span class="hljs-literal">false</span>
        }]
    },
    <span class="hljs-attr">options</span>: {
        <span class="hljs-attr">plugins</span>: {
            <span class="hljs-attr">zoom</span>: {
                <span class="hljs-attr">pan</span>: {
                    <span class="hljs-attr">enabled</span>: <span class="hljs-literal">true</span>,
                    <span class="hljs-attr">mode</span>: <span class="hljs-string">'xy'</span>
                },
                <span class="hljs-attr">zoom</span>: {
                    <span class="hljs-attr">enabled</span>: <span class="hljs-literal">true</span>,
                    <span class="hljs-attr">mode</span>: <span class="hljs-string">'xy'</span>
                }
            }
        },
        <span class="hljs-attr">hover</span>: {
            <span class="hljs-attr">mode</span>: <span class="hljs-string">'nearest'</span>,
            <span class="hljs-attr">intersect</span>: <span class="hljs-literal">true</span>
        }
    }
});
</code></pre>
<p>In this example:</p>
<ul>
<li><p><strong>Zoom and Pan</strong>: The <code>chartjs-plugin-zoom</code> plugin is used to add zooming and panning capabilities. Users can zoom in and out using the mouse wheel or pan by dragging.</p>
</li>
<li><p><strong>Hover Mode</strong>: The <code>hover</code> option is set to <code>nearest</code>, ensuring the nearest data point is highlighted when hovered over.</p>
</li>
</ul>
<h3 id="heading-complete-html-example">Complete HTML Example</h3>
<p>Here's the complete HTML file incorporating the examples above:</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Chart.js Customization and Interactivity<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/chart.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom@1.0.0"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Chart.js Customization and Interactivity<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Customizing Chart Appearance<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"customChart"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"400"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"200"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Adding Tooltips and Legends<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"tooltipsAndLegendChart"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"400"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"200"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Making Charts Interactive (Zooming, Hovering, etc.)<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"interactiveChart"</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"400"</span> <span class="hljs-attr">height</span>=<span class="hljs-string">"200"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span>
        // Customizing Chart Appearance
        var customCtx = document.getElementById('customChart').getContext('2d');
        var customChart = new Chart(customCtx, {
            type: 'bar',
            data: {
                labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
                datasets: [{
                    label: 'Votes',
                    data: [12, 19, 3, 5, 2, 3],
                    backgroundColor: [
                        'rgba(255, 99, 132, 0.8)',
                        'rgba(54, 162, 235, 0.8)',
                        'rgba(255, 206, 86, 0.8)',
                        'rgba(75, 192, 192, 0.8)',
                        'rgba(153, 102, 255, 0.8)',
                        'rgba(255, 159, 64, 0.8)'
                    ],
                    borderColor: [
                        'rgba(255, 99, 132, 1)',
                        'rgba(54, 162, 235, 1)',
                        'rgba(255, 206, 86, 1)',
                        'rgba(75, 192, 192, 1)',
                        'rgba(153, 102, 255, 1)',
                        'rgba(255, 159, 64, 1)'
                    ],
                    borderWidth: 2
                }]
            },
            options: {
                plugins: {
                    legend: {
                        display: true,
                        labels: {
                            color: 'rgb(255, 99, 132)',
                            font: {
                                size: 16,
                                family: "'Helvetica Neue', 'Helvetica', 'Arial', sans-serif"
                            }
                        }
                    },
                    tooltip: {
                        backgroundColor: 'rgba(0, 0, 0, 0.8)',
                        titleFont: {
                            size: 18
                        },
                        bodyFont: {
                            size: 14
                        },
                        callbacks: {
                            label: function(context) {
                                return context.dataset.label + ': ' + context.raw + ' votes';
                            }
                        }
                    }
                },
                scales: {
                    x: {
                        ticks: {
                            color: 'rgba(54, 162, 235, 1)',
                            font: {
                                size: 14
                            }
                        }
                    },
                    y: {
                        ticks: {
                            color: 'rgba(54, 162, 235, 1)',
                            font: {
                                size: 14
                            }
                        }
                    }
                }
            }
        });

        // Adding Tooltips and Legends
        var tooltipsAndLegendCtx = document.getElementById('

tooltipsAndLegendChart').getContext('2d');
        var chartWithTooltipsAndLegend = new Chart(tooltipsAndLegendCtx, {
            type: 'line',
            data: {
                labels: ['January', 'February', 'March', 'April', 'May', 'June'],
                datasets: [{
                    label: 'Sales',
                    data: [30, 45, 60, 35, 50, 40],
                    borderColor: 'rgba(54, 162, 235, 1)',
                    borderWidth: 2,
                    fill: false
                }]
            },
            options: {
                plugins: {
                    legend: {
                        display: true,
                        position: 'top',
                        labels: {
                            font: {
                                size: 14
                            }
                        }
                    },
                    tooltip: {
                        enabled: true,
                        callbacks: {
                            label: function(tooltipItem) {
                                return 'Sales: $' + tooltipItem.raw;
                            }
                        }
                    }
                }
            }
        });

        // Making Charts Interactive (Zooming, Hovering, etc.)
        var interactiveCtx = document.getElementById('interactiveChart').getContext('2d');
        var interactiveChart = new Chart(interactiveCtx, {
            type: 'line',
            data: {
                labels: ['January', 'February', 'March', 'April', 'May', 'June'],
                datasets: [{
                    label: 'Sales',
                    data: [30, 45, 60, 35, 50, 40],
                    borderColor: 'rgba(54, 162, 235, 1)',
                    borderWidth: 2,
                    fill: false
                }]
            },
            options: {
                plugins: {
                    zoom: {
                        pan: {
                            enabled: true,
                            mode: 'xy'
                        },
                        zoom: {
                            enabled: true,
                            mode: 'xy'
                        }
                    }
                },
                hover: {
                    mode: 'nearest',
                    intersect: true
                }
            }
        });
    <span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></pre>
<div class="embed-wrapper"><iframe height="300" style="width:100%" src="https://codepen.io/joanayebola/embed/QWXyGqb?default-tab=html%2Cresult" title="Embedded content" loading="lazy">
  See the Pen <a href="https://codepen.io/joanayebola/pen/QWXyGqb">
  Untitled</a> by joan? (<a href="https://codepen.io/joanayebola">@joanayebola</a>)
  on <a href="https://codepen.io">CodePen</a>.
</iframe></div>

<p>This HTML file includes examples of customizing chart appearance, adding tooltips and legends, and making charts interactive. You can view the results by opening this HTML file in a web browser.</p>
<h2 id="heading-how-to-work-with-data-in-chartjs">How to Work with Data in Chart.js</h2>
<p>Chart.js provides versatile capabilities for handling data, accommodating various formats and requirements for data visualization:</p>
<h3 id="heading-data-formats-supported-by-chartjs">Data Formats Supported by Chart.js</h3>
<p>Chart.js provides flexible support for various data formats to accommodate different data structures and needs:</p>
<ul>
<li><p><strong>Arrays</strong>: Simple arrays of values are the most basic format and can be directly used to plot data points.</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> data = [<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">30</span>, <span class="hljs-number">40</span>, <span class="hljs-number">50</span>];
</code></pre>
</li>
<li><p><strong>Objects</strong>: Arrays of objects are useful for more complex data where each object represents a data point with multiple properties.</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> data = [
      { <span class="hljs-attr">x</span>: <span class="hljs-number">10</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">20</span> },
      { <span class="hljs-attr">x</span>: <span class="hljs-number">15</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">25</span> },
      { <span class="hljs-attr">x</span>: <span class="hljs-number">20</span>, <span class="hljs-attr">y</span>: <span class="hljs-number">30</span> }
  ];
</code></pre>
</li>
<li><p><strong>JSON</strong>: JSON (JavaScript Object Notation) is ideal for structured data interchange, allowing for clear organization of labels and datasets.</p>
<pre><code class="lang-json">  {
      <span class="hljs-attr">"labels"</span>: [<span class="hljs-string">"January"</span>, <span class="hljs-string">"February"</span>, <span class="hljs-string">"March"</span>, <span class="hljs-string">"April"</span>],
      <span class="hljs-attr">"datasets"</span>: [{
          <span class="hljs-attr">"label"</span>: <span class="hljs-string">"Sales"</span>,
          <span class="hljs-attr">"data"</span>: [<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">30</span>, <span class="hljs-number">40</span>]
      }]
  }
</code></pre>
</li>
<li><p><strong>CSV</strong>: Comma-Separated Values (CSV) are commonly used for tabular data and can be parsed into arrays or objects for Chart.js.</p>
</li>
</ul>
<h3 id="heading-how-to-load-data-from-external-files-json-csv">How to Load Data from External Files (JSON, CSV)</h3>
<p>Loading data from external files is essential for handling dynamic or large datasets efficiently:</p>
<ul>
<li><p><strong>Loading JSON Data</strong>: Use the <code>fetch</code> API to retrieve JSON data and integrate it into Chart.js.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
      fetch(<span class="hljs-string">'data.json'</span>)
          .then(<span class="hljs-function"><span class="hljs-params">response</span> =&gt;</span> response.json())
          .then(<span class="hljs-function"><span class="hljs-params">data</span> =&gt;</span> {
              <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
              <span class="hljs-keyword">new</span> Chart(ctx, {
                  <span class="hljs-attr">type</span>: <span class="hljs-string">'bar'</span>,
                  <span class="hljs-attr">data</span>: data,
                  <span class="hljs-attr">options</span>: {}
              });
          });
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Loading CSV Data</strong>: Utilize libraries like PapaParse to parse CSV files into usable data formats for Chart.js visualization.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.3.0/papaparse.min.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
      Papa.parse(<span class="hljs-string">'data.csv'</span>, {
          <span class="hljs-attr">download</span>: <span class="hljs-literal">true</span>,
          <span class="hljs-attr">header</span>: <span class="hljs-literal">true</span>,
          <span class="hljs-attr">complete</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">results</span>) </span>{
              <span class="hljs-keyword">const</span> labels = results.data.map(<span class="hljs-function"><span class="hljs-params">row</span> =&gt;</span> row[<span class="hljs-string">'Month'</span>]);
              <span class="hljs-keyword">const</span> data = results.data.map(<span class="hljs-function"><span class="hljs-params">row</span> =&gt;</span> <span class="hljs-built_in">parseFloat</span>(row[<span class="hljs-string">'Sales'</span>]));

              <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
              <span class="hljs-keyword">new</span> Chart(ctx, {
                  <span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>,
                  <span class="hljs-attr">data</span>: {
                      <span class="hljs-attr">labels</span>: labels,
                      <span class="hljs-attr">datasets</span>: [{
                          <span class="hljs-attr">label</span>: <span class="hljs-string">'Sales'</span>,
                          <span class="hljs-attr">data</span>: data
                      }]
                  },
                  <span class="hljs-attr">options</span>: {}
              });
          }
      });
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
</li>
</ul>
<h3 id="heading-dynamic-data-updates">Dynamic Data Updates</h3>
<p>Chart.js supports dynamic data updates, which is crucial for real-time data visualization:</p>
<ul>
<li><p><strong>Updating Data Dynamically</strong>: Use Chart.js methods to update chart data dynamically and re-render the chart as needed.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
      <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'myChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
      <span class="hljs-keyword">const</span> myChart = <span class="hljs-keyword">new</span> Chart(ctx, {
          <span class="hljs-attr">type</span>: <span class="hljs-string">'bar'</span>,
          <span class="hljs-attr">data</span>: {
              <span class="hljs-attr">labels</span>: [<span class="hljs-string">'January'</span>, <span class="hljs-string">'February'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>],
              <span class="hljs-attr">datasets</span>: [{
                  <span class="hljs-attr">label</span>: <span class="hljs-string">'Sales'</span>,
                  <span class="hljs-attr">data</span>: [<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">30</span>, <span class="hljs-number">40</span>]
              }]
          },
          <span class="hljs-attr">options</span>: {}
      });

      <span class="hljs-comment">// Example function to update the chart data</span>
      <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">updateChartData</span>(<span class="hljs-params"></span>) </span>{
          myChart.data.datasets[<span class="hljs-number">0</span>].data = [<span class="hljs-number">50</span>, <span class="hljs-number">60</span>, <span class="hljs-number">70</span>, <span class="hljs-number">80</span>];
          myChart.update();
      }

      <span class="hljs-comment">// Call the update function after 2 seconds</span>
      <span class="hljs-built_in">setTimeout</span>(updateChartData, <span class="hljs-number">2000</span>);
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
</li>
</ul>
<p>In this section, we've explored the various data formats supported by Chart.js, methods for loading data from external files such as JSON and CSV, and how to implement dynamic data updates for real-time visualization. These features make Chart.js a powerful tool for interactive data visualization in web applications.</p>
<h2 id="heading-advanced-chartjs-features">Advanced Chart.js Features</h2>
<p>Chart.js offers advanced features that enhance data visualization capabilities beyond basic charts. Let's delve into these features:</p>
<h3 id="heading-how-to-combine-different-chart-types">How to Combine Different Chart Types</h3>
<p>Chart.js allows you to combine different chart types within a single chart, offering flexibility in visualizing complex data sets:</p>
<ul>
<li><p><strong>Mixed Chart Types</strong>: You can mix line, bar, radar, and other chart types in a single chart to represent diverse datasets effectively.</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'mixedChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
  <span class="hljs-keyword">const</span> mixedChart = <span class="hljs-keyword">new</span> Chart(ctx, {
      <span class="hljs-attr">type</span>: <span class="hljs-string">'bar'</span>, <span class="hljs-comment">// Default type for the main dataset</span>
      <span class="hljs-attr">data</span>: {
          <span class="hljs-attr">labels</span>: [<span class="hljs-string">'January'</span>, <span class="hljs-string">'February'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>, <span class="hljs-string">'May'</span>, <span class="hljs-string">'June'</span>],
          <span class="hljs-attr">datasets</span>: [{
              <span class="hljs-attr">label</span>: <span class="hljs-string">'Sales'</span>,
              <span class="hljs-attr">data</span>: [<span class="hljs-number">50</span>, <span class="hljs-number">60</span>, <span class="hljs-number">70</span>, <span class="hljs-number">80</span>, <span class="hljs-number">90</span>, <span class="hljs-number">100</span>],
              <span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>, <span class="hljs-comment">// Specific type for this dataset</span>
              <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
              <span class="hljs-attr">tension</span>: <span class="hljs-number">0.1</span>
          }]
      },
      <span class="hljs-attr">options</span>: {}
  });
</code></pre>
</li>
</ul>
<h3 id="heading-how-to-create-chart-animations">How to Create Chart Animations</h3>
<p>Animations in Chart.js can bring your data visualizations to life, providing a dynamic and engaging user experience:</p>
<ul>
<li><p><strong>Animated Transitions</strong>: Configure animations to smoothly transition between different states, enhancing the clarity of data changes over time.</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'animatedChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
  <span class="hljs-keyword">const</span> animatedChart = <span class="hljs-keyword">new</span> Chart(ctx, {
      <span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>,
      <span class="hljs-attr">data</span>: {
          <span class="hljs-attr">labels</span>: [<span class="hljs-string">'January'</span>, <span class="hljs-string">'February'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>, <span class="hljs-string">'May'</span>, <span class="hljs-string">'June'</span>],
          <span class="hljs-attr">datasets</span>: [{
              <span class="hljs-attr">label</span>: <span class="hljs-string">'Sales'</span>,
              <span class="hljs-attr">data</span>: [<span class="hljs-number">50</span>, <span class="hljs-number">60</span>, <span class="hljs-number">70</span>, <span class="hljs-number">80</span>, <span class="hljs-number">90</span>, <span class="hljs-number">100</span>],
              <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
              <span class="hljs-attr">tension</span>: <span class="hljs-number">0.1</span>
          }]
      },
      <span class="hljs-attr">options</span>: {
          <span class="hljs-attr">animation</span>: {
              <span class="hljs-attr">duration</span>: <span class="hljs-number">2000</span>, <span class="hljs-comment">// Animation duration in milliseconds</span>
              <span class="hljs-attr">easing</span>: <span class="hljs-string">'easeInOutQuart'</span> <span class="hljs-comment">// Easing function for smooth animation</span>
          }
      }
  });
</code></pre>
</li>
</ul>
<h3 id="heading-how-to-use-third-party-plugins">How to Use Third-Party Plugins</h3>
<p>Extend Chart.js functionality with third-party plugins to add custom features and enhance visualization capabilities:</p>
<ul>
<li><p><strong>Integration of Plugins</strong>: Integrate plugins like zoom, tooltip enhancements, or data label customization to tailor charts to specific needs.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="javascript">
      <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'pluginChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
      <span class="hljs-keyword">const</span> pluginChart = <span class="hljs-keyword">new</span> Chart(ctx, {
          <span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>,
          <span class="hljs-attr">data</span>: {
              <span class="hljs-attr">labels</span>: [<span class="hljs-string">'January'</span>, <span class="hljs-string">'February'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>, <span class="hljs-string">'May'</span>, <span class="hljs-string">'June'</span>],
              <span class="hljs-attr">datasets</span>: [{
                  <span class="hljs-attr">label</span>: <span class="hljs-string">'Sales'</span>,
                  <span class="hljs-attr">data</span>: [<span class="hljs-number">50</span>, <span class="hljs-number">60</span>, <span class="hljs-number">70</span>, <span class="hljs-number">80</span>, <span class="hljs-number">90</span>, <span class="hljs-number">100</span>],
                  <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
                  <span class="hljs-attr">tension</span>: <span class="hljs-number">0.1</span>
              }]
          },
          <span class="hljs-attr">options</span>: {
              <span class="hljs-attr">plugins</span>: {
                  <span class="hljs-attr">zoom</span>: {
                      <span class="hljs-attr">pan</span>: {
                          <span class="hljs-attr">enabled</span>: <span class="hljs-literal">true</span>,
                          <span class="hljs-attr">mode</span>: <span class="hljs-string">'xy'</span>
                      },
                      <span class="hljs-attr">zoom</span>: {
                          <span class="hljs-attr">enabled</span>: <span class="hljs-literal">true</span>,
                          <span class="hljs-attr">mode</span>: <span class="hljs-string">'xy'</span>
                      }
                  }
              }
          }
      });
  </span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
</code></pre>
</li>
</ul>
<h2 id="heading-best-practices-for-chart-design">Best Practices for Chart Design</h2>
<p>Effective chart design ensures that your data is presented clearly and accurately, making it easy for users to understand and interpret. Here are some best practices to consider:</p>
<h3 id="heading-choose-the-right-chart-type">Choose the Right Chart Type</h3>
<p>Selecting the appropriate chart type is crucial for conveying your data effectively:</p>
<ul>
<li><p><strong>Bar Charts</strong>: Ideal for comparing different categories or tracking changes over time. Use bar charts when you have discrete data points.</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'barChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
  <span class="hljs-keyword">const</span> barChart = <span class="hljs-keyword">new</span> Chart(ctx, {
      <span class="hljs-attr">type</span>: <span class="hljs-string">'bar'</span>,
      <span class="hljs-attr">data</span>: {
          <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Red'</span>, <span class="hljs-string">'Blue'</span>, <span class="hljs-string">'Yellow'</span>, <span class="hljs-string">'Green'</span>, <span class="hljs-string">'Purple'</span>, <span class="hljs-string">'Orange'</span>],
          <span class="hljs-attr">datasets</span>: [{
              <span class="hljs-attr">label</span>: <span class="hljs-string">'Votes'</span>,
              <span class="hljs-attr">data</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">19</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
              <span class="hljs-attr">backgroundColor</span>: [
                  <span class="hljs-string">'rgba(255, 99, 132, 0.2)'</span>,
                  <span class="hljs-string">'rgba(54, 162, 235, 0.2)'</span>,
                  <span class="hljs-string">'rgba(255, 206, 86, 0.2)'</span>,
                  <span class="hljs-string">'rgba(75, 192, 192, 0.2)'</span>,
                  <span class="hljs-string">'rgba(153, 102, 255, 0.2)'</span>,
                  <span class="hljs-string">'rgba(255, 159, 64, 0.2)'</span>
              ],
              <span class="hljs-attr">borderColor</span>: [
                  <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
                  <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                  <span class="hljs-string">'rgba(255, 206, 86, 1)'</span>,
                  <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
                  <span class="hljs-string">'rgba(153, 102, 255, 1)'</span>,
                  <span class="hljs-string">'rgba(255, 159, 64, 1)'</span>
              ],
              <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
          }]
      },
      <span class="hljs-attr">options</span>: {
          <span class="hljs-attr">scales</span>: {
              <span class="hljs-attr">y</span>: {
                  <span class="hljs-attr">beginAtZero</span>: <span class="hljs-literal">true</span>
              }
          }
      }
  });
</code></pre>
</li>
<li><p><strong>Line Charts</strong>: Best for showing trends over time or continuous data. Line charts are useful when you want to highlight changes and patterns.</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'lineChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
  <span class="hljs-keyword">const</span> lineChart = <span class="hljs-keyword">new</span> Chart(ctx, {
      <span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>,
      <span class="hljs-attr">data</span>: {
          <span class="hljs-attr">labels</span>: [<span class="hljs-string">'January'</span>, <span class="hljs-string">'February'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>, <span class="hljs-string">'May'</span>, <span class="hljs-string">'June'</span>],
          <span class="hljs-attr">datasets</span>: [{
              <span class="hljs-attr">label</span>: <span class="hljs-string">'Sales'</span>,
              <span class="hljs-attr">data</span>: [<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">30</span>, <span class="hljs-number">40</span>, <span class="hljs-number">50</span>, <span class="hljs-number">60</span>],
              <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
              <span class="hljs-attr">tension</span>: <span class="hljs-number">0.1</span>
          }]
      },
      <span class="hljs-attr">options</span>: {}
  });
</code></pre>
</li>
<li><p><strong>Pie and Doughnut Charts</strong>: Suitable for displaying proportions and parts of a whole. Use these charts when you want to highlight distribution.</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'doughnutChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
  <span class="hljs-keyword">const</span> doughnutChart = <span class="hljs-keyword">new</span> Chart(ctx, {
      <span class="hljs-attr">type</span>: <span class="hljs-string">'doughnut'</span>,
      <span class="hljs-attr">data</span>: {
          <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Red'</span>, <span class="hljs-string">'Blue'</span>, <span class="hljs-string">'Yellow'</span>],
          <span class="hljs-attr">datasets</span>: [{
              <span class="hljs-attr">label</span>: <span class="hljs-string">'Votes'</span>,
              <span class="hljs-attr">data</span>: [<span class="hljs-number">300</span>, <span class="hljs-number">50</span>, <span class="hljs-number">100</span>],
              <span class="hljs-attr">backgroundColor</span>: [
                  <span class="hljs-string">'rgba(255, 99, 132, 0.2)'</span>,
                  <span class="hljs-string">'rgba(54, 162, 235, 0.2)'</span>,
                  <span class="hljs-string">'rgba(255, 206, 86, 0.2)'</span>
              ],
              <span class="hljs-attr">borderColor</span>: [
                  <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
                  <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                  <span class="hljs-string">'rgba(255, 206, 86, 1)'</span>
              ],
              <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
          }]
      },
      <span class="hljs-attr">options</span>: {}
  });
</code></pre>
</li>
</ul>
<h3 id="heading-design-for-clarity-and-readability">Design for Clarity and Readability</h3>
<p>Clear and readable charts help users understand data quickly and accurately:</p>
<ul>
<li><p><strong>Use Appropriate Labels</strong>: Ensure that all axes, data points, and legends are clearly labeled. Avoid cluttering the chart with too much information.</p>
</li>
<li><p><strong>Color Choices</strong>: Use contrasting colors to differentiate between data points or categories. Ensure that color choices are accessible to those with color vision deficiencies.</p>
</li>
<li><p><strong>Simplify Data</strong>: Avoid overloading the chart with too much data. Focus on the key message you want to convey and use additional charts for supplementary information.</p>
</li>
<li><p><strong>Consistent Scale</strong>: Use a consistent scale across charts when comparing similar data sets. This helps users make accurate comparisons without recalibrating their understanding of the scale.</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'clarityChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
  <span class="hljs-keyword">const</span> clarityChart = <span class="hljs-keyword">new</span> Chart(ctx, {
      <span class="hljs-attr">type</span>: <span class="hljs-string">'line'</span>,
      <span class="hljs-attr">data</span>: {
          <span class="hljs-attr">labels</span>: [<span class="hljs-string">'January'</span>, <span class="hljs-string">'February'</span>, <span class="hljs-string">'March'</span>, <span class="hljs-string">'April'</span>, <span class="hljs-string">'May'</span>, <span class="hljs-string">'June'</span>],
          <span class="hljs-attr">datasets</span>: [{
              <span class="hljs-attr">label</span>: <span class="hljs-string">'Sales'</span>,
              <span class="hljs-attr">data</span>: [<span class="hljs-number">10</span>, <span class="hljs-number">20</span>, <span class="hljs-number">30</span>, <span class="hljs-number">40</span>, <span class="hljs-number">50</span>, <span class="hljs-number">60</span>],
              <span class="hljs-attr">borderColor</span>: <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
              <span class="hljs-attr">tension</span>: <span class="hljs-number">0.1</span>
          }]
      },
      <span class="hljs-attr">options</span>: {
          <span class="hljs-attr">scales</span>: {
              <span class="hljs-attr">y</span>: {
                  <span class="hljs-attr">beginAtZero</span>: <span class="hljs-literal">true</span>
              }
          }
      }
  });
</code></pre>
</li>
</ul>
<h3 id="heading-make-charts-accessible">Make Charts Accessible</h3>
<p>Accessibility ensures that your charts can be understood by all users, including those with disabilities:</p>
<ul>
<li><p><strong>Use ARIA Labels</strong>: Implement ARIA (Accessible Rich Internet Applications) labels to provide additional context to screen readers.</p>
<pre><code class="lang-html">  <span class="hljs-tag">&lt;<span class="hljs-name">canvas</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"accessibleChart"</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">"Sales Data"</span> <span class="hljs-attr">role</span>=<span class="hljs-string">"img"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">canvas</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Provide Alternative Text</strong>: Include descriptive alternative text for charts, especially if the chart is complex. This helps users who rely on screen readers to understand the chart's content.</p>
</li>
<li><p><strong>Keyboard Navigation</strong>: Ensure that all interactive elements of the chart, such as tooltips and legends, are accessible via keyboard navigation.</p>
</li>
<li><p><strong>High Contrast Colors</strong>: Use high contrast colors for better visibility, especially for users with low vision or color blindness.</p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> ctx = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'accessibleChart'</span>).getContext(<span class="hljs-string">'2d'</span>);
  <span class="hljs-keyword">const</span> accessibleChart = <span class="hljs-keyword">new</span> Chart(ctx, {
      <span class="hljs-attr">type</span>: <span class="hljs-string">'bar'</span>,
      <span class="hljs-attr">data</span>: {
          <span class="hljs-attr">labels</span>: [<span class="hljs-string">'Red'</span>, <span class="hljs-string">'Blue'</span>, <span class="hljs-string">'Yellow'</span>, <span class="hljs-string">'Green'</span>, <span class="hljs-string">'Purple'</span>, <span class="hljs-string">'Orange'</span>],
          <span class="hljs-attr">datasets</span>: [{
              <span class="hljs-attr">label</span>: <span class="hljs-string">'Votes'</span>,
              <span class="hljs-attr">data</span>: [<span class="hljs-number">12</span>, <span class="hljs-number">19</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
              <span class="hljs-attr">backgroundColor</span>: [
                  <span class="hljs-string">'rgba(255, 99, 132, 0.8)'</span>,
                  <span class="hljs-string">'rgba(54, 162, 235, 0.8)'</span>,
                  <span class="hljs-string">'rgba(255, 206, 86, 0.8)'</span>,
                  <span class="hljs-string">'rgba(75, 192, 192, 0.8)'</span>,
                  <span class="hljs-string">'rgba(153, 102, 255, 0.8)'</span>,
                  <span class="hljs-string">'rgba(255, 159, 64, 0.8)'</span>
              ],
              <span class="hljs-attr">borderColor</span>: [
                  <span class="hljs-string">'rgba(255, 99, 132, 1)'</span>,
                  <span class="hljs-string">'rgba(54, 162, 235, 1)'</span>,
                  <span class="hljs-string">'rgba(255, 206, 86, 1)'</span>,
                  <span class="hljs-string">'rgba(75, 192, 192, 1)'</span>,
                  <span class="hljs-string">'rgba(153, 102, 255, 1)'</span>,
                  <span class="hljs-string">'rgba(255, 159, 64, 1)'</span>
              ],
              <span class="hljs-attr">borderWidth</span>: <span class="hljs-number">1</span>
          }]
      },
      <span class="hljs-attr">options</span>: {
          <span class="hljs-attr">scales</span>: {
              <span class="hljs-attr">y</span>: {
                  <span class="hljs-attr">beginAtZero</span>: <span class="hljs-literal">true</span>
              }
          }
      }
  });
</code></pre>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Using Chart.js for interactive data visualization is a great way to turn raw data into clear, engaging charts. This tool is easy to use and offers many types of charts, like bar, line, and pie charts. You can also customize your charts to make them look exactly how you want.</p>
<p>Chart.js is not only good for basic charts but also has advanced features. You can combine different types of charts, add animations, and use plugins to add extra functions like zooming. It supports various data formats, can load data from files, and update data in real-time.</p>
<p>When designing your charts, it’s important to choose the right type of chart for your data, keep your charts clear and easy to read, and make sure they are accessible to everyone, including people with disabilities.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
