Mudblazor pie/doughnut slice colors - charts

I am exploring Mudblazor. I created a doughnut chart and it works fine. But I need to define the colors of the slices of the pie/doughnut. I see you can have a class for the entire chart, but how do set custom colors for each slice of the pie?
The default for a 3 slice pie is like blue, teal and gold. I need to change those colors and will need to be changed in code also.
The theming palette options don't seem to have options for this.
Thanks,
Michael
Edit: I figured it out. In case anyone else needs to do this. Example:
ChartOptions options = new ChartOptions();
protected override void OnInitialized()
{
string[] colors = { "#ff0000", "#00FF00","#0000ff" };
options.ChartPalette = colors;
}
Chart-add ChartOptions="#options":

Related

Custom Colors on ThemeColor class

I have trying to set a custom color to a FileDecorationProvider class, the color should be set to text. I have been using charts colors but that limits me to like 6 colors.
The below method works but I am limited to chart colors(like 6 of them)
async provideFileDecoration(uri: vscode.Uri): Promise<FileDecoration | undefined> {
if (uri.fsPath === '\\temp11') {
return {
color: new ThemeColor("charts.red")
};
}
return undefined;
}
But I would like to something like this:
return {
color: new ThemeColor("#0000ff")
};
Use HexCode to set a custom color.
The ThemeColor API only supports workbench colors (https://code.visualstudio.com/docs/getstarted/theme-color-reference), which means hex values are not allowed. And since provideFileDecoration only works with ThemeColor and not string, you won't be able to use hex values at all.
You could however, define a new color for your extension (via https://code.visualstudio.com/api/references/contribution-points#contributes.colors), so the end user will be allowed to define its own color, via hex values.
Hope this helps
As #alefragnani suggests, you can define a new color in the package.json like this:
"contributes": {
"colors": [
{
"id": "editorManager.treeItemTextForeground", // your custom name here
"description": "Color for a TreeIteem label", // your description
"defaults": {
"dark": "#00ccff", // your own defined colors, not just references to other exisiting themeColors
"light": "#00ccff",
"highContrast": "errorForeground" // you can also use existing color theme references here
}
}
]
}
and then use it wherever a themeColor is accepted:
color: new ThemeColor("editorManager.treeItemTextForeground")
The end user will also be able to modify that color in their settings colorCustomizations.

Highchart Gantt chart Navigator color

I am rendering a Gantt chart with different series color. The colors are somehow not reflected on the navigator at the bottom. How can I display the same colors in both series and navigator?
Fiddle link : Fiddle
Note: These colors are going to be dynamic which will be based on different cases. So I want them to reflect in the navigator too, dynamically.
I am changing color of the series like so :
chart: {
events: {
load: function() {
Highcharts.each(this.series[0].points, function(p) {
p.color = 'grey'
});
}
}
},
As you can see series color is grey but in the navigator below, I see different colors.
As per highcharts-gantt documentation:
Update the series with a new set of options. For a clean and precise handling of new options, all methods and elements from the series are removed, and it is initialized from scratch.
On event, you should then go through given serie points and change its options (in your case 'color').
The changes will be applied in the timeline below - example code changes the color after 1,5sec.
//Updating the color
setTimeout(function() {
for (var i = 0; i < chart.series[0].points.length; i++) {
chart.series[0].points[i].update({
color: "grey"
});
}
}, 1500);
Working example
In your code it would be:
events: {
load: function() {
Highcharts.each(this.series[0].points, function(p) {
p.update({color: "grey"});
});
}
}
To avoid shrink of timeline - launch setExtremes() after chart update.
Fires when the minimum and maximum is set for the axis, either by calling the .setExtremes() method or by selecting an area in the chart.
//Fully selected timeline
this.xAxis[0].setExtremes();
Working example - timeline selection
You can also set options for series of navigator, like below:
navigator: {
series: {
...,
colorByPoint: false,
color: 'grey'
},
...
}
Live demo: https://jsfiddle.net/BlackLabel/c4j9dvqx/
API Reference: https://api.highcharts.com/gantt/navigator.series.color

Is it possible to select multiple markers in a dojo chart and pass their coordinates to an event?

I want to select two or more markers in a chart and perform an action using their coordinates.
Selecting the points is the main problem since I didn't find anything on this topic and I'm not sure if it can be done.
I did something like this in a Pie Chart.
What I did was use "connectToPlot" to change the series color when the user click on it.
This is a resume of the work that I did: change series color when user click on it
See that when you click on the serie, the color changes to gray and if you click again the series returns to it original color (saved it in the attribute "originalColor").
pieChart.connectToPlot("default", function(evt) {
var shape = evt.shape;
var type = evt.type;
if (type == "onclick") {
var fillColor = "rgb("+shape.fillStyle.r+", "+shape.fillStyle.g+", "+shape.fillStyle.b+")"; console.log(shape.fillStyle);
if(shape.rawNode.getAttribute("originalColor")==null)
shape.rawNode.setAttribute("originalColor",fillColor);
var strokeColor = "rgb("+shape.strokeStyle.color.r+", "+shape.strokeStyle.color.g+", "+shape.strokeStyle.color.b+")";
if(fillColor=='rgb(238, 238, 238)'){
shape.setFill(shape.rawNode.getAttribute("originalColor"));
shape.setStroke(shape.rawNode.getAttribute("originalColor"));
}else{
shape.setFill('rgb(238, 238, 238)');
shape.setStroke(shape.rawNode.getAttribute("originalColor"));
}
}

How to get a style using the console

I have a div
<div class="blue>;
The class blue is:
.blue {
background-color: blue;
}
Now I know I can set the background color of the div in the console using:
$0.style.backgroundColor = "#ffcc00"
But what if I want to get the value of the background color for that element using the console?
It's possible you may want computed style:
var style = getComputedStyle(document.body, null); // Gets the style for a passed element and optional pseudo selecter (eg. :hover)
console.log(style.backgroundColor);
It's important to note that computed style is the rendered result. If you have multiple rules for the same element, this will only display the ones that have been applied.
You can do :
var blue = document.getElementsByClassName('blue')[0];
blue.style.getPropertyCSSValue('background-color');
or you do:
blue.style.getPropertyValue('background-color');

jqPlot- issue with displaying bar charts -axis padding and inter-bar distance

I'm using the following piece of code to display a set of bar charts in jqPlot. However, I am getting 2 problems:
There is no padding on either side of the range values for the xaxis. The pad attribute seems to have no effect.
When the number of bars is large, the bars overlap on top of each other. The barPadding attribute seems to have no effect.
I looked at this link Having problems with jqPlot bar chart . The answer suggested there was to use a CategoryAxisRenderer. But since I'm using time-series data, I require the DateAxisRenderer.
Please help.
function plotBarGraph(data,myticks,series)
{
$("#placeholder").empty();
$.jqplot('placeholder',data,
{
//stackSeries:true,
seriesDefaults:{
renderer:$.jqplot.BarRenderer,
barMargin:1,
barPadding:0.5
},
axes:
{
xaxis:
{
ticks:myticks,
tickInterval:10,
renderer:$.jqplot.DateAxisRenderer,
pad:2.5,
tickOptions:
{
formatString:'%d-%m-%y'
}
}
},
legend:
{
show:true,
labels:series
}
});
}
In this case if you do not want to use the approach mentioned in the link, you might want to play with min/max values for your date axis.
I think you might also find useful the approach to a similar sort of problem with padding where I chose to set ticks on creation and hide the unwanted ones after the plot is drawn.
Before I can be of any further assistance please provide a sample presenting your problem.
For your second problem, I ran into a similar issue. I set up a selection statement that widened the size of my chart depending on how many bars would be in it. I then made the parent div scrollable (called "dataHolder"), and that solved the problem.
// set div properties depending on how many sets of data are in the
//array so the view is sized properly
$("#chartDiv").html("").css("width", "750px"); // chartDiv's default settings
$("#tabs-6").removeClass("dataHolder").css("width", "900px"); // parent Div's default settings
if (dataArray.length > 10) {
$("#chartDiv").css("width", "1600px");
$("#tabs-6").addClass("dataHolder").css("width", "900px");
} else if (dataArray.length > 6) {
$("#chartDiv").css("width", "1200px");
$("#tabs-6").addClass("dataHolder").css("width", "900px");
}
I found a solution to use Date data with CategoryAxisRenderer. You have to configure de xaxis like follows:
axes: {
xaxis: {
renderer: $.jqplot.CategoryAxisRenderer,
rendererOptions: {
tickRenderer: $.jqplot.DateTickRenderer,
tickOptions: {
formatter: $.jqplot.DateTickFormatter,
formatString:'%d/%m'
}
}
}
}
I hope it helps! ;)