Sourcegraphlabs
Get Cody

Welcome to the LLM Litmus Test

Compare and find out which LLM works best for your AI coding cases.

Toggle Cody Context to see how Sourcegraph's Cody Context can improve your answers.

This is an LLM comparison between:

GPT-4 Turbo

vs

Claude 3 Opus

Using the following repos: ashokdelphia/recharts

GPT-4 Turbo
how would implement a pie chart?

Cody Context Enabled!

Read 315 lines in 15 files

To implement a pie chart using Recharts, a popular React charting library, you can follow these steps. Here's a basic example to get you started:

  1. Install Recharts: If you haven't already installed Recharts, you can add it to your project by running:

    1npm install recharts
  2. Import Components: Import the necessary components from Recharts in your React component file.

    1import { PieChart, Pie, Tooltip, Legend, Cell } from 'recharts';
  3. Prepare the Data: Define the data that the PieChart will use. This should be an array of objects where each object represents a slice of the pie with value and name properties.

    1const data = [ 2 { name: 'Group A', value: 400 }, 3 { name: 'Group B', value: 300 }, 4 { name: 'Group C', value: 300 }, 5 { name: 'Group D', value: 200 }, 6];
  4. Render the PieChart: Use the PieChart and Pie components to render the pie chart. You can customize the pie chart with additional props like fill, dataKey, etc.

    1function MyPieChart() { 2 return ( 3 <PieChart width={400} height={400}> 4 <Pie 5 data={data} 6 cx={200} 7 cy={200} 8 outerRadius={80} 9 fill="#8884d8" 10 dataKey="value" 11 label 12 > 13 { 14 data.map((entry, index) => <Cell key={`cell-${index}`} fill={entry.color}/>) 15 } 16 </Pie> 17 <Tooltip /> 18 <Legend /> 19 </PieChart> 20 ); 21}
  5. Customization: You can customize the chart further by adding tooltips, legends, and labels. The Tooltip and Legend components from Recharts can be used directly without additional configuration for basic usage. The Cell component inside the Pie can be used to customize the colors of each slice.

  6. Integrate the Chart: Finally, integrate the MyPieChart component wherever you need it within your React application.

This basic setup will give you a functional pie chart using Recharts. You can explore more properties and customization options in the Recharts documentation to better suit your needs.

Claude 3 Opus
how would implement a pie chart?

Cody Context Enabled!

Read 315 lines in 15 files

To implement a pie chart using the code snippets you provided from the recharts repository, you can use the PieChart and Pie components. Here's an example of how you can create a pie chart:

1import React, { Component } from 'react'; 2import { PieChart, Pie, Cell, Tooltip, ResponsiveContainer } from 'recharts'; 3 4const data = [ 5 { name: 'Group A', value: 400 }, 6 { name: 'Group B', value: 300 }, 7 { name: 'Group C', value: 200 }, 8 { name: 'Group D', value: 200 }, 9]; 10 11const COLORS = ['#0088FE', '#00C49F', '#FFBB28', '#FF8042']; 12 13class Example extends Component { 14 render() { 15 return ( 16 <ResponsiveContainer width="100%" height={400}> 17 <PieChart> 18 <Pie 19 data={data} 20 cx="50%" 21 cy="50%" 22 labelLine={false} 23 outerRadius={80} 24 fill="#8884d8" 25 dataKey="value" 26 > 27 {data.map((entry, index) => ( 28 <Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} /> 29 ))} 30 </Pie> 31 <Tooltip /> 32 </PieChart> 33 </ResponsiveContainer> 34 ); 35 } 36} 37 38export default Example;

In this example:

  1. We import the necessary components from recharts: PieChart, Pie, Cell, Tooltip, and ResponsiveContainer.

  2. We define the data for the pie chart as an array of objects, where each object has a name and a value property.

  3. We define an array of colors (COLORS) to be used for the slices of the pie chart.

  4. In the render method, we create a ResponsiveContainer component to make the chart responsive to the container's width and height.

  5. Inside the ResponsiveContainer, we render the PieChart component.

  6. We add a Pie component inside the PieChart and pass the necessary props:

    • data: The data array for the pie chart.
    • cx and cy: The coordinates of the center of the pie.
    • labelLine: Set to false to disable the label lines.
    • outerRadius: The outer radius of the pie.
    • fill: The default fill color for the slices.
    • dataKey: The key in the data object to use as the value for each slice.
  7. We map over the data array and render a Cell component for each data entry, assigning a unique key and a fill color from the COLORS array.

  8. Finally, we add a Tooltip component to display information when hovering over the slices.

This code will render a basic pie chart with the provided data. You can customize the appearance and behavior of the pie chart by modifying the props and adding additional components as needed.