I'm using Chartjs.Blazor, and I haven't been able to do the same as described here : How to change the color of Chart.js points depending on the label
I've got a list of colors (rgba, or color name, I can choose) under the form of List<String>.
colors = ["rgba(255,0,0,1)", "rgba(0,255,0,1)", "rgba(0,0,255,1)", "rgba(255,0,0,1)", "rgba(0,255,0,1)"];
I tried to specify colors using the LineDataset.PointBackgroundColor property :
var _linebarDataSet = new ChartJs.Blazor.ChartJS.LineChart.LineDataset<ChartJs.Blazor.ChartJS.Common.Point>
{
Label = lineSet.Title,
Hidden = false,
Fill = false,
PointBackgroundColor = colors,
BorderWidth = 3,
PointBorderWidth = 0,
LineTension = 0,
PointRadius = 0,
};
for (int i = 0; i < lineSet.XAxisData.Count; i++)
{
_linebarDataSet.Add(new ChartJs.Blazor.ChartJS.Common.Point(i, lineSet.YAxisData[i]));
}
and tried to pass RGB values as in the example or colors name. It seems only the first definition is applied to all points.
I also tried to use javascript as :
await JSRuntime.InvokeAsync<string>("colorizePoints.HideOtherDatasetsFunc", valuesPoints, this.m_ValuesDataset.Colors);
and this code :
HideOtherDatasetsFunc: function (reference, colors, barchart) {
let colorsCode = []
for (var i = 0, len = colors.length; i < len; i++) {
colorsCode.push(colors[i]);
}
for (var i = 1; i <= reference.data.length - 1; i++) {
reference.pointBackgroundColor[i] = colorsCode[i];
}
}
And think Javascript like this would interfer with the Blazor server side rendering.
My problem using the javascript is to get the 2d context, as it's done in the link using :
var ctx = document.getElementById('lineChart').getContext('2d');
I can't set a fixed id as the CharJS, and retrieve it from javascript, because blazor components cannot stand id properties.
Has anybody an idea how to achieve this goal ?
Thank you for your reading-
This bug concerned 1.0 version.
The problem has been solved using IndexedOptions of the 2.0 version, which has just been released.
Related
I am trying to do the following:
Take render pass 1, render to attachment set S.
Take render pass 2, render to attachment set S again.
There is a one to one explanation on how to do this in the official Khronos github:
Under Graphics to Graphics dependency.
However, trying to implement the same code as in the example isn't working.
This is what I see:
This is what I should see:
What I think is currently happening is that the depth buffer is not being synchronized properly and so depth testing isn't working correctly.
I create both of my render passes like this:
// Create a render pass from the information of a render target
vk::UniqueRenderPass CreateRenderPass(HardwareInterface& hi,
const std::vector<vk::AttachmentDescription>& attachment_descriptions)
{
auto instance = hi.GetInstance();
auto phys_device = hi.GetPhysicalDevice();
auto device = hi.GetDevice();
// Create a reference for each image target the renderpass will render to
std::vector<vk::AttachmentReference> attachment_references(
attachment_descriptions.size());
for(uint i = 0; i < attachment_descriptions.size() - 1; i++)
{
vk::AttachmentReference color_attachment_ref(
i, vk::ImageLayout::eColorAttachmentOptimal);
attachment_references[i] = color_attachment_ref;
}
// Last attachment is depth
vk::AttachmentReference depth_attachment_ref(
attachment_descriptions.size() - 1,
vk::ImageLayout::eDepthStencilAttachmentOptimal);
attachment_references[attachment_references.size() - 1] = depth_attachment_ref;
const uint subpass_num = 1;
vector<vk::SubpassDescription> subpasses(subpass_num);
for(auto& sub_pass: subpasses)
{
// No input attachment (3rd and 4th parameters)
sub_pass = vk::SubpassDescription();
sub_pass.pipelineBindPoint = vk::PipelineBindPoint::eGraphics;
sub_pass.inputAttachmentCount = 0;
sub_pass.pInputAttachments = nullptr;
sub_pass.colorAttachmentCount = attachment_references.size() - 1;
sub_pass.pColorAttachments = attachment_references.data();
sub_pass.pResolveAttachments = nullptr;
sub_pass.pDepthStencilAttachment = &attachment_references.back();
}
vector<vk::SubpassDependency> dependencies(subpass_num);
uint current_dependency = 0;
for(auto& dependency: dependencies)
{
// Set the dependency of this subpass
uint32_t prev = current_dependency == 0 ? (uint32_t)VK_SUBPASS_EXTERNAL
: current_dependency - 1;
uint32_t next = current_dependency;
current_dependency++;
// Execution and memory dependencies between subpasses
dependency = vk::SubpassDependency();
dependency.srcSubpass = prev;
dependency.dstSubpass = next;
dependency.srcStageMask =
vk::PipelineStageFlagBits::eColorAttachmentOutput
| vk::PipelineStageFlagBits::eEarlyFragmentTests
| vk::PipelineStageFlagBits::eLateFragmentTests;
dependency.dstStageMask =
vk::PipelineStageFlagBits::eColorAttachmentOutput
| vk::PipelineStageFlagBits::eEarlyFragmentTests
| vk::PipelineStageFlagBits::eLateFragmentTests;
dependency.srcAccessMask =
vk::AccessFlagBits::eDepthStencilAttachmentWrite |
vk::AccessFlagBits::eDepthStencilAttachmentRead;
dependency.dstAccessMask =
vk::AccessFlagBits::eColorAttachmentRead |
vk::AccessFlagBits::eColorAttachmentWrite |
vk::AccessFlagBits::eDepthStencilAttachmentRead |
vk::AccessFlagBits::eDepthStencilAttachmentWrite;
}
vk::RenderPassCreateInfo render_pass_info(
{},
attachment_descriptions.size(),
attachment_descriptions.data(),
subpasses.size(),
subpasses.data(),
dependencies.size(),
dependencies.data());
auto [result, render_pass] = device.createRenderPassUnique(render_pass_info);
if(result != vk::Result::eSuccess)
Log::RecordLogError("Failed to create render pass!");
return move(render_pass);
}
I have read and reread the example and I have tried to make my code as identical to it as possible but alas, the issue still happens.
The way I created the working image is by having both renders occur under the same render pass, but I don't want to do it that way.
The problem was being caused because when i created the attachment descriptors, I set the storeOp and loadOp enums of the renderpass to eDontCare so the depth buffer was UB for me.
As suggested in the comments by #solidpixel. The solution is to make the first eStore and the second 'eLoad'.
Can we add any shape/image with chart data labels in ASPOSE .I need to show one arrow with different colors according to certain values with each data labels in the chart. i am using ASPOSE to generate my ppt. Or there is any way to find the data label positions in ASPOSE.
I have observed your requirements and like to share that MS PowerPoint supports LineWithMarker chart that can display different predefined or custom marker symbols(in the form of image) for different series data points. Please try using following sample code for possible options using Aspose.Slides and MSO charts.
public static void TestScatter()
{
var location = System.Reflection.Assembly.GetExecutingAssembly().Location;
//Open a presentation
Presentation pres = new Presentation();
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.StackedLineWithMarkers, 10, 10, 400, 400);
//populating cycle
var serie = chart.ChartData.Series[0];
var wbk = chart.ChartData.ChartDataWorkbook;
chart.ChartData.Series.RemoveAt(1);
chart.ChartData.Series.RemoveAt(1);
serie.Marker.Format.Fill.FillType = FillType.Picture;
serie.Marker.Size = 20;
// Set the picture
System.Drawing.Image img = (System.Drawing.Image)new Bitmap(#"C:\Users\Public\Pictures\Sample Pictures\Tulips.jpg");
IPPImage imgx = pres.Images.AddImage(img);
serie.Marker.Format.Fill.PictureFillFormat.Picture.Image = imgx;
//For individual data point
serie.DataPoints[0].Marker.Format.Fill.FillType = FillType.Solid;
serie.DataPoints[0].Marker.Format.Fill.SolidFillColor.Color = Color.Red;
serie.DataPoints[0].Marker.Size = 20;
serie.DataPoints[0].Marker.Symbol = MarkerStyleType.Triangle;
serie.DataPoints[0].Label.DataLabelFormat.ShowValue = true;
serie.DataPoints[1].Label.DataLabelFormat.ShowValue = true;
serie.DataPoints[2].Label.DataLabelFormat.ShowValue = true;
serie.DataPoints[3].Label.DataLabelFormat.ShowValue = true;
pres.Save(Path.Combine(Path.GetDirectoryName(location), "Result2.pptx"), SaveFormat.Pptx);
}
I am working as Support developer/ Evangelist at Aspose.
Many Thanks,
I have further observed your requirements and have observed that you have also posted the similar requirements in Aspose.Slides official support forum as well. Please try using following sample code on your end to serve the purpose.
public static void TestLineChart()
{
var location = System.Reflection.Assembly.GetExecutingAssembly().Location;
//Open a presentation
Presentation pres = new Presentation();
IChart chart = pres.Slides[0].Shapes.AddChart(ChartType.StackedLineWithMarkers, 10, 10, 400, 400);
//populating cycle
var serie = chart.ChartData.Series[0];
var wbk = chart.ChartData.ChartDataWorkbook;
chart.ChartData.Series.RemoveAt(1);
chart.ChartData.Series.RemoveAt(1);
serie.Marker.Format.Fill.FillType = FillType.Picture;
serie.Marker.Size = 20;
serie.Marker.Symbol = MarkerStyleType.Diamond;
serie.Marker.Format.Fill.FillType = FillType.Solid;
serie.Marker.Format.Fill.SolidFillColor.Color=Color.Orange;
serie.Marker.Format.Line.FillFormat.FillType = FillType.Solid;
serie.Marker.Format.Line.FillFormat.SolidFillColor.Color=Color.Red;
serie.Marker.Format.Line.Width=1.0F;
serie.Format.Line.Width = 3.0f;
serie.Format.Line.FillFormat.FillType=FillType.Solid;
serie.Format.Line.FillFormat.SolidFillColor.Color = Color.FromArgb(209,225,91) ;
for(int i=0;i<serie.DataPoints.Count;i++)
{
serie.DataPoints[i].Label.DataLabelFormat.ShowValue = true;
IDataLabel label=serie.Labels[i];
chart.ValidateChartLayout();
IAutoShape ashp=chart.UserShapes.Shapes.AddAutoShape(ShapeType.Triangle,chart.X + label.ActualX + 5, chart.Y + label.ActualY + 5, 20,20);
ashp.FillFormat.FillType = FillType.Solid;
ashp.LineFormat.FillFormat.FillType = FillType.NoFill;
if (i % 2 == 0)//even data points
{
ashp.FillFormat.SolidFillColor.Color = Color.Green;
}
else
{
ashp.Rotation = 180;
ashp.FillFormat.SolidFillColor.Color = Color.Red;
}
}
pres.Save(Path.Combine(Path.GetDirectoryName(location), "Result2.pptx"), Aspose.Slides.Export.SaveFormat.Pptx);
}
I am working as Support developer/ Evangelist at Aspose.
Many Thanks,
My goal is to create 101 separate text layers containing 0-100 (i.e. 1, 2, 3...100) I know I can mass change the attributes but cant write or alter the containing text.
What you want can easily be done with a script (easier than renaming 100 layers in all the right order and record an action for it) This script will create 100 layers of text, each layer will be named 1,2,3..etc and the text will be the same. I think that's waht you are after, your description was rather short.
// call the source document
var srcDoc = app.activeDocument;
var numOfLayers = 100;
//var numOfLayers = srcDoc.layers.length;
var numPadding = "0";
var layerNum = 1; // change this to 0 to start layers at 0
var w = Math.floor(srcDoc.width.value/2);
var h = Math.floor(srcDoc.height.value/2);
// main loop starts here
for (var i = numOfLayers -1; i >= 0 ; i--)
{
if (layerNum < 10) numPadding = "0";
else numPadding ="";
createText("Arial-BoldMT", 20.0, 0,0,0, layerNum, w, h);
var currentLayer = srcDoc.activeLayer;
currentLayer.name = numPadding + layerNum;
layerNum +=1;
}
// function CREATE TEXT(typeface, size, R, G, B, content, Xpos, Ypos)
// --------------------------------------------------------
function createText(fface, size, colR, colG, colB, content, tX, tY)
{
var artLayerRef = srcDoc.artLayers.add()
artLayerRef.kind = LayerKind.TEXT
textColor = new SolidColor();
textColor.rgb.red = colR;
textColor.rgb.green = colG;
textColor.rgb.blue = colB;
textItemRef = artLayerRef.textItem
textItemRef.font = fface;
textItemRef.contents = content;
textItemRef.color = textColor;
textItemRef.size = size
textItemRef.position = new Array(tX, tY) //pixels from the left, pixels from the top
activeDocument.activeLayer.textItem.justification.CENTER
}
Save this out as numberLayers1-100.jsx and then reun it from Photoshop via the Files -> Scripts menu.
I have a Visualisation table with server side constructed JSON.When I try to use color formatting based on cell value, it applies for particular only. I need to apply color for complete row based on the single cell value.
For Example,
C1 C2 C3 C4
R1 - - - 0 // This row should be "red"
R2 - - - 1 // This row should be "green"
R3 - - - 0
R4 - - - 1
But the color applies for C4 only.
MyCode :
var dataTable = new google.visualization.DataTable(data, 0.5);
var formatter_short1 = new google.visualization.DateFormat({pattern:'h:mm aa'});
formatter_short1.format(dataTable,1);
formatter_short1.format(dataTable,2);
var view = new google.visualization.DataView(dataTable);
view.hideColumns([0,3,4,5,8,9,14]);
var color_formatter = new google.visualization.ColorFormat();
color_formatter.addRange(0,1, 'green', 'orange');
color_formatter.addRange(1,null, 'orange', 'green');
//color_formatter.format(dataTable, 1,2,6,7,9,11,12,13); // Apply formatter to 10 column
color_formatter.format(dataTable, 10); // Apply formatter to 10 column
I didn't find answer on this question, so I'll post my solution for this old question here.
Looks like Google doesn't support such behaviour out of box, but you can achieve it with custom formatter. This one works in my case:
function RowColorFormat() {
var colorFormat = new google.visualization.ColorFormat();
this.addRange = function(from, to, color, bgcolor) {
colorFormat.addRange(from, to, color, bgcolor);
};
this.addGradientRange = function(from, to, color, fromBgColor, toBgColor) {
colorFormat.addGradientRange(from, to, color, bgcolor);
};
this.format = function(dataTable, column) {
dataTable.setPropertyOverriden = dataTable.setProperty;
dataTable.setProperty = function (row, column, name, value) {
var length = this.getNumberOfColumns();
for (var i = 0; i < length; i++) {
this.setPropertyOverriden(row, i, name, value);
}
};
colorFormat.format(dataTable, column);
dataTable.setProperty = dataTable.setPropertyOverriden;
delete dataTable.setPropertyOverriden;
};
}
and use it like google.visualization.ColorFormat
How does one order the bar chart series to render from most to least? Ordering the data before binding does not seem to help.
My code:
chart.Series.Add("port");
chart.Series["port"].Type = SeriesChartType.Bar;
chart.Series["port"]["PointWidth"] = "0.6";
chart.Series["port"]["BarLabelStyle"] = "Center";
chart.Series["port"].ShowLabelAsValue = true;
chart.Series["port"].Points.DataBind(myData, "Key", "Value", "Label=Value{p2}");
chart.Series["port"].BorderStyle = ChartDashStyle.Solid;
chart.Series["port"].BorderColor = Color.White;
chart.Series["port"].BorderWidth = 1;
chart.Series["port"].ShowLabelAsValue = true;
chart.Series["port"].Font = myfont;
chart.ChartAreas.Add("Default");
chart.ChartAreas["Default"].BackColor = Color.Transparent;
foreach (var axis in chart.ChartAreas["Default"].Axes)
{
axis.LabelStyle.Font = myfont;
axis.MajorGrid.Enabled = false;
}
chart.ChartAreas["Default"].AxisX.Interval = 1;
chart.ChartAreas["Default"].AxisY.LabelStyle.Format = "p0";
You need to call Sort() on the series, see http://msdn.microsoft.com/en-us/library/dd455394.aspx. So to sort the points from most to least you'd do
chart.Series["port"].Sort(PointSortOrder.Descending);
There are two other sort methods incase you need to sort by something other than the point value.