ArticleZip > Highcharts Make The Pie Chart 100 Of The Div

Highcharts Make The Pie Chart 100 Of The Div

Have you ever wanted to create a stunning pie chart that perfectly fits the space within a div on your webpage? Well, you're in luck because with Highcharts, you can easily achieve this! In this article, I'll guide you through the simple steps to make your pie chart fill 100% of the div container. Let's get started!

First things first, make sure you have Highcharts installed in your project. You can include it using a CDN link or by downloading the library directly. Once you have Highcharts set up, create a new HTML file or open an existing one where you want to implement the pie chart.

Next, let's add a div element to your HTML file where you want the pie chart to appear. Give it a unique ID so that we can easily target it in our JavaScript code. For example, you can name it "chartContainer".

Now, it's time to write the JavaScript code to initialize Highcharts and create your pie chart. You can use the following code snippet as a template:

Javascript

Highcharts.chart('chartContainer', {
  chart: {
    type: 'pie',
    height: '100%'
  },
  title: {
    text: 'Your Pie Chart Title'
  },
  series: [{
    name: 'Categories',
    data: [
      ['Category 1', 25],
      ['Category 2', 40],
      ['Category 3', 15],
      ['Category 4', 20]
    ]
  }]
});

In the code above, we specify the chart type as 'pie' and set the height of the chart to '100%', ensuring it fills the entire div. You can customize the chart title and data to suit your needs. Feel free to add more data points or modify the colors and styles of the chart to match your website's design.

If you want to make the pie chart responsive and resize dynamically with the div container, you can achieve this by setting the `chart.width` property to 'null'. This way, the chart will adapt to the size of the container as it changes.

That's it! You've successfully created a pie chart using Highcharts that fills 100% of the div container. You can now save your HTML file and open it in a web browser to see your beautiful chart in action.

In conclusion, Highcharts is a powerful tool for creating interactive and visually appealing charts on your website. By following these simple steps, you can easily make a pie chart that fits perfectly within a div element. Experiment with different chart types, colors, and configurations to bring your data to life and engage your website visitors. Happy coding!

×