Skip to content

Integrating with chartjs-plugin-datalabels #18

Description

@bwgjoseph

Hi,

I was wondering if it is possible to add in fields to the PieOptions if I wanted to use it with chartjs-plugin-datalabels extension.

So with Pie Chart, we can do something like this.

PieChart chart = new PieChart();
chart.setData(new PieData())); // Set some data / dataset
chart.setOptions(new PieOptions()); // Set  `cutoutPercentage` and `rotation`.

So for the PieOptions, you have specified fields that can be set for Pie Chart options which makes the end result in JSON look like... If I were to set in cutoutPercentage and rotation.

options: {
responsive: true,
cutoutPercentage: 10,
rotation: 10
}

So for the chartjs-plugin-datalabels, they have some additional fields that can be set like this example from their page. *This isn't exactly PieChart, but it doesn't really matter what type of chart here.

options: {
	plugins: {
		datalabels: {
			anchor: 'end',
			borderColor: 'white',
			borderRadius: 25,
			borderWidth: 2,
			color: 'white',
			font: {
				weight: 'bold'
			},
		}
	}
}

So if I mix it up, it would become... (I suppose)

options: {
	plugins: {
		datalabels: {
			anchor: 'end',
			borderColor: 'white',
			borderRadius: 25,
			borderWidth: 2,
			color: 'white',
			font: {
				weight: 'bold'
			},
		}
	},
	responsive: true,
	cutoutPercentage: 10,
	rotation: 10
}

Question is, how can I extend the PieOptions to add in new fields that allow me to set in the

plugins: {
		datalabels: {
			anchor: 'end',
			borderColor: 'white',
			borderRadius: 25,
			borderWidth: 2,
			color: 'white',
			font: {
				weight: 'bold'
			},
		}
	},

specified portion of the plugin....

Thanks.. And let me know if there is any other better way to do so.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions